Skip to content

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

Open
jfjrh2014 wants to merge 3 commits into
cli:trunkfrom
jfjrh2014:fix/browse-ambiguous-sha
Open

fix(browse): resolve ambiguous decimal SHA via local git lookup#13600
jfjrh2014 wants to merge 3 commits 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
@nhed

nhed commented Jun 8, 2026

Copy link
Copy Markdown

if I'm reading your description right (didn't open code) you did not abide by the agreement between the reporter (me) and the maintainer in the issue discussion that the ref MAY be remote.

@github-actions github-actions Bot removed the needs-triage needs to be reviewed label Jun 8, 2026
jfjrh2014 added 2 commits June 9, 2026 11:11
Use the GitHub REST API to disambiguate selectors that are both valid
decimal numbers and valid commit SHAs (e.g. 3096289). This handles the
case where the target ref may only exist on the remote, and also works
when using -R to override the repository.

The # prefix still forces issue interpretation regardless.

Closes cli#12357

Signed-off-by: jeff <jfjrh2014@gmail.com>
…enario 3

Clean up leftover CommitBody interface additions that are unused.
The ambiguous resolution now solely uses the remote REST API approach
as agreed with the maintainer in issue cli#12357.

Adds test for AC scenario 3: # prefix on ambiguous decimal SHA
forces issue interpretation regardless of commit existence.
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 ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh browse mistakes short hash for issue/pr number

3 participants