Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3b66c6a

Browse files
committed
Merge pull request libgit2#3256 from libgit2/cmn/fetch-spec-fetchhead
remote: insert refspecs with no rhs in FETCH_HEAD
2 parents 87987fd + 23aa7c9 commit 3b66c6a

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

src/remote.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,9 +1342,20 @@ static int update_tips_for_spec(
13421342
} else {
13431343
continue;
13441344
}
1345-
} else if (git_refspec_src_matches(spec, head->name) && spec->dst) {
1346-
if (git_refspec_transform(&refname, spec, head->name) < 0)
1347-
goto on_error;
1345+
} else if (git_refspec_src_matches(spec, head->name)) {
1346+
if (spec->dst) {
1347+
if (git_refspec_transform(&refname, spec, head->name) < 0)
1348+
goto on_error;
1349+
} else {
1350+
/*
1351+
* no rhs mans store it in FETCH_HEAD, even if we don't
1352+
update anything else.
1353+
*/
1354+
if ((error = git_vector_insert(&update_heads, head)) < 0)
1355+
goto on_error;
1356+
1357+
continue;
1358+
}
13481359
} else {
13491360
continue;
13501361
}

tests/fetchhead/nonetwork.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,47 @@ void test_fetchhead_nonetwork__quote_in_branch_name(void)
351351
cl_git_rewritefile("./test1/.git/FETCH_HEAD", FETCH_HEAD_QUOTE_DATA);
352352
cl_git_pass(git_repository_fetchhead_foreach(g_repo, read_noop, NULL));
353353
}
354+
355+
static bool found_master;
356+
static bool find_master_called;
357+
358+
int find_master(const char *ref_name, const char *remote_url, const git_oid *oid, unsigned int is_merge, void *payload)
359+
{
360+
GIT_UNUSED(remote_url);
361+
GIT_UNUSED(oid);
362+
GIT_UNUSED(payload);
363+
364+
find_master_called = true;
365+
366+
if (!strcmp("refs/heads/master", ref_name)) {
367+
cl_assert(is_merge);
368+
found_master = true;
369+
}
370+
371+
return 0;
372+
}
373+
374+
void test_fetchhead_nonetwork__create_when_refpecs_given(void)
375+
{
376+
git_remote *remote;
377+
git_buf path = GIT_BUF_INIT;
378+
char *refspec = "refs/heads/master";
379+
git_strarray specs = {
380+
&refspec,
381+
1,
382+
};
383+
384+
cl_set_cleanup(&cleanup_repository, "./test1");
385+
cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
386+
387+
cl_git_pass(git_buf_joinpath(&path, git_repository_path(g_repo), "FETCH_HEAD"));
388+
cl_git_pass(git_remote_create(&remote, g_repo, "origin", cl_fixture("testrepo.git")));
389+
390+
cl_assert(!git_path_exists(path.ptr));
391+
cl_git_pass(git_remote_fetch(remote, &specs, NULL, NULL));
392+
cl_assert(git_path_exists(path.ptr));
393+
394+
cl_git_pass(git_repository_fetchhead_foreach(g_repo, find_master, NULL));
395+
cl_assert(find_master_called);
396+
cl_assert(found_master);
397+
}

0 commit comments

Comments
 (0)