fix: reject deleted prior checkout branches#2610
Merged
Merged
Conversation
39f5509 to
95bfe47
Compare
Repository::rev_parse_single("@{-1}") could return the previous object id from
HEAD's reflog after the prior checkout branch had been deleted. Git treats @{-N}
as the previous checkout name and reparses that name, so a deleted branch no
longer names a single revision.
The regression adds deleted prior-checkout fixtures and asserts that @{-1}
follows the Git baseline failure for deleted branch names while still accepting
previous checkout names that are full object ids.
The fix keeps resolving existing prior checkout references as before, but only
falls back to a direct object id when the reflog name itself is a full object id
for the repository hash kind.
Git baseline: Git 2.50.1 rejects the deleted branch scenario with `git rev-parse
--verify @{-1}` reporting "Needed a single revision" and exiting 128. The
reference implementation in object-name.c expands @{-N} to the previous checkout
text before normal revision lookup.
Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
95bfe47 to
6b5c2ea
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes gix::Repository::rev_parse_single("@{-1}") to match Git’s behavior when the previous checkout target was a branch that has since been deleted: instead of resolving via the stale object id recorded in HEAD’s reflog, it now fails unless the prior checkout name itself is a full object id.
Changes:
- Update prior-checkout (
@{-N}) resolution to error on deleted branch names instead of falling back to the reflog’s recorded object id. - Preserve Git-compatible behavior for prior checkout names that are full object ids by accepting them even if they don’t correspond to an existing ref.
- Add fixtures + tests covering both the deleted-branch failure case and the “branch named like full object id” acceptance case.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| gix/src/revision/spec/parse/delegate/revision.rs | Adjusts @{-N} handling to re-resolve the previous checkout name and reject deleted branches, only allowing fallback for full object ids. |
| gix/tests/gix/revision/spec/from_bytes/reflog.rs | Adds regression tests for deleted prior-checkout branches and the full-object-id-name exception. |
| gix/tests/fixtures/make_rev_spec_parse_repos.sh | Adds new fixture repos to exercise the deleted-branch and full-object-id-name prior-checkout scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tasks
Created by Codex on behalf of Byron. Byron will review before this is ready to merge.
Summary
Fixes #2609.
Repository::rev_parse_single("@{-1}")now rejects a deleted prior checkout branch instead of resolving it through the stale object id stored in the HEAD reflog.The change keeps Git-compatible full-object-id behavior for previous checkout names that are themselves complete object ids.
Git Baseline
Git 2.50.1 rejects the deleted branch scenario with
git rev-parse --verify @{-1}reporting "Needed a single revision" and exiting 128.The Git reference implementation in
object-name.cexpands@{-N}to the previous checkout text before normal revision lookup.Validation
GIX_TEST_IGNORE_ARCHIVES=1 cargo test -p gix --test gix revision::spec::from_bytes::reflog::nth_prior_checkout_to_deleted_branch_fails_like_git --features revisionGIX_TEST_IGNORE_ARCHIVES=1 cargo test -p gix --test gix revision::spec::from_bytes::reflog --features revisioncargo test -p gix --test gix revision::spec::from_bytes::reflog --features revisionGIX_TEST_IGNORE_ARCHIVES=1 cargo test -p gix --test gix revision::spec::from_bytes --features revisioncargo test -p gix --test gix revision::spec::from_bytes --features revision