Skip to content

browse: check commit existence for ambiguous decimal-only short hashes#12943

Open
mateenali66 wants to merge 4 commits intocli:trunkfrom
mateenali66:fix/browse-decimal-hash
Open

browse: check commit existence for ambiguous decimal-only short hashes#12943
mateenali66 wants to merge 4 commits intocli:trunkfrom
mateenali66:fix/browse-decimal-hash

Conversation

@mateenali66
Copy link
Copy Markdown

@mateenali66 mateenali66 commented Mar 15, 2026

Fixes #12357

When a short commit hash is all decimal digits (e.g. 309628980), gh browse was routing it to the issues URL instead of commit URL. This happens because isNumber() is checked before isCommit(), so any all-decimal string that is also valid hex gets treated as issue number.

This PR calls the GitHub API to disambiguate when the arg passes both checks (all-decimal, 7+ chars, no # prefix). If the API confirms the commit exists on the remote, it use the commit URL. If not, falls back to issue URL.

The # prefix still forces issue behavior as before.

Closes #12357

Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
@mateenali66 mateenali66 requested a review from a team as a code owner March 15, 2026 19:14
@mateenali66 mateenali66 requested a review from BagToad March 15, 2026 19:14
@github-actions github-actions bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed labels Mar 15, 2026
The previous comment said '7+ chars' but the length check is inside isCommit(),
not at the call site. Reword to make it clear that isCommit() is what enforces
both the hex constraint and the 7-64 char minimum.

Signed-off-by: Mateen Anjum <mateenali66@gmail.com>
@mateenali66
Copy link
Copy Markdown
Author

Good catch on the comment — the '7+ chars' constraint is actually inside isCommit() via the regex [a-f0-9]{7,64}, not explicit at the call site. The wording implied there was an inline length check which wasn't visible in the diff.

Updated the comment to make it self-explanatory: decimal digits 0–9 are valid hex, so an all-decimal string without a # prefix can satisfy both isNumber and isCommit, and isCommit() is what enforces both the hex-only constraint and the 7–64 char minimum. Pushed as dbef094.

@nhed
Copy link
Copy Markdown

nhed commented Mar 17, 2026

Good catch on the comment — the '7+ chars' constraint is actually inside isCommit() via the regex [a-f0-9]{7,64}, not explicit at the call site. The wording implied there was an inline length check which wasn't visible in the diff.

I deleted my comment as soon as I realized it was in the isCommit impl (Guess I should have edited instead)

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

2 participants