8000 #6422: handle dangling symbolic refs gracefully by arroz · Pull Request #6423 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

#6422: handle dangling symbolic refs gracefully #6423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
8000 Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes. I feel like we should have a single error that can tell you that this was a dangling link. I can imagine that EINVALIDSPEC is used when the target is invalid? But I'm surprised that we may see ENOTFOUND and EPEEL. I feel like maybe we should coalesce errors during peel into a single error message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a place where we can improve in the future but for now, :shipit:

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