You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ResolveRevision prefers an abbreviated object id to a ref of the same name #2644
Repository.ResolveRevision resolves a branch or tag to the wrong commit when its name is also the start of an object id. Git resolves the ref.
git init demo &&cd demo
foriin$(seq 1 40);do git commit -q --allow-empty -m c$i;done
p=$(git rev-parse --short=4 HEAD~10)# 6a33 in my run
git tag $p HEAD
git branch 5 HEAD
git rev-parse $p 5 # HEAD twice, with "warning: refname '6a33' is ambiguous."
git rev-parse 918 # fatal: ambiguous argument '918': unknown revision
With go-git (main and releases/v5.x) on the same repository:
ResolveRevision("6a33") -> HEAD~10 (expected HEAD)
ResolveRevision("5") -> 59c2c73 (a commit starting with 5; expected HEAD)
ResolveRevision tries the name as an abbreviated id before it looks up the ref, and the comment there says Git prefers the id. That holds only for a full-length id. In Git's object-name.c, get_oid_1 calls get_oid_basic (a full id, then the refs) and falls back to get_short_oid only when no ref matched. get_short_oid also rejects anything shorter than minimum_abbrev (4), so git rev-parse 918 fails, while go-git accepts 1 to 3 hex digits as an abbreviated id.
Branch and tag names that are all hex digits are common (build numbers, ticket numbers, cafe, beef), and the chance of a collision grows with the repository. The result is silently wrong: the caller gets a different commit and no error.
I have a fix with tests and will open a PR for it.
Activity