]> git.proxmox.com Git - debcargo-conf.git/blob - dev/sync-pending-branches.sh
ssh2 - new upstream release.
[debcargo-conf.git] / dev / sync-pending-branches.sh
1 #!/bin/bash
2 # Sync remote pending branches locally, and prune merged branches.
3 set -e
4
5 git_hash() {
6 git rev-parse -q --verify "$@" || true
7 }
8
9 git fetch origin --prune
10 PREVBRANCH="$(git rev-parse --abbrev-ref HEAD)"
11
12 # delete merged
13 git branch --merged | tr -d ' ' | grep ^pending- | xargs -trn1 git branch -d
14 merged=( $(git branch --list -r 'origin/pending-*' --format='%(refname:lstrip=3)' --merged) )
15 git push origin "${merged[@]/#/:}"
16
17 # sync local branches
18 git branch --list -r 'origin/pending-*' --format='%(refname:lstrip=3)' | while read b; do
19 if [ -z "$(git_hash "$b")" ]; then
20 git checkout "$b"
21 fi
22 done
23 git checkout "$PREVBRANCH"
24 git branch --list 'pending-*' --format='%(refname:lstrip=2)' | while read b; do
25 if [ "$(git_hash "$b")" != "$(git_hash "origin/$b")" ]; then
26 echo >&2 "WARNING: Local $b ($(git_hash "$b")) differs from remote $b ($(git_hash "origin/$b"))"
27 fi
28 done