Skip to content
This repository has been archived by the owner on May 8, 2018. It is now read-only.

Commit

Permalink
Allow hack <branch> to both switch to the branch and rebase it.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Donovan committed Apr 8, 2011
1 parent ab5784c commit 42c8ca8
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions bin/hack
Expand Up @@ -8,15 +8,19 @@ gitdir=$(git rev-parse --git-dir)
explain=false
verbose=true
run=true
branch=$CURRENT

printUsage() {
echo "usage: $0 [options]"
echo "usage: $0 [options] [BRANCH]"
echo
echo " -h --help Show this message"
echo " -v --verbose Show all commands before running them (default: on)"
echo " -q --quiet Don't display commands before running them (default: off)"
echo " -e --explain --dry-run Don't actually run commands (default: off)"
echo
echo " If BRANCH is given then that branch will be updated and switched to instead of the"
echo " current branch."
echo
}

for arg in "$@"; do
Expand All @@ -37,11 +41,14 @@ for arg in "$@"; do
printUsage
exit
;;
*)
-*)
echo "$0: unrecognized parameter '$arg'"
printUsage
exit 1
;;
*)
branch=$arg
;;
esac
done

Expand Down Expand Up @@ -105,13 +112,13 @@ else
trap 'check_stash' EXIT
fi

REMOTE=`$GIT config branch.$CURRENT.remote`
REMOTE=`$GIT config branch.$branch.remote`

if [ -z "$REMOTE" ]; then
REMOTE=origin
fi

TRACK=`$GIT config branch.$CURRENT.merge`
TRACK=`$GIT config branch.$branch.merge`

if [ -z "$TRACK" ]; then
TRACK=refs/heads/master
Expand Down Expand Up @@ -140,9 +147,9 @@ else
die "Could not rebase against $REMOTE/$TRACK_BRANCH. You may need to resolve conflicts."
fi

if [ "$CURRENT" != "$TRACK_BRANCH" ]; then
git checkout $CURRENT ||
die "Could not switch back to $CURRENT."
if [ "$branch" != "$TRACK_BRANCH" ]; then
git checkout $branch ||
die "Could not switch back to $branch."
git rebase $TRACK_BRANCH ||
die "Could not rebase against $TRACK_BRANCH. You may need to resolve conflicts."
fi
Expand Down

0 comments on commit 42c8ca8

Please sign in to comment.