scripts: Fix delete-remote-branches script

We were deleting patch branches, oops.
This commit is contained in:
cloudhead 2023-08-04 12:19:27 +02:00
parent 2ea9a911af
commit aea7fb0e42
No known key found for this signature in database
1 changed files with 18 additions and 2 deletions

View File

@ -2,6 +2,18 @@
# Delete all remote branches that don't have a local copy.
remote="rad"
remote_branches="$(git for-each-ref --format='%(refname:short)' refs/remotes/rad)"
# Check that a branch isn't a remote tracking branch.
is_remote_branch() {
for remote_branch in $remote_branches; do
# Remove the "rad/" prefix
if [ "$1" = "${remote_branch#rad/}" ]; then
return 0
fi
done
return 1
}
# Iterate over all remote branches.
for branch in $(git branch -r --format "%(refname:short)"); do
@ -14,8 +26,12 @@ for branch in $(git branch -r --format "%(refname:short)"); do
# Check if the branch doesn't exist locally.
if ! git rev-parse --quiet --verify "$branch" >/dev/null; then
git push -o "no-sync" $remote --delete "$branch"
echo "Deleted '$branch'"
if ! is_remote_branch "$branch"; then
git push -o "no-sync" $remote --delete "$branch"
echo "Deleted '$branch'"
else
echo "Skipping remote branch '$branch'"
fi
fi
done