Add PR worktree checkout command#187
Conversation
Assisted-by: pi:gpt-5.5 Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Assisted-by: pi:gpt-5.5 Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Assisted-by: pi:gpt-5.5 Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
WalkthroughAdds a new Changesgit gtr pr feature
Sequence Diagram(s)sequenceDiagram
participant User
participant git_gtr as git-gtr
participant cmd_pr
participant gh as gh CLI
participant Git
User->>git_gtr: git gtr pr 123 --cd
git_gtr->>cmd_pr: cmd_pr "$@"
cmd_pr->>gh: gh pr view 123
gh-->>cmd_pr: PR number, head ref, owner/repo, URL
cmd_pr->>Git: resolve/create base remote
cmd_pr->>Git: git fetch refs/pull/123/head
cmd_pr->>Git: git worktree add
cmd_pr->>Git: set branch remote/pushRemote/merge config
cmd_pr-->>User: worktree ready, shell cd's into it
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
tests/init.bats (1)
966-976: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueOverly convoluted conditional; simplify to a direct call.
Since the cache file is always seeded with the stale
init=5stamp right before this line,[[ -f "$_gtr_init" ]] && head -n 1 ... | grep -q ' init=6 ' || cmd_init bash >/dev/null || truealways reduces to just runningcmd_init bash, and the trailing|| truesilently swallows any non-zero exit fromcmd_init. This duplicates the previous test's intent (lines 953-964) with unnecessary complexity.♻️ Simplification
- [[ -f "$_gtr_init" ]] && head -n 1 "$_gtr_init" | grep -q ' init=6 ' || cmd_init bash >/dev/null || true + cmd_init bash >/dev/null🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/init.bats` around lines 966 - 976, The setup in the gtr bash cache test is overcomplicated and effectively always falls through to initialization, so simplify the logic in the documented bash setup regenerates old schema cache case by calling cmd_init bash directly after seeding the stale cache. Update the test body around the local _gtr_init and cmd_init bash usage to remove the redundant file-check/grep conditional and the trailing || true, keeping the intent clear and consistent with the existing cache-regeneration tests.lib/commands/pr.sh (1)
9-44: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick wingh failures are silently swallowed, hiding the real cause.
Both
gh pr viewinvocations redirect stderr to/dev/nullbefore falling back to a generic"Could not resolve pull request"message. Auth failures, rate limiting, or network errors will all look identical to "PR not found", making troubleshooting harder for users.♻️ Capture and surface gh's stderr on failure
- if [ -n "$repo_arg" ]; then - output=$(gh pr view "$selector" --repo "$repo_arg" --json "$json_fields" --template "$template" 2>/dev/null) || { - log_error "Could not resolve pull request: $selector" - return 1 - } - else - output=$(gh pr view "$selector" --json "$json_fields" --template "$template" 2>/dev/null) || { - log_error "Could not resolve pull request: $selector" - return 1 - } - fi + local gh_stderr + if [ -n "$repo_arg" ]; then + output=$(gh pr view "$selector" --repo "$repo_arg" --json "$json_fields" --template "$template" 2>&1 >/dev/null); gh_stderr="$output" + output=$(gh pr view "$selector" --repo "$repo_arg" --json "$json_fields" --template "$template" 2>/dev/null) || { + log_error "Could not resolve pull request: $selector" + [ -n "$gh_stderr" ] && log_info "$gh_stderr" + return 1 + } + else + ... + fi(Simplify by capturing stderr once via a temp var/
2> >(...)-free approach appropriate for Bash 3.2.)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/commands/pr.sh` around lines 9 - 44, The _pr_resolve helper is swallowing gh errors by redirecting stderr to /dev/null, so auth/network/rate-limit failures are indistinguishable from a missing PR. Update _pr_resolve to capture gh pr view stderr once and surface that detail in the log_error path, while still handling both repo_arg and non-repo_arg calls. Keep the parsing of _ctx_pr_number and related fields unchanged, but make the failure message include gh’s actual stderr so users can diagnose the real cause.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/commands/pr.sh`:
- Around line 84-110: _pr_remote_for_url currently compares remote URLs after
only trimming trailing slash and .git, so SSH remotes from git remote get-url
won’t match the HTTPS URL shape used by gh pr view. Update
_pr_normalize_repo_url to canonicalize SSH/HTTPS variants of the same GitHub
repo (including scp-style git@host:owner/repo and ssh:// URLs) into one
comparable form before _pr_remote_for_url does the equality check. Keep the fix
localized to _pr_normalize_repo_url and preserve the existing lookup flow in
_pr_remote_for_url and _pr_configure_base_remote_for_gh so real remotes like
origin are reused instead of creating synthetic gtr-pr-* remotes.
In `@tests/cmd_pr.bats`:
- Around line 112-118: The cmd_pr "requires GitHub CLI" test can still hit a
real gh binary on PATH after removing only the mock symlink. Update the test
setup in cmd_pr.bats to fully control PATH (or otherwise ensure no fallback gh
exists), and assert the missing-CLI failure by checking stderr for the expected
"gh not found" / "GitHub CLI" message. Use the cmd_pr test case and the existing
TEST_MOCK_BIN setup to keep the failure path deterministic.
---
Nitpick comments:
In `@lib/commands/pr.sh`:
- Around line 9-44: The _pr_resolve helper is swallowing gh errors by
redirecting stderr to /dev/null, so auth/network/rate-limit failures are
indistinguishable from a missing PR. Update _pr_resolve to capture gh pr view
stderr once and surface that detail in the log_error path, while still handling
both repo_arg and non-repo_arg calls. Keep the parsing of _ctx_pr_number and
related fields unchanged, but make the failure message include gh’s actual
stderr so users can diagnose the real cause.
In `@tests/init.bats`:
- Around line 966-976: The setup in the gtr bash cache test is overcomplicated
and effectively always falls through to initialization, so simplify the logic in
the documented bash setup regenerates old schema cache case by calling cmd_init
bash directly after seeding the stale cache. Update the test body around the
local _gtr_init and cmd_init bash usage to remove the redundant file-check/grep
conditional and the trailing || true, keeping the intent clear and consistent
with the existing cache-regeneration tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 9e39081a-7ed1-4aaf-9474-fa56092f09b7
📒 Files selected for processing (16)
README.mdbin/git-gtrcompletions/_git-gtrcompletions/git-gtr.fishcompletions/gtr.bashdocs/configuration.mdlib/commands/create.shlib/commands/help.shlib/commands/init.shlib/commands/pr.shlib/core.shscripts/generate-completions.shtests/cmd_help.batstests/cmd_pr.batstests/core_create_worktree.batstests/init.bats
Assisted-by: pi:gpt-5.5 Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Description
git gtr pr <number|url|branch>to create PR review worktrees.gtr pr <selector> --cdvia shell integration.gh pr viewworks from created PR worktrees.Motivation
gh pr checkoutchecks out PRs in the current working tree; this adds the equivalent workflow forgit gtrworktrees.Type of Change
Testing
Manual Testing Checklist
Tested on:
Core functionality tested:
git gtr new <branch>- Create worktreegit gtr go <branch>- Navigate to worktreegit gtr editor <branch>- Open in editor (if applicable)git gtr ai <branch>- Start AI tool (if applicable)git gtr rm <branch>- Remove worktreegit gtr list- List worktreesgit gtr config- Configuration commands (if applicable)git gtr pr,gtr pr --cd,git gtr initTest Steps
bash -n bin/git-gtr lib/commands/*.sh scripts/generate-completions.sh completions/gtr.bash tests/*.bats./scripts/generate-completions.sh --checkgit diff --checkhttps://github.com/cataclysmbn/Cataclysm-BN/pull/9664in a fork clone and rungh pr viewfrom inside it.Expected behavior:
git gtr prcreates a separate worktree at the PR head commit.gtr pr --cdchanges into the new worktree with shell integration.gh pr viewresolves the PR from inside the created worktree.Actual behavior:
batsandshellcheckwere not available locally.Breaking Changes
Checklist
Before submitting this PR, please check:
git gtr(production) and./bin/gtr(development)License Acknowledgment
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache License 2.0.
PR opened by gpt-5.5 xhigh on pi
Summary by CodeRabbit
New Features
git gtr prto create a local worktree for GitHub pull requests (supports branch/repo/remote selection, editor/AI startup, and non-interactive mode).--cdbehavior for PR worktrees, including shell-integration support to land in the created directory.Bug Fixes
Documentation
git gtr prusage, options, and examples.Completions
prsubcommand and related flags.Tests