Repository navigation
Make worktree removal survive read-only directories - #268
Merged
Merged
Conversation
git worktree remove fails partway through a read-only directory, such as Go's module cache, and still deletes the worktree's admin dir, which orphans the checkout. Add worktree_remove to lib/git-worktree.sh, which makes every directory writable before it calls git, unless git will refuse the removal or the directory is already gone. tree-me and git-bclean-local now remove worktrees through it. git-bclean-local now detects uncommitted changes from git's refusal, as it already did for locks. disk-cleanup's make_writable_cmd prints the same find command as the new make_writable helper and could switch to it. Claude-Session: https://claude.ai/code/session_01AovXvX6L3zUjLxi9RCBWt6
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.
git worktree removefails partway through a read-only directory, and git deletes the worktree's admin dir anyway. The checkout stays on disk with a.gitfile that points at nothing, sotree-meandgit worktree liststop seeing it. Go makes its module cache read-only, so posthog worktrees created before posthog's flox manifest setGOFLAGS=-modcacherwhit this when removed. One orphan I found was 5.2G.worktree_removeinbin/lib/git-worktree.shgives the owner write permission on every read-only directory and then calls git.tree-meandgit-bclean-localboth remove worktrees through it. It leaves permissions alone when git will refuse anyway (main worktree, locked, or uncommitted changes without-f). If a directory can't be made writable, it doesn't call git, so it never leaves a worktree half-deleted. It doesn't predict git's refusal for populated submodules, so in that case the directories become writable and git removes nothing.git-bclean-localnow learns about uncommitted changes from git's refusal message instead of runninggit statusitself. As a result, it reports a worktree that is both locked and dirty as locked.I think disk-cleanup's
make_writable_cmdcould switch to the newmake_writablelater, since both run the samefindcommand.Test plan
bin/lib/test-tree-me-remove.shand the newbin/lib/test-git-bclean-local.shcover a worktree with a read-only directory, a worktree whose directory is already gone, and refused removals that keep their permissions. The removal tests failed before the fix./bin/bash3.2.https://claude.ai/code/session_01AovXvX6L3zUjLxi9RCBWt6