This is a continuation of an earlier thread:
http://lists.gnu.org/archive/html/lilypond-devel/2010-01/msg00534.html

I suppose I have a different git style than Carl and Trevor;
I don't really see the value in keeping outdated branches.
Or put another way, I don't see the harm in keeping all my
branches current.

Anyway, in case anyone might benefit from this, here's the
script I'm currently using.  With this script, I can select
exactly the branches I want to rebase, or just use "--all"
(which is what I usually do).

As with the previous version, rebases abort at the slightest
sign of a problem, and the output clearly shows which
branches succeeded/failed.

Here's the header:

# rebase-multiple.sh --
#   * rebase local master to remote master, and
#   * rebase local git branches to updated local master
#
# Usage:
#   rebase-multiple.sh <branches>
#   rebase-multiple.sh --all

See the attachment for the full script.
- Mark


      
#!/bin/bash

# rebase-multiple.sh --
#   * rebase local master to remote master, and
#   * rebase local git branches to updated local master
#
# Usage:
#   rebase-multiple.sh <branches>
#   rebase-multiple.sh --all


# exit without a branch list or --all
if [[ ( $# -eq 0 ) || ( $1 == "--all" && $# -gt 1 ) ]]; then
  echo -e "Usage:" \
          "\n  `basename $0` <branches>" \
          "\n  `basename $0` --all" >&2
  exit 1
fi


# remember where we started
starting_branch=`git branch | sed -n 's/^\* //p'`


return_from_branch () {
  if [[ $1 != $starting_branch ]]; then
    echo
    git checkout $starting_branch
  fi
}

rebase_abort_verbose () {
  echo "Aborting rebase on branch '$1'..." >&2
  git rebase --abort
  git status
}


# exit now if we can't checkout master
if [[ $starting_branch != master ]]; then
  git checkout master || exit 1
fi


# update master
if ! git pull --rebase; then
  rebase_abort_verbose master
  return_from_branch master
  echo -e "\nERROR: There was a problem with 'master'." \
          "\n       No branches were rebased." >&2
  exit 1
fi


# parse arguments
if [[ $# -eq 1 && $1 == "--all" ]]; then
  # sed removes current branch `* master' from rebase_list
  # `--reverse' leaves local branches in order in gitk.
  rebase_list=`git branch | sed '/^\*/d' | sort --reverse`
else
  rebase_list="$@"
fi


# rebase local branches to master where possible
successful_branches=""
failed_branches=""
for branch in $rebase_list; do
  echo
  if git rebase master $branch; then
    successful_branches="$successful_branches\n$branch"
  else
    failed_branches="$failed_branches\n$branch"
    rebase_abort_verbose $branch
  fi
done


# return to starting branch
return_from_branch $branch


# report success/failure
if [[ $successful_branches ]]; then
  successful_branches=`echo -e \
    "$successful_branches\nmaster" | sort`
  echo -e "\nThe following branches are up to date:"
  for branch in $successful_branches; do
    git branch --no-color | sed -n "/^[* ] $branch$/p"
  done
fi

if [[ $failed_branches ]]; then
  failed_branches=`echo -e "$failed_branches" | sort`
  echo -e "\nThe following branches failed to rebase:"
  for branch in $failed_branches; do
    git branch --no-color | sed -n "/^[* ] $branch$/p"
  done
  exit 1
fi


exit
_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to