]> git.wh0rd.org Git - home.git/commitdiff
git-rb-all: add more features
authorMike Frysinger <vapier@gentoo.org>
Fri, 27 Sep 2019 17:50:31 +0000 (13:50 -0400)
committerMike Frysinger <vapier@gentoo.org>
Fri, 27 Sep 2019 17:50:31 +0000 (13:50 -0400)
.bin/git-rb-all

index ef3f54c773596eb17cf39607052b1392f2f947e5..122d85d2bffc2190445a9b0d21857632e99f1a46 100755 (executable)
@@ -3,14 +3,16 @@
 
 rb_one() {
        local b=$1
+       shift
 
-       printf "### ${b}"
+       printf "${BRACKET}### ${GREEN}${b}${NORMAL}"
        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 "${opts[@]}" | sed -e '/^Fast-forwarded/d' -e "s:^:${BAD}:" -e "s:$:${NORMAL}:"
+               if [[ ${PIPESTATUS[0]} -ne 0 ]] ; then
                        git rebase --abort
                fi
        fi
@@ -18,25 +20,38 @@ rb_one() {
 
 usage() {
        cat <<EOF
-Usage: rb-all
+Usage: rb-all [-q]
 EOF
        exit 1
 }
 
 main() {
-       if [[ $# -ne 0 ]] ; then
-               usage
-       fi
+       local opts=(-q)
+       while [[ $# -ne 0 ]] ; do
+               case $1 in
+               -q|-v|-n|--no-stat|--stat) opts+=( "$1" );;
+               *) usage ;;
+               esac
+               shift
+       done
+
+       [[ -z ${GOOD} ]] && eval "$(bash-colors --env)"
 
        # Switch to the top dir in case the working dir doesn't exist in every branch.
        cd "$(git rev-parse --show-toplevel)" || return
 
+       # Skip if rebase is in progress.
+       if [[ -e .git/rebase-merge/interactive ]] ; then
+               printf "${BAD}skipping due to active rebase${NORMAL}\n"
+               exit 1
+       fi
+
        local orig b branches
        orig=$(git rev-parse --abbrev-ref HEAD) || return
 
-       branches=( $(git ls-remote --heads . | sed 's:.*refs/heads/::') )
+       branches=( $(git for-each-ref --format='%(refname:short)' 'refs/heads/*') )
        for b in "${branches[@]}" ; do
-               rb_one "${b}"
+               rb_one "${b}" "${opts[@]}"
        done
 
        git checkout -q "${orig}"