Skip to content

fix(prune): honor --dry-run flag (T-0175)#24

Merged
jadb merged 1 commit intomainfrom
fix/prune-dry-run
Apr 28, 2026
Merged

fix(prune): honor --dry-run flag (T-0175)#24
jadb merged 1 commit intomainfrom
fix/prune-dry-run

Conversation

@jadb
Copy link
Copy Markdown
Contributor

@jadb jadb commented Apr 28, 2026

Summary

  • git hop prune --dry-run was performing the prune instead of previewing it — runPrune never read the persistent --dry-run flag.
  • Refactor extracts runPruneFS(fs, st, dryRun) so the wiring is unit-testable; the prune helpers take dryRun and only mutate state when false; state.SaveState is gated on !dryRun.
  • Log lines are prefixed [dry-run] Would prune vs Pruning depending on mode, so the CLI output makes the difference visible.
  • Doctor's --fix path passes dryRun=false explicitly (no behavior change).

Closes T-0175.

Test plan

  • go build ./...
  • go test ./cmd/... ./internal/... — 698/698 pass (was 695; +3 new)
  • New TestRunPrune_DryRun — state.json unchanged after dry-run reporting 1 orphan
  • New TestRunPrune_Apply — in-memory state mutated when dryRun=false
  • Manual: built binary, fed a state.json with one orphan, verified prune --dry-run preserves it and prefixes logs with [dry-run] Would prune; subsequent prune (no flag) removes it

`git hop prune --dry-run` was performing the prune instead of
previewing it: runPrune never read the persistent --dry-run flag.

Refactor:
  - runPrune now reads the flag via cmd.Flags().GetBool("dry-run")
  - Extract runPruneFS(fs, st, dryRun) helper for unit testing
  - pruneOrphanedWorktrees / pruneOrphanedHubs take dryRun and only
    mutate state when false; both prefix log lines with "[dry-run]
    Would prune" or "Pruning" depending on mode
  - state.SaveState is gated on !dryRun

Also updates the only other caller (cmd/doctor.go --fix path) to
pass dryRun=false explicitly.

Tests:
  - TestRunPrune_DryRun: state.json on disk is unchanged after a
    dry-run that reports 1 orphan
  - TestRunPrune_Apply: in-memory state is mutated when dryRun=false
  - Existing pruneOrphanedWorktrees/Hubs tests updated for new sig
@jadb jadb merged commit ee98684 into main Apr 28, 2026
4 of 5 checks passed
@jadb jadb deleted the fix/prune-dry-run branch April 28, 2026 01:54
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