Skip to content

fix(dev-lead): release stale PR-branch worktrees before checkout (#470) - #494

Merged
don-petry merged 4 commits into
mainfrom
fix/worktree-branch-collision-470
Jun 8, 2026
Merged

don-petry merged 4 commits into
mainfrom
fix/worktree-branch-collision-470

Conversation

@don-petry

Copy link
Copy Markdown
Collaborator

Summary

Fixes #470 — checkout_pr_in_worktree aborts with fatal: '<branch>' is already used by worktree at '<stale path>' (exit status 128) when a crashed prior run on the same runner left the PR's head branch checked out in a now-defunct worktree. This broke review-changes on #383 (run 27107230249), which then reported ci-failing and could never be reviewed by the cascade.

Fix

Before gh pr checkout, checkout_pr_in_worktree now clears stale state:

  1. git worktree prune — drops registry entries whose directories are gone.
  2. Looks up the PR head branch and releases whatever holds it:
    • the main agent checkout → git checkout --detach in place (it can't be removed);
    • any other worktree → git worktree remove --force;
    • then git worktree prune again.

Tests

tests/dev-lead/unit/test_pr_worktree.bats — 3 new cases for every collision shape:

  • PR branch held by a stale sibling worktree still on disk;
  • stale registry entry whose directory was deleted;
  • the agent checkout itself on the PR branch (detached in place, never removed).

Local: full dev-lead unit suite 372/372, shellcheck --severity=warning -x clean.

Note

Prior autonomous dev-lead runs reported this issue "Implementation Complete" but committed to the already-merged branch fix/dev-lead-pr-worktree-checkout (PR #449, closed) and never opened a PR — so the fix never reached main, and retriggers dedup-skipped on the stale dev-lead/issue-470-* branches. Implemented manually on a fresh branch off main.

🤖 Generated with Claude Code

`checkout_pr_in_worktree` did `git worktree add --detach` then `gh pr
checkout`, which aborts with

  fatal: '<branch>' is already used by worktree at '<stale path>'
  failed to run git: exit status 128

when a crashed prior run on the same runner left the PR's head branch
checked out in a now-defunct worktree (issue #470; run 27107230249 broke
review-changes on PR #383, which then showed ci-failing and could never be
reviewed).

Before checking the PR branch out, the function now:
  1. `git worktree prune` — drop registry entries whose dirs are gone;
  2. look up the PR head branch and release whoever holds it — detach the
     main agent checkout in place (it can't be removed), force-remove any
     other worktree — then prune again.

Adds 3 bats tests covering all three collision shapes (stale sibling
worktree on disk, stale registry entry with dir deleted, agent checkout
itself on the branch). Full dev-lead unit suite: 372/372; shellcheck clean.

Note: prior dev-lead runs reported this "complete" but committed to the
already-merged branch fix/dev-lead-pr-worktree-checkout and never opened a
PR, so the fix never reached main. Implemented manually on a fresh branch.

Closes #470

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 8, 2026 17:48
@don-petry
don-petry requested a review from a team as a code owner June 8, 2026 17:48

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces recovery logic to clear stale Git worktree states left by crashed prior runs, preventing checkout collisions when checking out a PR branch. It also adds comprehensive unit tests to verify recovery under various scenarios. A review comment suggests normalizing the worktree and agent directory paths using git rev-parse --show-toplevel before comparing them, ensuring robust matching on systems with symlinks.

Comment thread scripts/lib/pr-worktree.sh
@don-petry
don-petry enabled auto-merge (squash) June 8, 2026 17:49
…view)

Gemini review on PR #494: git worktree list emits resolved paths but
PR_WORKTREE_AGENT_DIR comes from pwd and may contain symlinks (macOS, some
CI runners). Resolve both with `pwd -P` before deciding detach-vs-remove,
so the agent's own checkout isn't mis-routed to force-remove (a no-op that
would leave the branch unreleased).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses dev-lead failures caused by leftover/stale git worktrees on the same runner, where gh pr checkout can abort with “branch is already used by worktree …” (issue #470), preventing automated review/fix runs from proceeding.

Changes:

  • Add pre-checkout cleanup logic to prune stale worktrees and release the PR head branch from any existing worktree holder (including detaching the agent checkout when necessary).
  • Extend unit coverage with new Bats cases for the main collision shapes (stale sibling worktree, stale registry entry, agent checkout holding the branch).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
scripts/lib/pr-worktree.sh Adds collision-recovery logic before creating/checking out the PR worktree.
tests/dev-lead/unit/test_pr_worktree.bats Adds regression tests covering worktree collision recovery scenarios.

Comment thread scripts/lib/pr-worktree.sh
Comment thread tests/dev-lead/unit/test_pr_worktree.bats Outdated
Comment thread tests/dev-lead/unit/test_pr_worktree.bats Outdated
@don-petry
don-petry disabled auto-merge June 8, 2026 17:51
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — fix-bot-comment (no-changes)

Agent reasoning
Issues addressed: 0
Files changed: none
Skipped (informational): 0
```
The SonarCloud comment is a clean passing report — Quality Gate passed with 0 new issues, 0 security hotspots, and 0 duplication. There are no actionable findings to fix.
There are also no Tier 1 CI blockers (no failed/cancelled/timed-out checks) and no `CHANGES_REQUESTED` reviews. The PR is unblocked pending the in-progress checks (CodeQL, bats, SonarCloud scan, etc.) that are still running.

@don-petry
don-petry enabled auto-merge (squash) June 8, 2026 17:52
… dirs

Copilot review on PR #494:
- PR_WORKTREE_AGENT_DIR is pwd, which can be a SUBDIRECTORY of the repo,
  while `git worktree list` reports the worktree root — so the equality
  check could miss the agent checkout (collision unfixed) or target the
  main worktree. Resolve via `git rev-parse --show-toplevel` (+ pwd -P)
  before comparing. Adds a subdirectory regression test.
- The two new collision tests leaked their mktemp parent dirs; capture and
  rm -rf them after the test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@don-petry
don-petry disabled auto-merge June 8, 2026 17:55
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — fix-bot-comment (no-changes)

Agent reasoning
Issues addressed: 0
Files changed: none
Skipped (informational): 0
Notes:
  - Quality Gate passed: 0 new issues, 0 security hotspots, 0 accepted issues
  - All CI checks green (success or skipped — no failures)
  - No CHANGES_REQUESTED reviews — zero Tier 1 blockers
  - No open review threads from sonarqubecloud[bot] to resolve
```
The SonarCloud analysis is fully clean — no actionable findings and no stale threads to resolve. The PR is unblocked from this bot's perspective.

@don-petry
don-petry enabled auto-merge (squash) June 8, 2026 17:56

@donpetry-bot donpetry-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review — APPROVED ✓

Risk: MEDIUM
Reviewed commit: 4af1196c3982623a8fea18d528e475bb7ef98483
Review mode: triage-approved (single reviewer)

Summary

Targeted dev-lead fix for issue #470: clears stale worktree state before gh pr checkout so a crashed prior run on the same runner can't permanently break review-changes for a PR. Logic is well-scoped (prune → release branch holder → prune again), distinguishes the agent's own checkout (detach in place) from sibling worktrees (force-remove), and ships with focused regression tests for all four collision shapes (sibling, missing dir, agent self-hold, agent self-hold from subdir cwd).

Linked issue analysis

Closes #470 (checkout_pr_in_worktree aborts with fatal: '<branch>' is already used by worktree at '<stale path>'). The diff directly fixes the failure mode described in the issue — prior runs leaving the PR head branch claimed by a defunct worktree — and the new bats cases reproduce each crash shape before exercising the fix. PR-body context about the previously-merged-but-orphaned #449 attempt is consistent with what's on main (fix/dev-lead-pr-worktree-checkout not present in current source).

Findings

Prior bot findings — all resolved in head commit 4af1196:

  • Gemini (high): direct string-equality against PR_WORKTREE_AGENT_DIR would misroute on symlinked runners → fixed: both sides now canonicalized via pwd -P before comparison.
  • Copilot: PR_WORKTREE_AGENT_DIR from pwd may be a subdir, breaking the equality check → fixed: git rev-parse --show-toplevel resolves to the repo root first; a dedicated subdirectory regression test was added.
  • Copilot (×2): two new tests leaked mktemp -d parent dirs → fixed: both now rm -rf the captured parent at end.

Independent observations (non-blocking):

  • gh pr view ... 2>/dev/null || true silently falls through to a no-op if the API call fails (rate limit, transient network); on collision the next gh pr checkout will then surface the original exit 128 — acceptable degradation, matches today's behavior.
  • The cleanup runs under the EXIT trap chain established two lines earlier, so failures inside the loop won't leak the PR worktree.
  • No secrets, no migrations, no GHA workflow changes, no new dependencies.

CI status

All required checks green: shellcheck, bats, unit-tests, CodeQL (actions+python), Agent Security Scan, AgentShield, Secret scan (gitleaks), SonarCloud (Quality Gate passed, 0 new issues), validate-agent-profiles, gh-aw-compile. Dependency-audit ecosystem matrices skipped as expected (no ecosystem files changed). PR is BEHIND main but MERGEABLE — base ref update only.


Reviewed automatically by the PR-review agent (single-reviewer mode: opus 4.7). Reply if you need a human review.

@don-petry
don-petry disabled auto-merge June 8, 2026 17:59
@sonarqubecloud

sonarqubecloud Bot commented Jun 8, 2026

Copy link
Copy Markdown

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (no-changes)

No changes were needed for this PR.

@don-petry
don-petry merged commit 93f03db into main Jun 8, 2026
26 checks passed
@don-petry
don-petry deleted the fix/worktree-branch-collision-470 branch June 8, 2026 18:00

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a699132666

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# detaching releases the branch so the new worktree can claim it.
git -C "$_wt_path" checkout --detach --quiet 2>/dev/null || true
else
git worktree remove --force "$_wt_path" 2>/dev/null || true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid deleting worktrees by branch name alone

On a persistent runner, if this repo has any other registered worktree checked out to a local branch whose name matches the PR's headRefName (common for fork PRs using names like main or patch-1), this removes that worktree even though it may be unrelated to a stale dev-lead temp checkout. I checked git worktree remove -h; --force forces removal even when the worktree is dirty or locked, so this can discard active/uncommitted work instead of only releasing stale /tmp/dev-lead-wt-* worktrees.

Useful? React with 👍 / 👎.

don-petry added a commit that referenced this pull request Jun 12, 2026
… (#494)

* fix(dev-lead): release stale PR-branch worktrees before checkout (#470)

`checkout_pr_in_worktree` did `git worktree add --detach` then `gh pr
checkout`, which aborts with

  fatal: '<branch>' is already used by worktree at '<stale path>'
  failed to run git: exit status 128

when a crashed prior run on the same runner left the PR's head branch
checked out in a now-defunct worktree (issue #470; run 27107230249 broke
review-changes on PR #383, which then showed ci-failing and could never be
reviewed).

Before checking the PR branch out, the function now:
  1. `git worktree prune` — drop registry entries whose dirs are gone;
  2. look up the PR head branch and release whoever holds it — detach the
     main agent checkout in place (it can't be removed), force-remove any
     other worktree — then prune again.

Adds 3 bats tests covering all three collision shapes (stale sibling
worktree on disk, stale registry entry with dir deleted, agent checkout
itself on the branch). Full dev-lead unit suite: 372/372; shellcheck clean.

Note: prior dev-lead runs reported this "complete" but committed to the
already-merged branch fix/dev-lead-pr-worktree-checkout and never opened a
PR, so the fix never reached main. Implemented manually on a fresh branch.

Closes #470

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(dev-lead): canonicalize worktree paths before comparison (#470 review)

Gemini review on PR #494: git worktree list emits resolved paths but
PR_WORKTREE_AGENT_DIR comes from pwd and may contain symlinks (macOS, some
CI runners). Resolve both with `pwd -P` before deciding detach-vs-remove,
so the agent's own checkout isn't mis-routed to force-remove (a no-op that
would leave the branch unreleased).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(dev-lead): compare worktree by repo top-level; clean up test temp dirs

Copilot review on PR #494:
- PR_WORKTREE_AGENT_DIR is pwd, which can be a SUBDIRECTORY of the repo,
  while `git worktree list` reports the worktree root — so the equality
  check could miss the agent checkout (collision unfixed) or target the
  main worktree. Resolve via `git rev-parse --show-toplevel` (+ pwd -P)
  before comparing. Adds a subdirectory regression test.
- The two new collision tests leaked their mktemp parent dirs; capture and
  rm -rf them after the test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: donpetry-bot <{}+donpetry-bot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
don-petry added a commit that referenced this pull request Jun 14, 2026
… (#494)

* fix(dev-lead): release stale PR-branch worktrees before checkout (#470)

`checkout_pr_in_worktree` did `git worktree add --detach` then `gh pr
checkout`, which aborts with

  fatal: '<branch>' is already used by worktree at '<stale path>'
  failed to run git: exit status 128

when a crashed prior run on the same runner left the PR's head branch
checked out in a now-defunct worktree (issue #470; run 27107230249 broke
review-changes on PR #383, which then showed ci-failing and could never be
reviewed).

Before checking the PR branch out, the function now:
  1. `git worktree prune` — drop registry entries whose dirs are gone;
  2. look up the PR head branch and release whoever holds it — detach the
     main agent checkout in place (it can't be removed), force-remove any
     other worktree — then prune again.

Adds 3 bats tests covering all three collision shapes (stale sibling
worktree on disk, stale registry entry with dir deleted, agent checkout
itself on the branch). Full dev-lead unit suite: 372/372; shellcheck clean.

Note: prior dev-lead runs reported this "complete" but committed to the
already-merged branch fix/dev-lead-pr-worktree-checkout and never opened a
PR, so the fix never reached main. Implemented manually on a fresh branch.

Closes #470

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(dev-lead): canonicalize worktree paths before comparison (#470 review)

Gemini review on PR #494: git worktree list emits resolved paths but
PR_WORKTREE_AGENT_DIR comes from pwd and may contain symlinks (macOS, some
CI runners). Resolve both with `pwd -P` before deciding detach-vs-remove,
so the agent's own checkout isn't mis-routed to force-remove (a no-op that
would leave the branch unreleased).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(dev-lead): compare worktree by repo top-level; clean up test temp dirs

Copilot review on PR #494:
- PR_WORKTREE_AGENT_DIR is pwd, which can be a SUBDIRECTORY of the repo,
  while `git worktree list` reports the worktree root — so the equality
  check could miss the agent checkout (collision unfixed) or target the
  main worktree. Resolve via `git rev-parse --show-toplevel` (+ pwd -P)
  before comparing. Adds a subdirectory regression test.
- The two new collision tests leaked their mktemp parent dirs; capture and
  rm -rf them after the test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: donpetry-bot <{}+donpetry-bot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
don-petry added a commit that referenced this pull request Jun 18, 2026
… (#494)

* fix(dev-lead): release stale PR-branch worktrees before checkout (#470)

`checkout_pr_in_worktree` did `git worktree add --detach` then `gh pr
checkout`, which aborts with

  fatal: '<branch>' is already used by worktree at '<stale path>'
  failed to run git: exit status 128

when a crashed prior run on the same runner left the PR's head branch
checked out in a now-defunct worktree (issue #470; run 27107230249 broke
review-changes on PR #383, which then showed ci-failing and could never be
reviewed).

Before checking the PR branch out, the function now:
  1. `git worktree prune` — drop registry entries whose dirs are gone;
  2. look up the PR head branch and release whoever holds it — detach the
     main agent checkout in place (it can't be removed), force-remove any
     other worktree — then prune again.

Adds 3 bats tests covering all three collision shapes (stale sibling
worktree on disk, stale registry entry with dir deleted, agent checkout
itself on the branch). Full dev-lead unit suite: 372/372; shellcheck clean.

Note: prior dev-lead runs reported this "complete" but committed to the
already-merged branch fix/dev-lead-pr-worktree-checkout and never opened a
PR, so the fix never reached main. Implemented manually on a fresh branch.

Closes #470

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(dev-lead): canonicalize worktree paths before comparison (#470 review)

Gemini review on PR #494: git worktree list emits resolved paths but
PR_WORKTREE_AGENT_DIR comes from pwd and may contain symlinks (macOS, some
CI runners). Resolve both with `pwd -P` before deciding detach-vs-remove,
so the agent's own checkout isn't mis-routed to force-remove (a no-op that
would leave the branch unreleased).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(dev-lead): compare worktree by repo top-level; clean up test temp dirs

Copilot review on PR #494:
- PR_WORKTREE_AGENT_DIR is pwd, which can be a SUBDIRECTORY of the repo,
  while `git worktree list` reports the worktree root — so the equality
  check could miss the agent checkout (collision unfixed) or target the
  main worktree. Resolve via `git rev-parse --show-toplevel` (+ pwd -P)
  before comparing. Adds a subdirectory regression test.
- The two new collision tests leaked their mktemp parent dirs; capture and
  rm -rf them after the test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: donpetry-bot <{}+donpetry-bot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
don-petry added a commit that referenced this pull request Jun 25, 2026
… (#494)

* fix(dev-lead): release stale PR-branch worktrees before checkout (#470)

`checkout_pr_in_worktree` did `git worktree add --detach` then `gh pr
checkout`, which aborts with

  fatal: '<branch>' is already used by worktree at '<stale path>'
  failed to run git: exit status 128

when a crashed prior run on the same runner left the PR's head branch
checked out in a now-defunct worktree (issue #470; run 27107230249 broke
review-changes on PR #383, which then showed ci-failing and could never be
reviewed).

Before checking the PR branch out, the function now:
  1. `git worktree prune` — drop registry entries whose dirs are gone;
  2. look up the PR head branch and release whoever holds it — detach the
     main agent checkout in place (it can't be removed), force-remove any
     other worktree — then prune again.

Adds 3 bats tests covering all three collision shapes (stale sibling
worktree on disk, stale registry entry with dir deleted, agent checkout
itself on the branch). Full dev-lead unit suite: 372/372; shellcheck clean.

Note: prior dev-lead runs reported this "complete" but committed to the
already-merged branch fix/dev-lead-pr-worktree-checkout and never opened a
PR, so the fix never reached main. Implemented manually on a fresh branch.

Closes #470

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(dev-lead): canonicalize worktree paths before comparison (#470 review)

Gemini review on PR #494: git worktree list emits resolved paths but
PR_WORKTREE_AGENT_DIR comes from pwd and may contain symlinks (macOS, some
CI runners). Resolve both with `pwd -P` before deciding detach-vs-remove,
so the agent's own checkout isn't mis-routed to force-remove (a no-op that
would leave the branch unreleased).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(dev-lead): compare worktree by repo top-level; clean up test temp dirs

Copilot review on PR #494:
- PR_WORKTREE_AGENT_DIR is pwd, which can be a SUBDIRECTORY of the repo,
  while `git worktree list` reports the worktree root — so the equality
  check could miss the agent checkout (collision unfixed) or target the
  main worktree. Resolve via `git rev-parse --show-toplevel` (+ pwd -P)
  before comparing. Adds a subdirectory regression test.
- The two new collision tests leaked their mktemp parent dirs; capture and
  rm -rf them after the test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: donpetry-bot <{}+donpetry-bot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
don-petry added a commit that referenced this pull request Jun 25, 2026
… (#494)

* fix(dev-lead): release stale PR-branch worktrees before checkout (#470)

`checkout_pr_in_worktree` did `git worktree add --detach` then `gh pr
checkout`, which aborts with

  fatal: '<branch>' is already used by worktree at '<stale path>'
  failed to run git: exit status 128

when a crashed prior run on the same runner left the PR's head branch
checked out in a now-defunct worktree (issue #470; run 27107230249 broke
review-changes on PR #383, which then showed ci-failing and could never be
reviewed).

Before checking the PR branch out, the function now:
  1. `git worktree prune` — drop registry entries whose dirs are gone;
  2. look up the PR head branch and release whoever holds it — detach the
     main agent checkout in place (it can't be removed), force-remove any
     other worktree — then prune again.

Adds 3 bats tests covering all three collision shapes (stale sibling
worktree on disk, stale registry entry with dir deleted, agent checkout
itself on the branch). Full dev-lead unit suite: 372/372; shellcheck clean.

Note: prior dev-lead runs reported this "complete" but committed to the
already-merged branch fix/dev-lead-pr-worktree-checkout and never opened a
PR, so the fix never reached main. Implemented manually on a fresh branch.

Closes #470

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(dev-lead): canonicalize worktree paths before comparison (#470 review)

Gemini review on PR #494: git worktree list emits resolved paths but
PR_WORKTREE_AGENT_DIR comes from pwd and may contain symlinks (macOS, some
CI runners). Resolve both with `pwd -P` before deciding detach-vs-remove,
so the agent's own checkout isn't mis-routed to force-remove (a no-op that
would leave the branch unreleased).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(dev-lead): compare worktree by repo top-level; clean up test temp dirs

Copilot review on PR #494:
- PR_WORKTREE_AGENT_DIR is pwd, which can be a SUBDIRECTORY of the repo,
  while `git worktree list` reports the worktree root — so the equality
  check could miss the agent checkout (collision unfixed) or target the
  main worktree. Resolve via `git rev-parse --show-toplevel` (+ pwd -P)
  before comparing. Adds a subdirectory regression test.
- The two new collision tests leaked their mktemp parent dirs; capture and
  rm -rf them after the test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: donpetry-bot <{}+donpetry-bot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

dev-lead: git worktree collision ('branch already used by worktree') breaks review-changes — blocks PR #383

3 participants