Add a flag to "git delete-squashed-branches" to not abort on first error
I love this command, but I often have squashed branches which cannot be deleted because they are checked out locally in a different worktree. And because the script immediately aborts in this situation, it will not try to delete other squashed branches.
I created a local copy which simply replaces git branch -D "$branch" with git branch -D "$branch" || true, but I could file a PR which instead uses a flag for this if you are interested. or is there a reason to not do that?
something like the following (do not like the flag name):
--- /opt/homebrew/bin/git-delete-squashed-branches 2023-10-29 03:52:56
+++ /Users/norbert.kiesel/bin/git-delete-squashed-branches 2024-02-12 12:51:33
@@ -37,6 +37,17 @@
set -euo pipefail
+try-next() {
+ false
+}
+
+if [[ $# -gt 0 && "$1" == "--all" ]]; then
+ try-next() {
+ true
+ }
+ shift
+fi
+
if [[ $# -eq 0 ]]; then
targetBranch=$(git rev-parse --abbrev-ref HEAD)
else
@@ -48,6 +59,6 @@
mergeBase=$(git merge-base "$targetBranch" "$branch")
if [[ $(git cherry "$targetBranch" "$(git commit-tree "$(git rev-parse "$branch^{tree}")" -p "$mergeBase" -m _)") == "-"* ]]; then
- git branch -D "$branch"
+ git branch -D "$branch" || try-next
fi
done
PR is welcome! What name do you want to use for this new flag?
Done