Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --proceed flag to git-delete-squashed-branches (#1134) #1135

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading