Skip to content

Commit

Permalink
Merge pull request #6423 from cavaquinho/fix/6422-revwalk_push_glob-d…
Browse files Browse the repository at this point in the history
…angling-ref

#6422: handle dangling symbolic refs gracefully
  • Loading branch information
ethomson committed Feb 14, 2023
2 parents 3b43c9d + b57221e commit 0362ecd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/libgit2/revwalk.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@ int git_revwalk__push_ref(git_revwalk *walk, const char *refname, const git_revw
{
git_oid oid;

if (git_reference_name_to_id(&oid, walk->repo, refname) < 0)
int error = git_reference_name_to_id(&oid, walk->repo, refname);
if (opts->from_glob && (error == GIT_ENOTFOUND || error == GIT_EINVALIDSPEC || error == GIT_EPEEL)) {
return 0;
} else if (error < 0) {
return -1;
}

return git_revwalk__push_commit(walk, &oid, opts);
}
Expand Down
17 changes: 17 additions & 0 deletions tests/libgit2/revwalk/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ void test_revwalk_basic__glob_heads_with_invalid(void)
cl_assert_equal_i(20, i);
}

void test_revwalk_basic__glob_invalid_symbolic_ref(void)
{
int i;
git_oid oid;

revwalk_basic_setup_walk("testrepo");

cl_git_mkfile("testrepo/.git/refs/heads/broken-sym-ref", "ref: refs/heads/does-not-exist");
cl_git_pass(git_revwalk_push_glob(_walk, "heads"));

for (i = 0; !git_revwalk_next(&oid, _walk); ++i)
/* walking */;

/* git log --branches --oneline | wc -l => 16 */
cl_assert_equal_i(20, i);
}

void test_revwalk_basic__push_head(void)
{
int i = 0;
Expand Down

0 comments on commit 0362ecd

Please sign in to comment.