diff --git a/tools/clean-branches b/tools/clean-branches index 54b2cd76a3..915491bf46 100755 --- a/tools/clean-branches +++ b/tools/clean-branches @@ -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/!!')"