1
0
Fork 0

git: Add dedicated branch-prune script

This commit is contained in:
Jeremy Kaplan 2020-09-05 17:02:01 -07:00
commit 53e056469c
2 changed files with 39 additions and 1 deletions

38
bin/git-branch-prune Executable file
View file

@ -0,0 +1,38 @@
#!/usr/bin/env bash
export USAGE='<remote>
'
# This is the recommended pattern from `man git-sh-setup`.
#
# shellcheck disable=SC1090
. "$(git --exec-path)/git-sh-setup"
set -euo pipefail
case "$#" in
0)
remote='origin'
;;
1)
remote="$1"
;;
*) usage ;;
esac
git remote prune "${remote}"
# This grep "fails" if there are no matches, so temporarily disable error
# checking.
set +e
pruned_branches=$(git branch -vv | grep ': gone]')
set -e
if [ -z "${pruned_branches}" ]; then
>&2 echo 'Nothing to do!'
exit 0
fi
vipe <<< "${pruned_branches}" | \
awk '{print $1}' | \
xargs git branch -D

View file

@ -23,7 +23,7 @@ default = simple
ap = add -p
b = branch
bn = symbolic-ref --short HEAD
bp = !git remote prune origin && git branch -vv | grep ': gone]' | vipe | awk '{print $1}' | xargs git branch -D
bp = branch-prune
bv = branch -vv
c = commit
chk = commit -a -n -m 'CHECKPOINT'