Skip to content

fix: wt new resumes existing worktrees instead of erroring#22

Open
ukanga wants to merge 5 commits intomainfrom
fix-wt19
Open

fix: wt new resumes existing worktrees instead of erroring#22
ukanga wants to merge 5 commits intomainfrom
fix-wt19

Conversation

@ukanga
Copy link
Copy Markdown
Collaborator

@ukanga ukanga commented May 9, 2026

Closes #19

What changed

wt new <name> now behaves idempotently when a worktree already exists:

  • Registered worktree — prints Worktree '<name>' already exists at <path>, entering it. to stderr, then drops into the shell (or prints the path for --print-path). The migration step is skipped, so no stash is created and the main repo's branch is not switched.
  • Orphan directory (exists on disk but not tracked by git) — exits non-zero with an actionable error naming the path and suggesting git worktree prune or manual removal. The directory is not modified.
  • Fresh create — unchanged behaviour.

Commits

  • fix(worktree): replace bare path.exists() bail in create_worktree with a two-branch check against git worktree list
  • fix(new): intercept in cmd_new before the migration step; reuse existing get_worktree_info + spawn_wt_shell
  • docs: update README and commands/do.md

Tests

Three new integration tests in tests/new_resume_test.rs covering fresh, already-registered, and orphan states. The orphan test confirms the directory is left untouched after the error.

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.

wt new <name> should resume the existing worktree instead of erroring when one is already registered

1 participant