Skip to content

feat: open existing worktree on duplicate pr checkout - #161

Merged
raphi011 merged 2 commits into
raphi011:mainfrom
ppn26:pr-checkout-already-exists
Apr 1, 2026
Merged

raphi011 merged 2 commits into
raphi011:mainfrom
ppn26:pr-checkout-already-exists

Conversation

@ppn26

@ppn26 ppn26 commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

When wt pr checkout targets a branch that already has a worktree, open it
instead of failing with a fatal git error. Fetches latest changes, refreshes
PR cache, and runs hooks with action="open".

Mirrors the behavior already implemented for wt checkout in c730458.

Breaking Changes

  • wt pr checkout <number> no longer errors when the branch already has a
    worktree — it opens it instead.

Test Coverage

  • Integration tests added: 1

🤖 Generated with Claude Code

@raphi011

Copy link
Copy Markdown
Owner

Review Feedback

Hook action should stay ActionPR, not ActionOpen

wt pr checkout is semantically a PR action — if the user just wanted to open an existing worktree they'd use wt co <branch>. Hooks configured with on=["pr"] should still fire when reopening a PR worktree. Keep action = hooks.ActionPR for all pr checkout paths.

Test coverage

The test calls findWorktreeForBranch and openExistingWorktree directly, which are already covered by checkout tests. The new code unique to this PR (the else if placement, hook action, output message selection) isn't exercised. Consider verifying stdout output ("Opened worktree" vs "Created worktree") at minimum.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Mar 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/wt/pr_cmd.go 0.00% 12 Missing ⚠️

📢 Thoughts on this report? Let us know!

@raphi011 raphi011 closed this Apr 1, 2026
@raphi011 raphi011 reopened this Apr 1, 2026
ppn26 and others added 2 commits April 1, 2026 09:38
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Keep hooks.ActionPR for all pr checkout paths (don't switch to
  ActionOpen — pr checkout is semantically a PR action)
- Rewrite test to verify the actual output message selection logic
  from pr_cmd.go instead of calling unrelated openExistingWorktree

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ppn26
ppn26 force-pushed the pr-checkout-already-exists branch from 3c5b4c1 to 33adf9b Compare April 1, 2026 07:38
@raphi011
raphi011 merged commit ae4ac79 into raphi011:main Apr 1, 2026
1 of 2 checks passed
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