summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authortobi1805 <66414944+tobi1805@users.noreply.github.com>2023-10-09 18:07:51 +0200
committerGitHub <noreply@github.com>2023-10-09 18:07:51 +0200
commit24b2600558f999dd53f0d354ad61fc07cf7d6e2b (patch)
treea6f790168a70a28621df44089df9d24694786537 /plugins
parent29b99c2c7b16f22f3ca2bdf9478ba700ac6c48b5 (diff)
downloadzsh-24b2600558f999dd53f0d354ad61fc07cf7d6e2b.tar.gz
zsh-24b2600558f999dd53f0d354ad61fc07cf7d6e2b.tar.bz2
zsh-24b2600558f999dd53f0d354ad61fc07cf7d6e2b.zip
feat(git): delete squash-merged branches in `gbda` (#11948)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/git/README.md2
-rw-r--r--plugins/git/git.plugin.zsh17
2 files changed, 17 insertions, 2 deletions
diff --git a/plugins/git/README.md b/plugins/git/README.md
index 9c16cb6e7..33c10ffd0 100644
--- a/plugins/git/README.md
+++ b/plugins/git/README.md
@@ -41,7 +41,6 @@ plugins=(... git)
| `gba` | `git branch --all` |
| `gbd` | `git branch --delete` |
| `gbD` | `git branch --delete --force` |
-| `gbda` | `git branch --no-color --merged \| command grep -vE "^([+*]\|\s*($(git_main_branch)\|$(git_develop_branch))\s*$)" \| command xargs git branch --delete 2>/dev/null` |
| `gbgd` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -d` |
| `gbgD` | `LANG=C git branch --no-color -vv \| grep ": gone\]" \| awk '"'"'{print $1}'"'"' \| xargs git branch -D` |
| `gbm` | `git branch --move` |
@@ -251,6 +250,7 @@ receive further support.
| `git_develop_branch` | Returns the name of the “development” branch: `dev`, `devel`, `development` if they exist, `develop` otherwise. |
| `git_main_branch` | Returns the name of the main branch: `main` if it exists, `master` otherwise. |
| `grename <old> <new>` | Renames branch `<old>` to `<new>`, including on the origin remote. |
+| `gbda` | Deletes all merged and squash-merged branches |
### Work in Progress (WIP)
diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh
index cb848b407..ceb2011f9 100644
--- a/plugins/git/git.plugin.zsh
+++ b/plugins/git/git.plugin.zsh
@@ -122,7 +122,22 @@ alias gb='git branch'
alias gba='git branch --all'
alias gbd='git branch --delete'
alias gbD='git branch --delete --force'
-alias gbda='git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null'
+
+# Copied and modified from James Roeder (jmaroeder) under MIT License
+# https://github.com/jmaroeder/plugin-git/blob/216723ef4f9e8dde399661c39c80bdf73f4076c4/functions/gbda.fish
+function gbda() {
+ git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null
+
+ local default_branch=$(git_main_branch)
+ git for-each-ref refs/heads/ "--format=%(refname:short)" | \
+ while read branch; do
+ local merge_base=$(git merge-base $default_branch $branch)
+ if [[ '-*' == $(git cherry $default_branch $(git commit-tree $(git rev-parse $branch\^{tree}) -p $merge_base -m _)) ]]; then
+ git branch -D $branch
+ fi
+ done
+}
+
alias gbgd='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -d'
alias gbgD='LANG=C git branch --no-color -vv | grep ": gone\]" | awk '"'"'{print $1}'"'"' | xargs git branch -D'
alias gbm='git branch --move'