]> git.wh0rd.org - home.git/blobdiff - .bin/git-rb-all
git-rb-all: handle missing working dirs
[home.git] / .bin / git-rb-all
index 839d1432f68b4674fb757985464bfc4132b4a0d4..ef3f54c773596eb17cf39607052b1392f2f947e5 100755 (executable)
@@ -4,10 +4,15 @@
 rb_one() {
        local b=$1
 
-       echo "### ${b}"
-       git checkout -q "${b}" || exit
-       if ! git rebase ; then
-               git rebase --abort
+       printf "### ${b}"
+       if ! git config --local "branch.${b}.merge" >/dev/null; then
+               echo " -> skipping due to missing merge branch"
+       else
+               echo
+               git checkout -q "${b}" || return
+               if ! git rebase ; then
+                       git rebase --abort
+               fi
        fi
 }
 
@@ -23,10 +28,13 @@ main() {
                usage
        fi
 
+       # Switch to the top dir in case the working dir doesn't exist in every branch.
+       cd "$(git rev-parse --show-toplevel)" || return
+
        local orig b branches
        orig=$(git rev-parse --abbrev-ref HEAD) || return
 
-       branches=( $(git ls-remote . 'heads/*' | sed 's:.*refs/heads/::') )
+       branches=( $(git ls-remote --heads . | sed 's:.*refs/heads/::') )
        for b in "${branches[@]}" ; do
                rb_one "${b}"
        done