Skip to content

fix(cmd): detach worktrees before pool reuse#19

Merged
kunchenguid merged 4 commits into
mainfrom
fix/detach-dirty-worktrees
May 2, 2026
Merged

fix(cmd): detach worktrees before pool reuse#19
kunchenguid merged 4 commits into
mainfrom
fix/detach-dirty-worktrees

Conversation

@kunchenguid
Copy link
Copy Markdown
Owner

Summary

  • Detach worktrees when acquiring and returning them so dirty or branch-checked-out trees can be safely reset for reuse.
  • Make treehouse return --force recover conflicted or dirty worktrees through forced cleanup instead of failing before reset.
  • Update README and CLI help text to make the destructive --force cleanup behavior explicit, with e2e coverage for the detach and forced-return cases.

Risk Assessment

✅ Low: The change is narrowly scoped to detaching worktree HEADs before reuse/return and adds focused regression coverage, with no material issues found in the changed code.

Testing

  • Summary: Exercised the new dirty-worktree detach regressions plus the full Go test suite; all tests passed.
  • go test ./cmd
  • go test ./cmd -run 'Test(GetDetachesWorktreeWhenLeavingDirty|ReturnForceCleansAndDetachesCheckedOutBranch|ReturnForceCleansConflictedWorktree)$' -count=1
  • go test ./... -count=1
  • Outcome: ✅ passed across 1 run (28.6s)

Pipeline

Updates from git push no-mistakes

✅ **Rebase** - passed

Round 1 - passed ✅

🔧 **Review** - 1 issue found → auto-fixed

Round 1 - found 1 error

  • 🚨 cmd/return_cmd.go:47 - treehouse return --force now runs a non-forced git checkout --detach before cleanup. A dirty worktree with an unmerged/conflicted index can make this detach fail before pool.Release reaches ResetWorktree's forced checkout/reset, so --force can no longer recover and clean that state. Move the detach until after the non-force confirmation, or let the forced reset path handle detaching for --force.

Round 2 (auto-fix) - passed ✅

✅ **Test** - passed

Round 1 - passed ✅

  • go test ./cmd
  • go test ./cmd -run 'Test(GetDetachesWorktreeWhenLeavingDirty|ReturnForceCleansAndDetachesCheckedOutBranch|ReturnForceCleansConflictedWorktree)$' -count=1
  • go test ./... -count=1
🔧 **Document** - 1 issue found → auto-fixed (2)

Round 1 - found 1 info

  • ℹ️ README.md:151 - The return --force documentation still describes the flag only as skipping the dirty-check prompt, but the changed behavior now force-detaches and hard-resets/cleans worktrees so it can recover checked-out branches and conflicted states. Update the flag description to make the destructive cleanup behavior explicit, such as noting that it cleans/resets the worktree and returns it without prompting.

Round 2 (auto-fix) - found 1 info

  • ℹ️ cmd/return_cmd.go:74 - The Cobra help text for treehouse return --force still says Skip dirty check prompt, but the changed behavior now force-cleans/resets and detaches the worktree before returning it. Update the flag description used by treehouse return --help so the built-in CLI documentation matches the README and the new destructive cleanup behavior.

Round 3 (auto-fix) - passed ✅

✅ **Lint** - passed

Round 1 - passed ✅

✅ **Push** - passed

Round 1 - passed ✅

@kunchenguid kunchenguid merged commit 0d849a3 into main May 2, 2026
4 checks passed
@kunchenguid kunchenguid deleted the fix/detach-dirty-worktrees branch May 2, 2026 20:32
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.

1 participant