Skip to content

Commit d38a025

Browse files
committed
Fix cleanup-branches script
1 parent 03b4af4 commit d38a025

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

bin/common/.local/bin/git-cleanup-branches

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ set -eu -o pipefail
66

77
git fetch --prune &>/dev/null
88

9-
for branch in $(git branch -vv | grep -o -E '^[\* ]+\S+' | tr -d '* '); do
10-
upstream=$(git rev-parse --abbrev-ref --symbolic-full-name "${branch}@{upstream}" 2>/dev/null)
11-
if [ -n "${upstream}" ]; then
12-
if ! git show-ref --quiet "refs/remotes/${upstream}"; then
9+
current_branch=$(git symbolic-ref --quiet --short HEAD || true)
10+
11+
git branch --format='%(refname:short)%09%(upstream:track)' |
12+
while IFS=$'\t' read -r branch upstream_track; do
13+
if [ "${upstream_track}" = "[gone]" ]; then
14+
if [ "${branch}" = "${current_branch}" ]; then
15+
echo "Skipping current branch '${branch}'"
16+
continue
17+
fi
18+
1319
echo "Deleting branch '${branch}'"
1420
git branch -D "${branch}"
1521
fi
16-
fi
17-
done
22+
done

0 commit comments

Comments
 (0)