Repository navigation
fix(switch): refuse --path naming the bare repository; drop rm -rf hint for --path - #4532
Merged
Merged
Conversation
…nt for --path `wt switch --create x --path <bare-repo> --clobber` moved the bare repository aside: the overlap guard skipped a requested path equal to the git common dir, as it does for a registered worktree, but nothing later checks the git dir. The guard now refuses it. It also compares paths with canonicalize_with_parents, so a deep Windows path and a short root keep one spelling for starts_with. For a directory named by --path, the "Directory already exists" hint suggested `rm -rf` on it, though --path can name any directory, such as a project. That hint now suggests a different --path, keeping the --clobber command, which moves the directory to a backup. Both came in with --path (#4317). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
worktrunk-bot
approved these changes
Oct 20, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
worktrunk-bot
approved these changes
Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two problems with the new
wt switch --pathflag from #4317, found in release review.Bare repository moved aside.
wt switch --create x --path proj.git --clobberin a bare clone with no worktrees printedMoved ~/proj.git to ~/proj.git.bak.<ts> (--clobber)and created a worktree in the repository's place.reject_path_overlapping_worktreesskipped a requested path equal to any entry it checks, which is right for a registered worktree (validate_worktree_creationreports it by branch) but nothing later checks the git common dir. The guard now refuses that case with--path <dir> is the repository's git directory. The template route has the same exposure and is left to #4461; this guard runs only for--path.While there, the guard compares paths with
canonicalize_with_parentsrather thandunce::canonicalize, so a deep Windows path and the short root containing it get the same prefix spelling forstarts_with(the #3898 mismatch).rm -rfhint for a user-named directory. When the--pathdirectory exists, the hint suggestedrm -rf <path>, though--pathcan name any directory, such as a project. For--pathit now readsTo place the worktree elsewhere, choose a different --path; to overwrite (with backup), run wt switch --create --clobber <branch> --path=<path>. The template route's hint is unchanged.Verification: reproduced both on a build of
mainand confirmed the fix on this branch.test_bare_repo_switch_path_rejects_the_repositoryfails with the old guard (its snapshot shows theMoved … (--clobber)line), and theswitch_path_occupiedsnapshot shows the new hint.test_switch_path_naming_another_worktreepins that--pathnaming another branch's worktree, with--clobber, still reports that worktree's branch and leaves it in place. Ran the switch, bare-repository and error-display integration tests, clippy, and pre-commit.