10000 git_revwalk_push_glob errors if glob includes a dangling symbolic reference · Issue #6422 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

git_revwalk_push_glob errors if glob includes a dangling symbolic reference #6422

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

Open
arroz opened this issue Nov 3, 2022 · 0 comments
Open

Comments

@arroz
Copy link
Contributor
arroz commented Nov 3, 2022

According to the documentation and a pre-existing test (test_revwalk_basic__glob_heads_with_invalid), git_revwalk_push_glob should ignore references that are included by the glob but do not point to a commit, instead of returning an error. However, the situation where a dangling symbolic reference (ie a symbolic reference pointing to a non-existing reference) is included by the glob is not being handled gracefully, and an error is returned.

This was detected as part of another problem, when running a fetch operation with pruning on a repository whose HEAD changed from master to main twice fails the second time, since the fetch negotiation uses a revwalk (and git_revwalk_push_glob). For the record, these were the steps for that:

  1. Create a remote repository where the default branch (and HEAD) is master.
  2. Clone that remote to a local repository.
  3. On the remote, rename master to main (git branch -m master main). Make sure the HEAD reference on the remote itself changes to main as well.
  4. Using libgit2, run a fetch operation on the local clone created on step 2 with pruning turned on. This should go through, remove the remote's master reference and add main (not sure what happens exactly if you have master checked out, adjust if needed for the remote's master to be removed). Make sure /refs/remotes/<remote-name>/HEAD still points to master, as expected (if the equivalent core git operation is performed, git warns the remote HEAD turned into a dangling reference).
  5. Add a few commits to the remote from another clone (this step is necessary because, in the following step, libgit2 is too smart and wont actually enter the negotiation phase if it knows there's nothing to fetch).
  6. Repeat step 4 (run a fetch operation on the local clone created on step 2 with pruning turned on).

An error will be thrown saying refs/remotes/<remote-name>/master does not exist.

Reproduction steps

Regarding the root issue this ticket addresses, the following code will fail with an error (-1) when it should succeed:

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"));

Expected behavior

The broken reference should be ignored and not cause an error.

Actual behavior

An error is thrown (refs/remotes/<remote-name>/master does not exist.).

Version of libgit2 (release number or SHA1)

main (a3841af5eecc6301e87f8302c7fdce6555e39247)

Operating system(s) tested

macOS (13.0).

arroz added a commit to cavaquinho/libgit2 that referenced this issue Nov 3, 2022
ethomson added a commit that referenced this issue Feb 14, 2023
…angling-ref

#6422: handle dangling symbolic refs gracefully
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2E35
Development

No branches or pull requests

1 participant
0