Skip to content

Commit 52897f7

Browse files
hyperupcallnkiesel
andauthored
Add --proceed flag to git-delete-squashed-branches (#1134) (#1135)
Co-authored-by: Norbert Kiesel <[email protected]>
1 parent 5f19424 commit 52897f7

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

bin/git-delete-squashed-branches

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
set -euo pipefail
44

5+
proceed=false
6+
if [[ $# -gt 0 && ("$1" == "--proceed" || "$1" == "-p") ]]; then
7+
proceed=true
8+
shift
9+
fi
10+
511
if [[ $# -eq 0 ]]; then
612
targetBranch=$(git rev-parse --abbrev-ref HEAD)
713
else
@@ -13,6 +19,10 @@ git for-each-ref refs/heads/ "--format=%(refname:short)" | while read -r branch;
1319
mergeBase=$(git merge-base "$targetBranch" "$branch")
1420

1521
if [[ $(git cherry "$targetBranch" "$(git commit-tree "$(git rev-parse "$branch^{tree}")" -p "$mergeBase" -m _)") == "-"* ]]; then
16-
git branch -D "$branch"
22+
if [[ $proceed == true ]]; then
23+
git branch -D "$branch" || true
24+
else
25+
git branch -D "$branch"
26+
fi
1727
fi
1828
done

man/git-delete-squashed-branches.1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "GIT\-DELETE\-SQUASHED\-BRANCHES" "1" "May 2021" "" "Git Extras"
4+
.TH "GIT\-DELETE\-SQUASHED\-BRANCHES" "1" "February 2024" "" "Git Extras"
55
.
66
.SH "NAME"
77
\fBgit\-delete\-squashed\-branches\fR \- Delete branches that were squashed
88
.
99
.SH "SYNOPSIS"
10-
\fBgit\-delete\-squashed\-branches\fR [<branch\-name>]
10+
\fBgit\-delete\-squashed\-branches\fR [\-\-proceed, \-p] [<branch\-name>]
1111
.
1212
.SH "DESCRIPTION"
1313
Deletes all git branches that have been "squash\-merged" into \fBbranch\-name\fR\.
1414
.
1515
.SH "OPTIONS"
16+
\-\-proceed, \-p
17+
.
18+
.P
19+
Proceed with the next branch even if the current branch cannot be deleted (e\.g\. because it is checked out in a worktree)
20+
.
21+
.P
1622
<branch\-name>
1723
.
1824
.P

man/git-delete-squashed-branches.html

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/git-delete-squashed-branches.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ git-delete-squashed-branches(1) -- Delete branches that were squashed
33

44
## SYNOPSIS
55

6-
`git-delete-squashed-branches` [&lt;branch-name&gt;]
6+
`git-delete-squashed-branches` [--proceed, -p] [&lt;branch-name&gt;]
77

88
## DESCRIPTION
99

1010
Deletes all git branches that have been "squash-merged" into `branch-name`.
1111

1212
## OPTIONS
1313

14+
--proceed, -p
15+
16+
Proceed with the next branch even if the current branch cannot be deleted (e.g. because it is checked out in a worktree)
17+
1418
&lt;branch-name&gt;
1519

1620
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.

0 commit comments

Comments
 (0)