Merge branch 'wc/rebase-insn'
[gitweb.git] / git-rebase--interactive.sh
index 0dd77b4005b9d80bfe6c606954d7666df77abc57..beeefec0e473efc8af67c702c88b655131eea026 100755 (executable)
@@ -13,6 +13,7 @@
 USAGE='(--continue | --abort | --skip | [--preserve-merges] [--verbose]
        [--onto <branch>] <upstream> [<branch>])'
 
+OPTIONS_SPEC=
 . git-sh-setup
 require_work_tree
 
@@ -29,6 +30,11 @@ test -d "$REWRITTEN" && PRESERVE_MERGES=t
 test -f "$DOTEST"/strategy && STRATEGY="$(cat "$DOTEST"/strategy)"
 test -f "$DOTEST"/verbose && VERBOSE=t
 
+GIT_CHERRY_PICK_HELP="  After resolving the conflicts,
+mark the corrected paths with 'git add <paths>', and
+run 'git rebase --continue'"
+export GIT_CHERRY_PICK_HELP
+
 warn () {
        echo "$*" >&2
 }
@@ -52,7 +58,7 @@ require_clean_work_tree () {
        git rev-parse --verify HEAD > /dev/null &&
        git update-index --refresh &&
        git diff-files --quiet &&
-       git diff-index --cached --quiet HEAD ||
+       git diff-index --cached --quiet HEAD -- ||
        die "Working tree is dirty"
 }
 
@@ -116,7 +122,7 @@ pick_one () {
                sha1=$(git rev-parse --short $sha1)
                output warn Fast forward to $sha1
        else
-               output git cherry-pick $STRATEGY "$@"
+               output git cherry-pick "$@"
        fi
 }
 
@@ -172,6 +178,8 @@ pick_one_preserving_merges () {
                        author_script=$(get_author_ident_from_commit $sha1)
                        eval "$author_script"
                        msg="$(git cat-file commit $sha1 | sed -e '1,/^$/d')"
+                       # No point in merging the first parent, that's HEAD
+                       new_parents=${new_parents# $first_parent}
                        # NEEDSWORK: give rerere a chance
                        if ! GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME" \
                                GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" \
@@ -184,7 +192,7 @@ pick_one_preserving_merges () {
                        fi
                        ;;
                *)
-                       output git cherry-pick $STRATEGY "$@" ||
+                       output git cherry-pick "$@" ||
                                die_with_patch $sha1 "Could not pick $sha1"
                        ;;
                esac
@@ -353,7 +361,7 @@ do
                git rev-parse --verify HEAD > /dev/null &&
                git update-index --refresh &&
                git diff-files --quiet &&
-               ! git diff-index --cached --quiet HEAD &&
+               ! git diff-index --cached --quiet HEAD -- &&
                . "$DOTEST"/author-script && {
                        test ! -f "$DOTEST"/amend || git reset --soft HEAD^
                } &&
@@ -387,10 +395,9 @@ do
                output git reset --hard && do_rest
                ;;
        -s|--strategy)
-               shift
                case "$#,$1" in
                *,*=*)
-                       STRATEGY="-s `expr "z$1" : 'z-[^=]*=\(.*\)'`" ;;
+                       STRATEGY="-s "$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
                1,*)
                        usage ;;
                *)
@@ -483,8 +490,13 @@ do
                SHORTUPSTREAM=$(git rev-parse --short $UPSTREAM)
                SHORTHEAD=$(git rev-parse --short $HEAD)
                SHORTONTO=$(git rev-parse --short $ONTO)
-               cat > "$TODO" << EOF
-# Rebasing $SHORTUPSTREAM..$SHORTHEAD onto $SHORTONTO
+               git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
+                       --abbrev=7 --reverse --left-right --cherry-pick \
+                       $UPSTREAM...$HEAD | \
+                       sed -n "s/^>/pick /p" > "$TODO"
+               cat >> "$TODO" << EOF
+
+# Rebase $SHORTUPSTREAM..$SHORTHEAD onto $SHORTONTO
 #
 # Commands:
 #  pick = use commit
@@ -492,12 +504,9 @@ do
 #  squash = use commit, but meld into previous commit
 #
 # If you remove a line here THAT COMMIT WILL BE LOST.
+# However, if you remove everything, the rebase will be aborted.
 #
 EOF
-               git rev-list $MERGES_OPTION --pretty=oneline --abbrev-commit \
-                       --abbrev=7 --reverse --left-right --cherry-pick \
-                       $UPSTREAM...$HEAD | \
-                       sed -n "s/^>/pick /p" >> "$TODO"
 
                has_action "$TODO" ||
                        die_abort "Nothing to do"