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

Commit

Permalink
Add the `rebase' subcommand to quickly rebase a particular change.
Browse files Browse the repository at this point in the history
Gerrit sometimes gets stuck and is unable to cherry-pick a commit,
even if git can do it, and forces you to do it yourself. This command
just automates that process for you, stopping if you encounter any
conflicts.
  • Loading branch information
Brian Donovan committed Jul 16, 2009
1 parent bf075b6 commit c2b6f4d
Showing 1 changed file with 55 additions and 8 deletions.
63 changes: 55 additions & 8 deletions bin/git-review
Expand Up @@ -58,6 +58,17 @@ is_integer() {
return $?
}

is_review_branch() {
branch=$1
if [ "${branch:0:1}" = "r" ]; then
change=${branch:1}
if is_integer $change; then
return `true`
fi
fi
return `false`
}

printShortUsage() {
echo "Usage: $this [<options>] push [<change number>]"
echo " or: $this [<options>] <change number>"
Expand Down Expand Up @@ -94,19 +105,22 @@ printUsage() {
echo " diff <change number> [<patch number> <patch number>]"
echo " Displays a diff of the last two patches applies to the given changeset, or between"
echo " the given patches of that changeset."
echo
echo " rebase [<change number>]"
echo " Rebases the latest patch for a given change number (or the current change branch)"
echo " against master, then submits it as a new patch to that change. This helps deal with"
echo " Gerrit's \"Your change could not be merged due to a path conflict\" error message."
}


pushReview() {
change=$1
if [ -z "$change" ]; then
# try to read the change number from the branch name
if [ "${CURRENT:0:1}" = "r" ]; then
if is_review_branch $CURRENT; then
change=${CURRENT:1}
if is_integer $change; then
if [ $run = true ]; then
good "Using change number $change from branch name"
else
change=""
fi
fi
fi
Expand All @@ -115,10 +129,12 @@ pushReview() {
CHANGESETS=$($GIT rev-list origin/master..HEAD | wc -l)
CHANGESETS=${CHANGESETS//[[:space:]]}

if [ "$CHANGESETS" = "0" ]; then
die "You have no changes to review. Are you on the right branch?"
elif [ "$CHANGESETS" != "1" ]; then
die "You have $CHANGESETS changes, but you should only push one at a time. Did you forget to squash your commits?"
if [ "$run" = true ]; then
if [ "$CHANGESETS" = "0" ]; then
die "You have no changes to review. Are you on the right branch?"
elif [ "$CHANGESETS" != "1" ]; then
die "You have $CHANGESETS changes, but you should only push one at a time. Did you forget to squash your commits?"
fi
fi

if [ "$change" != "" ]; then
Expand Down Expand Up @@ -211,6 +227,33 @@ diffPatches() {
$GIT diff --src-prefix=$patchref1: --dst-prefix=$patchref2: $patchref1 $patchref2
}

rebaseReview() {
change=$1
if [ -z "$change" ]; then
if is_review_branch $CURRENT; then
change=${CURRENT:1}
if [ $run = true ]; then
good "Using change number $change from branch name"
fi
else
die "Please provide a change number to rebase (see help for more info)"
fi
fi

if ! is_review_branch $CURRENT; then
# if not already on a review branch, fetch and check it out
startReview $change
fi

# try to push this patch along
pushReview $change

# reset if we weren't already on a review branch
if is_review_branch $CURRENT; then
resetReview
fi
}

if ! no_changes; then
die "You have local changes. Please do something with them before using $this"
fi
Expand Down Expand Up @@ -257,6 +300,10 @@ while true; do
diffPatches $1 $2 $3
exit
;;
rebase)
rebaseReview $1
exit
;;
*)
if is_integer $arg; then
startReview $arg
Expand Down

0 comments on commit c2b6f4d

Please sign in to comment.