diff --git a/include/git2/remote.h b/include/git2/remote.h index 6649b3a46..f3b0a9443 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -24,6 +24,14 @@ */ 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// *" + */ +#define GIT_REMOTE_DEFAULT_FETCH "" + typedef int (*git_remote_rename_problem_cb)(const char *problematic_refspec, void *payload); /* * TODO: This functions still need to be implemented: diff --git a/src/remote.c b/src/remote.c index 24a821e44..28ce88a93 100644 --- a/src/remote.c +++ b/src/remote.c @@ -115,7 +115,7 @@ int git_remote_new(git_remote **out, git_repository *repo, const char *name, con GITERR_CHECK_ALLOC(remote->name); /* 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) goto on_error; fetch = git_buf_cstr(&fetchbuf); diff --git a/tests-clar/clone/network.c b/tests-clar/clone/network.c index 5d564f99d..018f464ad 100644 --- a/tests-clar/clone/network.c +++ b/tests-clar/clone/network.c @@ -14,7 +14,7 @@ static git_remote *g_origin; void test_clone_network__initialize(void) { 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) @@ -70,7 +70,7 @@ void test_clone_network__empty_repository(void) cl_set_cleanup(&cleanup_repository, "./empty"); 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)); diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c index 9a1eed772..af1298191 100644 --- a/tests-clar/clone/nonetwork.c +++ b/tests-clar/clone/nonetwork.c @@ -11,7 +11,7 @@ static git_remote *g_origin = NULL; void test_clone_nonetwork__initialize(void) { 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) @@ -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 */ 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_assert(!git_path_exists("./foo")); diff --git a/tests-clar/fetchhead/network.c b/tests-clar/fetchhead/network.c index 0eeac9ed2..aed5b5ad8 100644 --- a/tests-clar/fetchhead/network.c +++ b/tests-clar/fetchhead/network.c @@ -15,7 +15,7 @@ static git_remote *g_origin; void test_fetchhead_network__initialize(void) { 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) diff --git a/tests-clar/network/fetch.c b/tests-clar/network/fetch.c index fa3199fe7..246435b1b 100644 --- a/tests-clar/network/fetch.c +++ b/tests-clar/network/fetch.c @@ -89,7 +89,7 @@ void test_network_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_dat git_remote *remote; 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)); git_repository_free(_repository);