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:
parent
cd95974e48
commit
25353f548d
1 changed files with 11 additions and 2 deletions
|
|
@ -113,8 +113,17 @@ git-pr-cleanup() {
|
||||||
git -C "$bare_repo" worktree remove "$pr_path"
|
git -C "$bare_repo" worktree remove "$pr_path"
|
||||||
|
|
||||||
echo "Deleting branch: $branch_name"
|
echo "Deleting branch: $branch_name"
|
||||||
git -C "$bare_repo" branch -d "$branch_name" 2>/dev/null \
|
if ! git -C "$bare_repo" branch -d "$branch_name" 2>/dev/null; then
|
||||||
|| git -C "$bare_repo" branch -D "$branch_name"
|
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."
|
echo "Done."
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue