Skip to content

fix(browse): resolve ambiguous decimal SHA via local git lookup#13600

Open
jfjrh2014 wants to merge 1 commit into
cli:trunkfrom
jfjrh2014:fix/browse-ambiguous-sha
Open

fix(browse): resolve ambiguous decimal SHA via local git lookup#13600
jfjrh2014 wants to merge 1 commit into
cli:trunkfrom
jfjrh2014:fix/browse-ambiguous-sha

Conversation

@jfjrh2014
Copy link
Copy Markdown

Summary

gh browse 309628980 always opened /issues/309628980, even when the selector matched an abbreviated commit SHA in the local repository.

When a selector is all decimal digits and 7+ characters long, it is ambiguous: it could be either an issue number or a shortened commit hash. Today the issue interpretation wins unconditionally.

This change adds a local-git lookup on the ambiguous path: if a matching commit exists, the commit URL is opened. Otherwise the existing issue-URL behavior is preserved.

Fixes #12357

Changes

  • pkg/cmd/browse/browse.go: parseSection now consults the local git repo for ambiguous (numeric, 7+ char) selectors. Adds CommitBody to the gitClient interface.
  • pkg/cmd/browse/browse_test.go: covers both directions — ambiguous SHA that exists locally → commit URL; ambiguous SHA that does not → issue URL.

Notes

  • Local-only: remoteGitClient.CommitBody returns an error so remote repos preserve the previous behavior (no GraphQL endpoint to validate an arbitrary abbreviated SHA).
  • Zero impact on the non-ambiguous paths (issue numbers < 7 chars, hex-only SHAs).

When the selector argument was all decimal digits and 7+ characters
long (e.g. 3096289), gh browse always treated it as an issue number
even when it matched an abbreviated commit hash in the local repo.

Now ambiguous selectors are checked against the local git repository:
if the SHA resolves to a commit, the commit URL is opened; otherwise
the existing issue-URL behavior is preserved.

Fixes cli#12357

Signed-off-by: jeff <jfjrh2014@gmail.com>
@jfjrh2014 jfjrh2014 requested a review from a team as a code owner June 5, 2026 20:30
@jfjrh2014 jfjrh2014 requested a review from babakks June 5, 2026 20:30
@github-actions github-actions Bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed labels Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team needs-triage needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh browse mistakes short hash for issue/pr number

1 participant