Skip to content

Fix git pr to resolve fork PRs on renamed branches - #209

Merged
haacked merged 3 commits into
mainfrom
haacked/fix-git-pr-parsing
Sep 10, 2026
Merged

haacked merged 3 commits into
mainfrom
haacked/fix-git-pr-parsing

Conversation

@haacked

@haacked haacked commented Sep 10, 2026

Copy link
Copy Markdown
Owner
  • Replaces the pr git alias with bin/git-pr, which reads branch.<name>.merge instead of the local branch name, so a fork PR checked out under a renamed local branch (via gh pr checkout) resolves correctly.
  • Filters gh pr list --head results by the push remote's owner, so a same-named branch in an unrelated fork can't outrank the right PR, and lets gh errors propagate instead of silently swallowing them.
  • Points resolve_pr_target() in bin/lib/github.sh at the new script too, so detect-pr.sh, pr-review.sh, copilot-review-loop.sh, and gh-resolve-threads pick up the same fix.

Test plan

  • Check out a fork PR under a renamed local branch with gh pr checkout <url>, then run git pr and confirm it prints that PR's URL.
  • Run git pr on a branch with no PR and confirm it prints an error instead of nothing.
  • Run bin/detect-pr.sh --json on a branch with no PR and confirm the JSON error is a single clean message.

https://claude.ai/code/session_01TXeApJn9nTh2UMJm6NtRZV

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
@haacked
haacked requested a lite review from Copilot September 10, 2026 00:44
@haacked
haacked marked this pull request as ready for review September 10, 2026 00:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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-pr to resolve the PR URL by reading branch.<name>.merge and filtering gh pr list --head by the push remote’s owner.
  • Update the pr git alias to call the new script (fallback via a hardcoded dotfiles path).
  • Point resolve_pr_target() in bin/lib/github.sh at bin/git-pr so 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.

Comment thread git/gitconfig.aliases.symlink
@haacked
haacked merged commit 72ce0f8 into main Sep 10, 2026
2 checks passed
@haacked
haacked deleted the haacked/fix-git-pr-parsing branch September 10, 2026 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants