From aea7fb0e423da08aadcc4efee40040d314f8bfe4 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Fri, 4 Aug 2023 12:19:27 +0200 Subject: [PATCH] scripts: Fix delete-remote-branches script We were deleting patch branches, oops. --- scripts/delete-remote-branches.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/delete-remote-branches.sh b/scripts/delete-remote-branches.sh index 94775b1f..d2d9e75e 100755 --- a/scripts/delete-remote-branches.sh +++ b/scripts/delete-remote-branches.sh @@ -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