Skip to content

feat(ui): allow deleting locked worktrees - #16

Merged
AgileIndustrialComplex merged 2 commits into
essafrom
delete-locked-worktrees
Jul 20, 2026
Merged

AgileIndustrialComplex merged 2 commits into
essafrom
delete-locked-worktrees

Conversation

@AgileIndustrialComplex

Copy link
Copy Markdown
Owner

Intent

The user hit a real 'fatal: contains modified or untracked files, use --force to delete it' error from wt when deleting worktrees; that turned out to be a stale binary (an earlier fix already handled dirty worktrees on branch essa), so we rebuilt/reinstalled it. As a follow-up, the user then explicitly asked to add the ability to delete LOCKED worktrees too, which was previously hard-rejected in code (internal/action/action.go had an early 'cannot delete a locked worktree' error, and internal/ui/ui.go excluded locked worktrees from being marked at all).

We deliberately reused the existing dirty/unmerged force-delete confirmation flow rather than adding a new one: locked worktrees can now be marked (toggleMarked no longer excludes Locked, only IsCurrent), and a marked batch containing a locked worktree routes through the same phrase-typed 'delete' confirmation (modeConfirmForceDelete) already used for unmerged branches and dirty worktrees, via a new hasLockedWorktree() check alongside hasUnmergedBranch/hasDirtyWorktree. The confirmation screen lists locked worktrees in their own section, separate from the unmerged/dirty sections.

On the git side, we found (verified by hand against a real locked+dirty worktree) that git worktree remove needs --force twice to remove a locked worktree - a single --force only overrides dirty state, not a lock (git's own docs: 'To remove a locked worktree, specify --force twice'). So deleteWorktreesWith in action.go now branches: Locked items get ["--force", "--force"], Dirty-only items keep a single ["--force"], and when both are set only the double-force is used (locked implies force twice covers dirty too) - we did not stack three force flags.

Updated the README's mark/delete section and the architecture paragraph to describe this, and updated/added tests in internal/action/action_test.go and internal/ui/ui_test.go, replacing the old 'rejects locked worktree' tests with tests asserting the new force-delete-with-double---force behavior, and added ui tests mirroring the existing dirty-worktree confirmation tests. All committed on this new branch delete-locked-worktrees (branched off essa, since essa had picked up uncommitted work and is the default branch). go build/vet/gofmt/test all pass.

What Changed

  • Allow locked worktrees to be marked and deleted through the picker’s phrase-typed confirmation flow, with locked items listed separately.
  • Remove locked worktrees using git worktree remove --force --force, while retaining a single --force for dirty-only worktrees.
  • Update the README, specification, and action/UI tests to document and verify locked worktree deletion.

Risk Assessment

✅ Low: The change is well-bounded and consistently implements locked-worktree marking, typed confirmation, separate display, and Git's required double-force removal.

Testing

The relevant package tests and full Go suite passed, and a real compiled CLI successfully marked, warned about, phrase-confirmed, and removed a locked-and-dirty Git worktree end-to-end; post-delete Git and filesystem checks confirmed both its worktree and branch were gone.

Evidence: Actual CLI force-delete confirmation screen
The following worktree(s) have modified or untracked files that will be permanently lost:
locked-demo …/demo-locked
The following worktree(s) are locked and will be force-unlocked and removed:
locked-demo …/demo-locked
Type "delete" and press Enter to proceed, or Esc to cancel:

>
Evidence: Actual CLI deletion result
Deleted branch locked-demo (was d49dfd4).
wt: deleted 1 branch(es)
Evidence: Post-deletion Git and filesystem state
git worktree list showed only main; git branch --list locked-demo returned empty; filesystem check reported: locked worktree path removed

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • go test ./internal/action ./internal/ui
  • go test ./...
  • Built ./cmd/wt, created a real secondary worktree, added an untracked file, and locked it using git worktree lock --reason 'active agent session'
  • Ran the compiled wt --no-color interactively, selected locked-demo, pressed c, D, and Enter, and verified the separate dirty and locked warnings plus the required delete phrase prompt
  • Typed delete and pressed Enter, then verified git worktree list --porcelain, git branch --list locked-demo, and the filesystem: the locked-and-dirty worktree path and branch were removed
  • git status --short in the validation worktree confirmed testing left no transient repository artifacts
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Locked worktrees can now be marked and deleted via the same
phrase-typed force-delete confirmation used for unmerged branches and
dirty worktrees, instead of being rejected outright. git requires
--force twice to remove a locked worktree, so deleteWorktreesWith now
passes --force --force for locked items.
@AgileIndustrialComplex
AgileIndustrialComplex merged commit e748da8 into essa Jul 20, 2026
5 checks passed
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