Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
71 lines
2.0 KiB
Bash
Executable File
71 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# usage: clean-branches
|
|
# Deletes any local branches which are ancestors of origin/main,
|
|
# and also any branches in origin which are ancestors of
|
|
# origin/main 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 with names like review-*
|
|
|
|
review=0
|
|
if [ $# -ne 0 ] && [ "$1" == "--reviews" ]; then
|
|
review=1
|
|
fi
|
|
push_args=()
|
|
|
|
function is_merged() {
|
|
! git rev-list -n 1 origin/main.."$1" | grep -q .
|
|
}
|
|
|
|
function clean_ref() {
|
|
ref="$1"
|
|
case "$ref" in
|
|
*/main | */HEAD)
|
|
return
|
|
;;
|
|
|
|
refs/heads/review-*)
|
|
if [ $review -ne 0 ]; then
|
|
echo -n "Deleting local branch ${ref#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 ${ref#refs/heads/}"
|
|
echo " (was $(git rev-parse --short "$ref"))"
|
|
git update-ref -d "$ref"
|
|
fi
|
|
;;
|
|
|
|
refs/remotes/origin/$USER-*)
|
|
if is_merged "$ref"; then
|
|
remote_name="${ref#refs/remotes/origin/}"
|
|
echo -n "Deleting remote branch $remote_name"
|
|
echo " (was $(git rev-parse --short "$ref"))"
|
|
# NB: this won't handle spaces in ref names
|
|
push_args=("${push_args[@]}" ":$remote_name")
|
|
fi
|
|
;;
|
|
esac
|
|
}
|
|
|
|
if [ "$(git symbolic-ref HEAD)" != 'refs/heads/main' ]; then
|
|
echo "Check out main before you run this script." >&2
|
|
exit 1
|
|
fi
|
|
|
|
git fetch --prune origin
|
|
|
|
eval "$(git for-each-ref --shell --format='clean_ref %(refname);')"
|
|
|
|
if [ "${#push_args[@]}" -ne 0 ]; then
|
|
git push origin "${push_args[@]}"
|
|
fi
|