Fix git pr to resolve fork PRs on renamed branches - #209
Merged
Merged
Conversation
gh pr view with no argument resolves the head ref from the local branch name instead of branch.<name>.merge, so it misses a PR checked out under a different local name, and the alias silenced every gh error with 2>/dev/null. Moves the lookup into bin/git-pr, which resolves the real head (including the refs/pull/<N>/head form gh writes when a fork disables "allow edits by maintainers"), looks it up via gh pr list --head filtered by the push remote's owner so a same-named branch in an unrelated fork can't outrank the right one, and lets genuine gh errors through. Claude-Session: https://claude.ai/code/session_01TXeApJn9nTh2UMJm6NtRZV
Drops the manual refs/pull/<N>/head PR-number parsing: gh's own no-argument lookup already resolves that merge-ref form, verified against a real gh pr checkout with maintainer edits disabled. Collapses the three identical gh pr view calls into one helper, merges the merge-ref and branch variables since nothing needs both, folds the origin fallback into the single remote-resolution chain, and drops a tr/printf pipeline for bash's native lowercase expansion. Claude-Session: https://claude.ai/code/session_01TXeApJn9nTh2UMJm6NtRZV
Points the pr alias at the hardcoded ~/.dotfiles/bin/git-pr path instead of a bare git-pr invocation. Git tries an external git-<cmd> command on PATH before expanding any alias, so the alias body only ran when bin/git-pr was missing from PATH, and its own bare git-pr invocation failed for the same reason. Has resolve_pr_target's no-argument branch call bin/git-pr instead of gh pr view directly, so detect-pr.sh, pr-review.sh, copilot-review-loop.sh, and gh-resolve-threads all resolve a fork PR checked out under a renamed local branch, matching what git pr already does. Adds comments explaining why bin/git-pr's remote-URL fallback and OPEN-over-merged sort exist, and names the excluded owner in the not-found error so a same-named branch in another fork doesn't read as no PR at all. Claude-Session: https://claude.ai/code/session_01TXeApJn9nTh2UMJm6NtRZV
There was a problem hiding this comment.
🟡 Changes recommended
The git pr alias fallback doesn’t forward arguments and resolve_pr_target currently discards actionable stderr from git-pr/gh, leading to incorrect or unhelpful failures.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR replaces the previous git pr alias behavior with a dedicated bin/git-pr script that resolves PRs more reliably for fork PR checkouts on renamed local branches, and wires internal tooling (resolve_pr_target) to use the same logic.
Changes:
- Add
bin/git-prto resolve the PR URL by readingbranch.<name>.mergeand filteringgh pr list --headby the push remote’s owner. - Update the
prgit alias to call the new script (fallback via a hardcoded dotfiles path). - Point
resolve_pr_target()inbin/lib/github.shatbin/git-prso other scripts share the fix.
File summaries
| File | Description |
|---|---|
git/gitconfig.aliases.symlink |
Updates git pr alias to invoke the new bin/git-pr script. |
bin/lib/github.sh |
Switches PR auto-detection to call bin/git-pr instead of gh pr view. |
bin/git-pr |
New script to resolve PR URLs correctly for renamed local branches / fork PR checkouts. |
Review details
- Files reviewed: 1/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
prgit alias withbin/git-pr, which readsbranch.<name>.mergeinstead of the local branch name, so a fork PR checked out under a renamed local branch (viagh pr checkout) resolves correctly.gh pr list --headresults by the push remote's owner, so a same-named branch in an unrelated fork can't outrank the right PR, and letsgherrors propagate instead of silently swallowing them.resolve_pr_target()inbin/lib/github.shat the new script too, sodetect-pr.sh,pr-review.sh,copilot-review-loop.sh, andgh-resolve-threadspick up the same fix.Test plan
gh pr checkout <url>, then rungit prand confirm it prints that PR's URL.git pron a branch with no PR and confirm it prints an error instead of nothing.bin/detect-pr.sh --jsonon a branch with no PR and confirm the JSON error is a single clean message.https://claude.ai/code/session_01TXeApJn9nTh2UMJm6NtRZV