rb_one() {
local b=$1
+ shift
- echo "### ${b}"
- git checkout -q "${b}" || exit
- if ! git rebase ; then
- git rebase --abort
+ 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
+ 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
}
usage() {
cat <<EOF
-Usage: rb-all
+Usage: rb-all [-q]
EOF
exit 1
}
main() {
- if [[ $# -ne 0 ]] ; then
- usage
+ 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 rev-parse --git-path rebase-merge) || \
+ -e $(git rev-parse --git-path rebase-apply) ]] ; 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}"
+ # If it's a branch in another worktree, ignore it.
+ if [[ $(git branch --list "${b}") != "+"* ]] ; then
+ rb_one "${b}" "${opts[@]}"
+ fi
done
git checkout -q "${orig}"