Skip to content

Fall back to git rev-parse when go-git cannot resolve a revision#193

Merged
andrew merged 1 commit into
mainfrom
rev-parse-fallback
May 9, 2026
Merged

Fall back to git rev-parse when go-git cannot resolve a revision#193
andrew merged 1 commit into
mainfrom
rev-parse-fallback

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented May 7, 2026

go-git's ResolveRevision does not implement the full gitrevisions(7) grammar. Reflog refs (HEAD@{1}, @{-1}), message search (:/text), and date refs (main@{yesterday}) all fail with reference 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-dir and config reads so this adds no new dependency. --end-of-options stops a user-supplied rev from being read as a flag.

This affects show, tree, bisect, and branch, which all go through Repository.ResolveRevision.

If the #166 report turns out to be go-git failing to read the object store entirely (rather than just resolution), CommitObject will still fail one line later in show and we'll need a deeper fix, but this at least gets every standard rev spelling through the front door.

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.
@andrew andrew merged commit 970917f into main May 9, 2026
7 checks passed
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.

1 participant