From 20e8935225706efd0636d74cf37e882c7af71413 Mon Sep 17 00:00:00 2001 From: Shivakumar Date: Mon, 20 Jul 2026 02:21:16 +0530 Subject: [PATCH] fix(scripts): don't run git worktree prune under --dry-run cleanup-branches.sh's dry-run mode is documented as 'list what would be removed, change nothing', but the trailing git worktree prune call ran unconditionally regardless of the flag. On at least one Windows/Git-Bash setup, that prune misjudged every registered worktree as stale even though their directories were all present and unmodified, wiping .git/worktrees// bookkeeping for ~29 worktrees from a single --dry-run invocation. No branches, commits, or worktree files were lost (prune only removes admin state), but every affected worktree needs manual re-registration. git worktree remove already drops the admin entry for anything it actually removes, so prune only matters on a real (non-dry-run) pass. --- scripts/cleanup-branches.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/cleanup-branches.sh b/scripts/cleanup-branches.sh index 75a226b5..91c39fa6 100644 --- a/scripts/cleanup-branches.sh +++ b/scripts/cleanup-branches.sh @@ -111,7 +111,12 @@ for b in "${!candidates[@]}"; do fi done -git worktree prune +# `git worktree remove` above already drops the admin entry for anything it +# actually removes. `prune` is a real mutation (not a preview), and on at +# least one Windows/Git-Bash setup it has misjudged untouched, still-present +# worktrees as stale and wiped their registration — so it must never run +# under --dry-run, which promises to "change nothing". +((DRY_RUN)) || git worktree prune if ((DO_REMOTE)); then echo "== remote branches merged into origin/$DEFAULT_BRANCH =="