Commit 7c353afd by Ben Straub

Define constant for default fetch spec

parent 44f36f6e
...@@ -24,6 +24,14 @@ ...@@ -24,6 +24,14 @@
*/ */
GIT_BEGIN_DECL GIT_BEGIN_DECL
/**
* Use this when creating a remote with git_remote_new to get the default fetch
* behavior produced by git_remote_add. It corresponds to this fetchspec (note
* the spaces between '/' and '*' to avoid C compiler errors):
* "+refs/heads/ *:refs/remotes/<remote_name>/ *"
*/
#define GIT_REMOTE_DEFAULT_FETCH ""
typedef int (*git_remote_rename_problem_cb)(const char *problematic_refspec, void *payload); typedef int (*git_remote_rename_problem_cb)(const char *problematic_refspec, void *payload);
/* /*
* TODO: This functions still need to be implemented: * TODO: This functions still need to be implemented:
......
...@@ -115,7 +115,7 @@ int git_remote_new(git_remote **out, git_repository *repo, const char *name, con ...@@ -115,7 +115,7 @@ int git_remote_new(git_remote **out, git_repository *repo, const char *name, con
GITERR_CHECK_ALLOC(remote->name); GITERR_CHECK_ALLOC(remote->name);
/* An empty name indicates to use a sensible default for the fetchspec. */ /* An empty name indicates to use a sensible default for the fetchspec. */
if (fetch && strlen(fetch) == 0) { if (fetch && !(*fetch)) {
if (git_buf_printf(&fetchbuf, "+refs/heads/*:refs/remotes/%s/*", remote->name) < 0) if (git_buf_printf(&fetchbuf, "+refs/heads/*:refs/remotes/%s/*", remote->name) < 0)
goto on_error; goto on_error;
fetch = git_buf_cstr(&fetchbuf); fetch = git_buf_cstr(&fetchbuf);
......
...@@ -14,7 +14,7 @@ static git_remote *g_origin; ...@@ -14,7 +14,7 @@ static git_remote *g_origin;
void test_clone_network__initialize(void) void test_clone_network__initialize(void)
{ {
g_repo = NULL; g_repo = NULL;
cl_git_pass(git_remote_new(&g_origin, NULL, "origin", LIVE_REPO_URL, "")); cl_git_pass(git_remote_new(&g_origin, NULL, "origin", LIVE_REPO_URL, GIT_REMOTE_DEFAULT_FETCH));
} }
static void cleanup_repository(void *path) static void cleanup_repository(void *path)
...@@ -70,7 +70,7 @@ void test_clone_network__empty_repository(void) ...@@ -70,7 +70,7 @@ void test_clone_network__empty_repository(void)
cl_set_cleanup(&cleanup_repository, "./empty"); cl_set_cleanup(&cleanup_repository, "./empty");
git_remote_free(g_origin); git_remote_free(g_origin);
cl_git_pass(git_remote_new(&g_origin, NULL, "origin", LIVE_EMPTYREPO_URL, "")); cl_git_pass(git_remote_new(&g_origin, NULL, "origin", LIVE_EMPTYREPO_URL, GIT_REMOTE_DEFAULT_FETCH));
cl_git_pass(git_clone(&g_repo, g_origin, "./empty", NULL, NULL, NULL)); cl_git_pass(git_clone(&g_repo, g_origin, "./empty", NULL, NULL, NULL));
......
...@@ -11,7 +11,7 @@ static git_remote *g_origin = NULL; ...@@ -11,7 +11,7 @@ static git_remote *g_origin = NULL;
void test_clone_nonetwork__initialize(void) void test_clone_nonetwork__initialize(void)
{ {
g_repo = NULL; g_repo = NULL;
cl_git_pass(git_remote_new(&g_origin, NULL, "origin", cl_git_fixture_url("testrepo.git"), "")); cl_git_pass(git_remote_new(&g_origin, NULL, "origin", cl_git_fixture_url("testrepo.git"), GIT_REMOTE_DEFAULT_FETCH));
} }
static void cleanup_repository(void *path) static void cleanup_repository(void *path)
...@@ -28,7 +28,7 @@ void test_clone_nonetwork__bad_url(void) ...@@ -28,7 +28,7 @@ void test_clone_nonetwork__bad_url(void)
{ {
/* Clone should clean up the mess if the URL isn't a git repository */ /* Clone should clean up the mess if the URL isn't a git repository */
git_remote_free(g_origin); git_remote_free(g_origin);
cl_git_pass(git_remote_new(&g_origin, NULL, "origin", "not_a_repo", NULL)); cl_git_pass(git_remote_new(&g_origin, NULL, "origin", "not_a_repo", GIT_REMOTE_DEFAULT_FETCH));
cl_git_fail(git_clone(&g_repo, g_origin, "./foo", NULL, NULL, NULL)); cl_git_fail(git_clone(&g_repo, g_origin, "./foo", NULL, NULL, NULL));
cl_assert(!git_path_exists("./foo")); cl_assert(!git_path_exists("./foo"));
......
...@@ -15,7 +15,7 @@ static git_remote *g_origin; ...@@ -15,7 +15,7 @@ static git_remote *g_origin;
void test_fetchhead_network__initialize(void) void test_fetchhead_network__initialize(void)
{ {
g_repo = NULL; g_repo = NULL;
cl_git_pass(git_remote_new(&g_origin, NULL, "origin", LIVE_REPO_URL, "")); cl_git_pass(git_remote_new(&g_origin, NULL, "origin", LIVE_REPO_URL, GIT_REMOTE_DEFAULT_FETCH));
} }
void test_fetchhead_network__cleanup(void) void test_fetchhead_network__cleanup(void)
......
...@@ -89,7 +89,7 @@ void test_network_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_dat ...@@ -89,7 +89,7 @@ void test_network_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_dat
git_remote *remote; git_remote *remote;
bool invoked = false; bool invoked = false;
cl_git_pass(git_remote_new(&remote, NULL, "origin", "https://github.com/libgit2/TestGitRepository.git", "")); cl_git_pass(git_remote_new(&remote, NULL, "origin", "https://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DEFAULT_FETCH));
cl_git_pass(git_clone_bare(&_repository, remote, "./fetch/lg2", NULL, NULL)); cl_git_pass(git_clone_bare(&_repository, remote, "./fetch/lg2", NULL, NULL));
git_repository_free(_repository); git_repository_free(_repository);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment