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.
This commit is contained in:
Padreug 2026-06-20 09:52:17 +02:00
commit 25353f548d

View file

@ -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."
}