Skip to content

Commit b741bb8

Browse files
committed
remote: add a helper for generating the default fetchspec
1 parent b2640c3 commit b741bb8

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/remote.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ static int canonicalize_url(git_buf *out, const char *in)
189189
return git_buf_puts(out, in);
190190
}
191191

192+
static int default_fetchspec_for_name(git_buf *buf, const char *name)
193+
{
194+
if (git_buf_printf(buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0)
195+
return -1;
196+
197+
return 0;
198+
}
199+
192200
static int ensure_remote_doesnot_exist(git_repository *repo, const char *name)
193201
{
194202
int error;
@@ -295,7 +303,7 @@ int git_remote_create(git_remote **out, git_repository *repo, const char *name,
295303
git_buf buf = GIT_BUF_INIT;
296304
int error;
297305

298-
if (git_buf_printf(&buf, "+refs/heads/*:refs/remotes/%s/*", name) < 0)
306+
if (default_fetchspec_for_name(&buf, name) < 0)
299307
return -1;
300308

301309
error = git_remote_create_with_fetchspec(out, repo, name, url, git_buf_cstr(&buf));
@@ -1943,8 +1951,7 @@ static int rename_fetch_refspecs(git_vector *problems, git_remote *remote, const
19431951
if ((error = git_vector_init(problems, 1, NULL)) < 0)
19441952
return error;
19451953

1946-
if ((error = git_buf_printf(
1947-
&base, "+refs/heads/*:refs/remotes/%s/*", remote->name)) < 0)
1954+
if ((error = default_fetchspec_for_name(&base, remote->name)) < 0)
19481955
return error;
19491956

19501957
git_vector_foreach(&remote->refspecs, i, spec) {
@@ -1969,8 +1976,7 @@ static int rename_fetch_refspecs(git_vector *problems, git_remote *remote, const
19691976
git_buf_clear(&val);
19701977
git_buf_clear(&var);
19711978

1972-
if (git_buf_printf(
1973-
&val, "+refs/heads/*:refs/remotes/%s/*", new_name) < 0 ||
1979+
if (default_fetchspec_for_name(&val, new_name) < 0 ||
19741980
git_buf_printf(&var, "remote.%s.fetch", new_name) < 0)
19751981
{
19761982
error = -1;

0 commit comments

Comments
 (0)