fix(browse): resolve ambiguous decimal SHA via local git lookup#13600
Open
jfjrh2014 wants to merge 1 commit into
Open
fix(browse): resolve ambiguous decimal SHA via local git lookup#13600jfjrh2014 wants to merge 1 commit into
jfjrh2014 wants to merge 1 commit into
Conversation
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>
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.
Summary
gh browse 309628980always 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:parseSectionnow consults the local git repo for ambiguous (numeric, 7+ char) selectors. AddsCommitBodyto thegitClientinterface.pkg/cmd/browse/browse_test.go: covers both directions — ambiguous SHA that exists locally → commit URL; ambiguous SHA that does not → issue URL.Notes
remoteGitClient.CommitBodyreturns an error so remote repos preserve the previous behavior (no GraphQL endpoint to validate an arbitrary abbreviated SHA).