From 25353f548dca5e8aa0d8470b2345c22b3028bab0 Mon Sep 17 00:00:00 2001 From: Padreug Date: Sat, 20 Jun 2026 09:52:17 +0200 Subject: [PATCH] fix(dev-env): confirm before force-deleting an unmerged PR branch git-pr-cleanup (prc) tried `branch -d` then fell back to `branch -D` unconditionally, silently destroying an unmerged branch when prc was run before the PR merged or against the wrong branch. Keep the safe `-d` for the normal post-merge path, but prompt before forcing so unmerged commits aren't lost without consent; decline keeps the branch. --- modules/dev-env/scripts/pr-helpers.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/dev-env/scripts/pr-helpers.sh b/modules/dev-env/scripts/pr-helpers.sh index 46763d5..765cb03 100644 --- a/modules/dev-env/scripts/pr-helpers.sh +++ b/modules/dev-env/scripts/pr-helpers.sh @@ -113,8 +113,17 @@ git-pr-cleanup() { git -C "$bare_repo" worktree remove "$pr_path" echo "Deleting branch: $branch_name" - git -C "$bare_repo" branch -d "$branch_name" 2>/dev/null \ - || git -C "$bare_repo" branch -D "$branch_name" + if ! git -C "$bare_repo" branch -d "$branch_name" 2>/dev/null; then + echo " Branch '$branch_name' is not fully merged." + read -r -p " Force-delete it (unmerged commits will be lost)? [y/N] " -n 1 REPLY + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + git -C "$bare_repo" branch -D "$branch_name" + else + echo " Kept branch '$branch_name' (worktree already removed)." + return 1 + fi + fi echo "Done." }