Skip to content

Commit 0362ecd

Browse files
authored
Merge pull request libgit2#6423 from cavaquinho/fix/6422-revwalk_push_glob-dangling-ref
libgit2#6422: handle dangling symbolic refs gracefully
2 parents 3b43c9d + b57221e commit 0362ecd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/libgit2/revwalk.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,12 @@ int git_revwalk__push_ref(git_revwalk *walk, const char *refname, const git_revw
121121
{
122122
git_oid oid;
123123

124-
if (git_reference_name_to_id(&oid, walk->repo, refname) < 0)
124+
int error = git_reference_name_to_id(&oid, walk->repo, refname);
125+
if (opts->from_glob && (error == GIT_ENOTFOUND || error == GIT_EINVALIDSPEC || error == GIT_EPEEL)) {
126+
return 0;
127+
} else if (error < 0) {
125128
return -1;
129+
}
126130

127131
return git_revwalk__push_commit(walk, &oid, opts);
128132
}

tests/libgit2/revwalk/basic.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,23 @@ void test_revwalk_basic__glob_heads_with_invalid(void)
180180
cl_assert_equal_i(20, i);
181181
}
182182

183+
void test_revwalk_basic__glob_invalid_symbolic_ref(void)
184+
{
185+
int i;
186+
git_oid oid;
187+
188+
revwalk_basic_setup_walk("testrepo");
189+
190+
cl_git_mkfile("testrepo/.git/refs/heads/broken-sym-ref", "ref: refs/heads/does-not-exist");
191+
cl_git_pass(git_revwalk_push_glob(_walk, "heads"));
192+
193+
for (i = 0; !git_revwalk_next(&oid, _walk); ++i)
194+
/* walking */;
195+
196+
/* git log --branches --oneline | wc -l => 16 */
197+
cl_assert_equal_i(20, i);
198+
}
199+
183200
void test_revwalk_basic__push_head(void)
184201
{
185202
int i = 0;

0 commit comments

Comments
 (0)