From 52897f73b9b4b3834079afcf14a1a1a37d42f3a9 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Mon, 19 Feb 2024 18:47:36 -0800 Subject: [PATCH] Add --proceed flag to git-delete-squashed-branches (#1134) (#1135) Co-authored-by: Norbert Kiesel --- bin/git-delete-squashed-branches | 12 +++++++++++- man/git-delete-squashed-branches.1 | 10 ++++++++-- man/git-delete-squashed-branches.html | 10 +++++++--- man/git-delete-squashed-branches.md | 6 +++++- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/bin/git-delete-squashed-branches b/bin/git-delete-squashed-branches index 6245b6b30..6d1b6bbe9 100755 --- a/bin/git-delete-squashed-branches +++ b/bin/git-delete-squashed-branches @@ -2,6 +2,12 @@ set -euo pipefail +proceed=false +if [[ $# -gt 0 && ("$1" == "--proceed" || "$1" == "-p") ]]; then + proceed=true + shift +fi + if [[ $# -eq 0 ]]; then targetBranch=$(git rev-parse --abbrev-ref HEAD) else @@ -13,6 +19,10 @@ git for-each-ref refs/heads/ "--format=%(refname:short)" | while read -r branch; 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" + if [[ $proceed == true ]]; then + git branch -D "$branch" || true + else + git branch -D "$branch" + fi fi done diff --git a/man/git-delete-squashed-branches.1 b/man/git-delete-squashed-branches.1 index 45831b19a..f2b29bbb2 100644 --- a/man/git-delete-squashed-branches.1 +++ b/man/git-delete-squashed-branches.1 @@ -1,18 +1,24 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "GIT\-DELETE\-SQUASHED\-BRANCHES" "1" "May 2021" "" "Git Extras" +.TH "GIT\-DELETE\-SQUASHED\-BRANCHES" "1" "February 2024" "" "Git Extras" . .SH "NAME" \fBgit\-delete\-squashed\-branches\fR \- Delete branches that were squashed . .SH "SYNOPSIS" -\fBgit\-delete\-squashed\-branches\fR [] +\fBgit\-delete\-squashed\-branches\fR [\-\-proceed, \-p] [] . .SH "DESCRIPTION" Deletes all git branches that have been "squash\-merged" into \fBbranch\-name\fR\. . .SH "OPTIONS" +\-\-proceed, \-p +. +.P +Proceed with the next branch even if the current branch cannot be deleted (e\.g\. because it is checked out in a worktree) +. +.P . .P diff --git a/man/git-delete-squashed-branches.html b/man/git-delete-squashed-branches.html index a1ab81b69..e176da1d4 100644 --- a/man/git-delete-squashed-branches.html +++ b/man/git-delete-squashed-branches.html @@ -76,7 +76,7 @@

NAME

SYNOPSIS

-

git-delete-squashed-branches [<branch-name>]

+

git-delete-squashed-branches [--proceed, -p] [<branch-name>]

DESCRIPTION

@@ -84,6 +84,10 @@

DESCRIPTION

OPTIONS

+

--proceed, -p

+ +

Proceed with the next branch even if the current branch cannot be deleted (e.g. because it is checked out in a worktree)

+

<branch-name>

The target branch were the "squashed-merged" branches were committed to. If no value is given, then the current checked out branch will be used.

@@ -102,7 +106,7 @@

EXAMPLES

AUTHOR

-

Written by Teddy Katz <teddy.katz@gmail.com> and Vladimir Jimenez <me@allejo.io>

+

Written by Teddy Katz <teddy.katz@gmail.com> and Vladimir Jimenez <me@allejo.io>

REPORTING BUGS

@@ -115,7 +119,7 @@

SEE ALSO

  1. -
  2. May 2021
  3. +
  4. February 2024
  5. git-delete-squashed-branches(1)
diff --git a/man/git-delete-squashed-branches.md b/man/git-delete-squashed-branches.md index e46cd2831..de986e9fe 100644 --- a/man/git-delete-squashed-branches.md +++ b/man/git-delete-squashed-branches.md @@ -3,7 +3,7 @@ git-delete-squashed-branches(1) -- Delete branches that were squashed ## SYNOPSIS -`git-delete-squashed-branches` [<branch-name>] +`git-delete-squashed-branches` [--proceed, -p] [<branch-name>] ## DESCRIPTION @@ -11,6 +11,10 @@ Deletes all git branches that have been "squash-merged" into `branch-name`. ## OPTIONS + --proceed, -p + + Proceed with the next branch even if the current branch cannot be deleted (e.g. because it is checked out in a worktree) + <branch-name> The target branch were the "squashed-merged" branches were committed to. If no value is given, then the current checked out branch will be used.