Fall back to git rev-parse when go-git cannot resolve a revision#193
Merged
Conversation
go-git's ResolveRevision does not implement reflog (@{n}), :/regex,
date refs, and can fail on hashes in some storage layouts. Shell out
to git rev-parse --verify as a fallback so show/tree/bisect/branch
accept the full gitrevisions(7) grammar.
Reported in #166.
This was referenced May 7, 2026
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.
go-git's
ResolveRevisiondoes not implement the fullgitrevisions(7)grammar. Reflog refs (HEAD@{1},@{-1}), message search (:/text), and date refs (main@{yesterday}) all fail withreference not found, and there's a report in #166 of full and abbreviated SHAs failing too in some repos.When go-git fails, shell out to
git rev-parse --verify --end-of-options <rev>and use that. We already require the git CLI for--git-common-dirand config reads so this adds no new dependency.--end-of-optionsstops a user-supplied rev from being read as a flag.This affects
show,tree,bisect, andbranch, which all go throughRepository.ResolveRevision.If the #166 report turns out to be go-git failing to read the object store entirely (rather than just resolution),
CommitObjectwill still fail one line later inshowand we'll need a deeper fix, but this at least gets every standard rev spelling through the front door.