Skip to content

Commit

Permalink
Add --proceed flag to git-delete-squashed-branches (tj#1134) (tj#1135)
Browse files Browse the repository at this point in the history
Co-authored-by: Norbert Kiesel <[email protected]>
  • Loading branch information
hyperupcall and nkiesel authored Feb 20, 2024
1 parent 5f19424 commit 52897f7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
12 changes: 11 additions & 1 deletion bin/git-delete-squashed-branches
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
10 changes: 8 additions & 2 deletions man/git-delete-squashed-branches.1
Original file line number Diff line number Diff line change
@@ -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 [<branch\-name>]
\fBgit\-delete\-squashed\-branches\fR [\-\-proceed, \-p] [<branch\-name>]
.
.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
<branch\-name>
.
.P
Expand Down
10 changes: 7 additions & 3 deletions man/git-delete-squashed-branches.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/git-delete-squashed-branches.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ git-delete-squashed-branches(1) -- Delete branches that were squashed

## SYNOPSIS

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

## DESCRIPTION

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)

&lt;branch-name&gt;

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.
Expand Down

0 comments on commit 52897f7

Please sign in to comment.