tools: Update clean-branches to clean review branches.

This commit is contained in:
Rohitt Vashishtha 2017-06-01 23:57:44 +05:30 committed by Tim Abbott
parent 443e31e348
commit a4b76e78ac
1 changed files with 18 additions and 0 deletions

View File

@ -1,10 +1,20 @@
#!/usr/bin/env bash
set -e
# usage: clean-branches
# Deletes any local branches which are ancestors of origin/master,
# and also any branches in origin which are ancestors of
# origin/master and are named like $USER-*.
# usage: clean-branches --reviews
# Deletes all the above mentioned branches as well as branches
# created by the scripts like `fetch-rebase-pull-request`. Be careful
# as this would also remove other branches woth names like review-*
review=0
if [ $# -ne 0 ] && [ "$1" == "--reviews" ]; then
review=1
fi
push_args=()
function is_merged {
@ -18,6 +28,14 @@ function clean_ref {
return
;;
refs/heads/review-*)
if [ $review -ne 0 ]; then
echo -n "Deleting local branch $(echo "$ref" | sed 's!^refs/heads/!!')"
echo " (was $(git rev-parse --short "$ref"))"
git update-ref -d "$ref"
fi
;;
refs/heads/*)
if is_merged "$ref"; then
echo -n "Deleting local branch $(echo "$ref" | sed 's!^refs/heads/!!')"