Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: reject deleted prior checkout branches#2610

Draft
Sebastian Thiel (Byron) wants to merge 1 commit into
mainfrom
fix-rev-parse
Draft

fix: reject deleted prior checkout branches#2610
Sebastian Thiel (Byron) wants to merge 1 commit into
mainfrom
fix-rev-parse

Conversation

@Byron
Copy link
Copy Markdown
Member

Tasks

  • refackiew

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.c expands @{-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 revision
  • GIX_TEST_IGNORE_ARCHIVES=1 cargo test -p gix --test gix revision::spec::from_bytes::reflog --features revision
  • cargo test -p gix --test gix revision::spec::from_bytes::reflog --features revision
  • GIX_TEST_IGNORE_ARCHIVES=1 cargo test -p gix --test gix revision::spec::from_bytes --features revision
  • cargo test -p gix --test gix revision::spec::from_bytes --features revision

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.

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 revision
- GIX_TEST_IGNORE_ARCHIVES=1 cargo test -p gix --test gix revision::spec::from_bytes::reflog --features revision
- cargo test -p gix --test gix revision::spec::from_bytes::reflog --features revision
- GIX_TEST_IGNORE_ARCHIVES=1 cargo test -p gix --test gix revision::spec::from_bytes --features revision
- cargo test -p gix --test gix revision::spec::from_bytes --features revision
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gix::Repository::rev_parse_single doesn't agree with git for specs of the form @{-n}

2 participants