Skip to content

feat: wt delete --dry-run and destructive-path audit - #40

Merged
sahil-noon merged 4 commits into
mainfrom
260717-p5m9-delete-dry-run
Jul 18, 2026
Merged

sahil-noon merged 4 commits into
mainfrom
260717-p5m9-delete-dry-run

Conversation

@sahil-noon

Copy link
Copy Markdown
Collaborator

Meta

Change ID Type Confidence Plan Review
p5m9 feat 4.0/5.0 11/11 tasks, 21/21 acceptance ✓ ✓ 2 cycles
Impact +/− Net
raw +1343 / −64 +1279
true +554 / −57 +497
└ impl +171 / −57 +114
└ tests +383 / −0 +383

excludes fab/, docs/ · generated by fab-kit v2.15.5

Pipeline: intake ✓ → apply ✓ → review ✓ → hydrate ✓ → ship → review-pr

Summary

wt delete is 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 --branch auto 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 confirming wt delete is the only wt-owned destructive write.

Changes

  • New --dry-run flag on wt delete
  • Preview shares the live code path (decision logic runs live; only leaf mutations are suppressed)
  • Consent and prompt interplay (confirmations skipped, hazards reported as preview lines, selection menu retained)
  • Preview output contract (stdout Would … lines, unchanged exit codes)
  • Destructive-path audit confirming no other wt command needs --dry-run

@sahil-noon
sahil-noon marked this pull request as ready for review July 17, 2026 22:46
@sahil-noon
sahil-noon requested a review from Copilot July 17, 2026 22:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-run to wt delete, threads dryRun bool through 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.

Comment thread src/cmd/wt/delete.go
Comment on lines +343 to +347
if dryRun {
fmt.Printf("Would remove worktree: %s\n", name)
handleBranchCleanup(branch, name, deleteBranch, deleteRemote, dryRun)
return nil
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread src/cmd/wt/delete.go
Comment on lines +467 to 471
if dryRun {
fmt.Printf("Would remove worktree: %s\n", w.name)
handleBranchCleanup(w.branch, w.name, deleteBranch, deleteRemote, dryRun)
continue
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread src/cmd/wt/delete.go
Comment on lines +556 to +560
if dryRun {
fmt.Printf("Would remove worktree: %s\n", w.name)
handleBranchCleanup(w.branch, w.name, deleteBranch, deleteRemote, dryRun)
continue
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

sahil87 added 4 commits July 18, 2026 10:20
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.
@sahil87
sahil87 force-pushed the 260717-p5m9-delete-dry-run branch from ae2b1b8 to 2e0a3a0 Compare July 18, 2026 04:51
@sahil-noon
sahil-noon merged commit 304dbc0 into main Jul 18, 2026
2 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.

3 participants