git: Add dedicated branch-prune script
This commit is contained in:
parent
5e4b71d968
commit
53e056469c
2 changed files with 39 additions and 1 deletions
38
bin/git-branch-prune
Executable file
38
bin/git-branch-prune
Executable 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
|
||||||
|
|
@ -23,7 +23,7 @@ default = simple
|
||||||
ap = add -p
|
ap = add -p
|
||||||
b = branch
|
b = branch
|
||||||
bn = symbolic-ref --short HEAD
|
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
|
bv = branch -vv
|
||||||
c = commit
|
c = commit
|
||||||
chk = commit -a -n -m 'CHECKPOINT'
|
chk = commit -a -n -m 'CHECKPOINT'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue