Repository navigation
fix: match worktree paths exactly so worktree-remove can't delete the wrong folder - #15
Merged
Merged
Conversation
Both commands decided "is this a git worktree?" by grepping `git worktree
list` for the directory's path as a substring, using `pwd` (not `pwd -P`)
in most places.
- worktree-remove: /x/site-junk matched a real worktree /x/site-junk-2, so
`ddev worktree-remove junk` passed the safety check and ran rm -rf on an
unrelated folder. --list showed it too.
- From a symlinked project path, a real worktree was not recognised, so it
was rm -rf'd without unregistering it and the next `ddev worktree` of the
same branch failed ("missing but already registered worktree").
- worktree --force: same symlink problem; and the prefix match made the
other-branch guard refuse a valid --force on a plain folder.
All checks now use the existing exact helpers (is_linked_worktree /
is_linked_worktree_of_source), which compare `git worktree list --porcelain`
entries after `pwd -P`. Five regression tests added.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Found by the code review of #13. Stacked on #13 because it uses that PR's test suite; GitHub will retarget it to
mainwhen #13 merges.The bug
Both commands decided "is this a git worktree?" by searching
git worktree listoutput for the folder's path as plain text, mostly withpwdinstead ofpwd -P.worktree-removecould delete an unrelated folder./x/site-junkmatches a real worktree at/x/site-junk-2. With both present,ddev worktree-remove junkprinted "verified as git worktree" and ranrm -rfonsite-junk/.--listalso showed it as a clone.rm -rf'd without removing git's registration, so the nextddev worktree <same branch>failed with "missing but already registered worktree". This affectedworktree-removeandworktree --force.worktree --forcerefused a valid replace. The guard that stops--forcereplacing another branch's worktree mistook a plainsite-feat/for the worktreesite-feat-2, and failed with "is a worktree for branch '(detached HEAD)'". Nothing was deleted.The fix
Every check now uses the exact-match helpers that already existed for
--path(is_linked_worktreeinworktree-remove,is_linked_worktree_of_sourceinworktree). They read theworktree <path>entries fromgit worktree list --porcelainand compare them topwd -P. The looseis_git_worktreehelper is removed. No other behavior changes.Tests
Five new unit tests. All five failed before the fix and pass after it:
worktree-removerefuses a folder whose path is a prefix of a real worktree's, and leaves its files alone.--listdoesn't show that folder.worktree-removefrom a symlinked path unregisters the worktree, and recreating it works.worktree --forcereplaces a plain folder that shares a prefix with a real worktree.worktree --forcefrom a symlinked path unregisters the old worktree.The full unit suite (67 tests) and shellcheck pass locally on macOS bash 3.2. I didn't test it with real DDEV.
🤖 Generated with Claude Code