Repository navigation
feat: wt delete --dry-run and destructive-path audit - #40
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a --dry-run preview mode to the wt delete command so users/automation can see what worktrees/branches would be removed (and related hazards) while exercising the same decision logic as a real run, but with all leaf mutations suppressed. It also records the associated “destructive-path audit” and updates CLI surface + memory docs to reflect the new contract.
Changes:
- Adds
--dry-runtowt delete, threadsdryRun boolthrough delete handlers, and gates mutation seams (worktree removal, branch deletion, stash/discard) behind preview output. - Adds extensive unit + integration coverage for dry-run behavior across resolution paths and hazard reporting.
- Updates CLI spec + memory docs (and fab change artifacts) to document the new contract and the audit results.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/cmd/wt/delete.go | Implements --dry-run and threads/gates mutations; adds preview header + “Would …” lines. |
| src/cmd/wt/delete_test.go | Adds unit tests covering dry-run output and no-mutation guarantees across paths/flags. |
| src/cmd/wt/integration_test.go | Adds end-to-end dry-run tests asserting state remains byte-identical. |
| docs/specs/cli-surface.md | Documents --dry-run in the published CLI surface table for wt delete. |
| docs/memory/wt-cli/toolkit-standards-conformance.md | Updates standards conformance memory to mark principle №5 as closed via this change. |
| docs/memory/wt-cli/index.md | Adds the new delete dry-run contract to the wt-cli memory index. |
| docs/memory/wt-cli/flag-naming-conventions.md | Records --dry-run as long-only per flag surface conventions. |
| docs/memory/wt-cli/delete-dry-run-contract.md | Adds a full behavioral contract for wt delete --dry-run plus audit dispositions. |
| fab/changes/260717-p5m9-delete-dry-run/plan.md | Captures plan/requirements/acceptance and audit dispositions for the change. |
| fab/changes/260717-p5m9-delete-dry-run/intake.md | Captures intake context and intended contract for --dry-run and the audit. |
| fab/changes/260717-p5m9-delete-dry-run/.status.yaml | Records change metadata and stage progression for the fab workflow. |
| fab/changes/260717-p5m9-delete-dry-run/.history.jsonl | Records fab workflow history events for the change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if dryRun { | ||
| fmt.Printf("Would remove worktree: %s\n", name) | ||
| handleBranchCleanup(branch, name, deleteBranch, deleteRemote, dryRun) | ||
| return nil | ||
| } |
There was a problem hiding this comment.
Fixed — under --dry-run without --stash, handleDeleteByName now emits "Would discard uncommitted changes (use --stash to preserve them)" for a dirty target, matching the live force-removal. (4b42c4f)
| if dryRun { | ||
| fmt.Printf("Would remove worktree: %s\n", w.name) | ||
| handleBranchCleanup(w.branch, w.name, deleteBranch, deleteRemote, dryRun) | ||
| continue | ||
| } |
There was a problem hiding this comment.
Fixed — handleDeleteMultiple now emits the discard-hazard line per dirty target under --dry-run without --stash, aligning the preview with the live force-removal. (4b42c4f)
| if dryRun { | ||
| fmt.Printf("Would remove worktree: %s\n", w.name) | ||
| handleBranchCleanup(w.branch, w.name, deleteBranch, deleteRemote, dryRun) | ||
| continue | ||
| } |
There was a problem hiding this comment.
Fixed — handleDeleteAll now emits "Would discard uncommitted changes (use --stash to preserve them)" for dirty targets under --dry-run, closing the last preview↔live gap. (4b42c4f)
Surface the discard-uncommitted-changes hazard under --dry-run for the ByName, Multiple, and All delete paths. These paths force-remove worktrees live (RemoveWorktree(..., true) discards dirty changes) but their dry-run previews omitted the discard warning when --stash was not set, misaligning preview vs. live output (plan R6). Only handleDeleteCurrent handled it. Extract the dir-scoped dirty check from handleStashInDir into a reusable worktreeIsDirty helper and emit "Would discard uncommitted changes (use --stash to preserve them)" per dirty target when not stashing. Adds regression tests for the ByName/Multiple/All discard-preview and the clean-worktree no-op.
ae2b1b8 to
2e0a3a0
Compare
Meta
p5m9excludes
fab/,docs/· generated by fab-kit v2.15.5Pipeline: intake ✓ → apply ✓ → review ✓ → hydrate ✓ → ship → review-pr
Summary
wt deleteis the toolkit's most destructive command, yet had no way to preview what an invocation would do — especially under selector forms (--all,--stale, positionals) and the tri-state--branchauto logic. This closes the toolkit standards gap (principle No.5) by adding--dry-run, sharing the live decision path and gating only the leaf mutations, plus an audit confirmingwt deleteis the only wt-owned destructive write.Changes
--dry-runflag onwt deleteWould …lines, unchanged exit codes)--dry-run