Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
scripts: Fix delete-remote-branches script
cloudhead committed 2 years ago
commit aea7fb0e423da08aadcc4efee40040d314f8bfe4
parent 2ea9a911afd97c6e78212ebca10fda0b04fe9a46
1 file changed +18 -2
modified 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