diff --git a/dev/sync-pending-branches.sh b/dev/sync-pending-branches.sh index 7537f6c..6358853 100755 --- a/dev/sync-pending-branches.sh +++ b/dev/sync-pending-branches.sh @@ -2,8 +2,21 @@ # Sync remote pending branches locally, and prune merged branches. set -e +git_hash() { + git rev-parse -q --verify "$@" || true +} + git fetch origin --prune PREVBRANCH="$(git rev-parse --abbrev-ref HEAD)" git branch --merged | tr -d ' ' | grep ^pending- | xargs -trn1 git branch -d -git branch --list -r 'origin/pending-*' --format='%(refname:lstrip=3)' | xargs -trn1 git checkout +git branch --list -r 'origin/pending-*' --format='%(refname:lstrip=3)' | while read b; do + if [ -z "$(git_hash "$b")" ]; then + git checkout "$b" + fi +done git checkout "$PREVBRANCH" +git branch --list 'pending-*' --format='%(refname:lstrip=2)' | while read b; do + if [ "$(git_hash "$b")" != "$(git_hash "origin/$b")" ]; then + echo >&2 "WARNING: Local $b ($(git_hash "$b")) differs from remote $b ($(git_hash "origin/$b"))" + fi +done