fix: prefer a reference over a commit hash as Git does - #508
Open
DeveloperC286 wants to merge 2 commits into
Open
fix: prefer a reference over a commit hash as Git does#508DeveloperC286 wants to merge 2 commits into
DeveloperC286 wants to merge 2 commits into
Conversation
The provided argument was resolved as a shortened commit hash before being resolved as a reference, the inverse of Git's own precedence. So a reference whose name was also the start of a commit hash, such as a branch named after a shortened commit hash, was silently shadowed and a different range of commits than Git itself would use was linted. Now a reference is resolved first, only falling back to a commit hash when no reference matches, and a warning is emitted when the provided argument is both, so which was used is never a surprise. Searching the history for a match is now also skipped when the provided argument can not be a commit hash, as it contains non hexadecimal characters. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ek4L1fyrQp7kNbitNo3ysH
DeveloperC286
force-pushed
the
claude/short-hash-ref-precedence-kfzduc
branch
from
September 10, 2026 06:40
df2aa83 to
c99a0b4
Compare
Resolving a reference before a commit hash matched Git for a shortened commit hash, but not in three other ways Git resolves an ambiguous name. A full commit hash is now resolved to the commit even when a reference shares its name, as Git does, warning that the name is ambiguous. A shortened commit hash of fewer than four characters is no longer matched, as Git's own MINIMUM_ABBREV does not match one either. References are now matched via the same expansions Git uses, in the same order, so a name matching several references resolves to the same one Git resolves to, warning that the name is ambiguous. The warning for a name which is both a reference and a shortened commit hash is also no longer conditional upon them differing, as Git warns whenever both match. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ek4L1fyrQp7kNbitNo3ysH
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.
Summary
This PR improves the handling of ambiguous Git references by aligning the behavior with how Git itself resolves them. When a provided argument matches both a reference name and a commit hash, the reference is now preferred, with appropriate logging and warnings.
Key Changes
resolve_to_oid()function: Replaces the previous error-chaining logic with a more explicit resolution strategy that prefers references over commit hashes, matching Git's behaviorparse_to_oid()validation: Added early validation to reject non-hexadecimal strings before attempting to search the repository history, improving performance and clarityImplementation Details
parse_to_oid()now rejects empty strings and non-hexadecimal characters upfront, avoiding unnecessary repository history searcheshttps://claude.ai/code/session_01Ek4L1fyrQp7kNbitNo3ysH