Merge branch 'dk/format-patch-ignore-diff-submodule'
[gitweb.git] / git-rebase.sh
index a209ab9ce4ecc58ebaac293cd21cf3c031447abf..55da9db818665f39ed205d3c77352987e3ca9963 100755 (executable)
@@ -59,6 +59,7 @@ If you prefer to skip this patch, run "git rebase --skip" instead.
 To check out the original branch and stop rebasing, run "git rebase --abort".')
 "
 unset onto
+unset restrict_revision
 cmd=
 strategy=
 strategy_opts=
@@ -155,7 +156,7 @@ move_to_original_branch () {
        esac
 }
 
-finish_rebase () {
+apply_autostash () {
        if test -f "$state_dir/autostash"
        then
                stash_sha1=$(cat "$state_dir/autostash")
@@ -171,30 +172,30 @@ You can run "git stash pop" or "git stash drop" at any time.
 '
                fi
        fi
+}
+
+finish_rebase () {
+       apply_autostash &&
        git gc --auto &&
        rm -rf "$state_dir"
 }
 
-run_specific_rebase_internal () {
+run_specific_rebase () {
        if [ "$interactive_rebase" = implied ]; then
                GIT_EDITOR=:
                export GIT_EDITOR
                autosquash=
        fi
-       # On FreeBSD, the shell's "return" returns from the current
-       # function, not from the current file inclusion.
-       # run_specific_rebase_internal has the file inclusion as a
-       # last statement, so POSIX and FreeBSD's return will do the
-       # same thing.
        . git-rebase--$type
-}
-
-run_specific_rebase () {
-       run_specific_rebase_internal
        ret=$?
        if test $ret -eq 0
        then
                finish_rebase
+       elif test $ret -eq 2 # special exit status for rebase -i
+       then
+               apply_autostash &&
+               rm -rf "$state_dir" &&
+               die "Nothing to do"
        fi
        exit $ret
 }
@@ -453,6 +454,10 @@ then
                test "$fork_point" = auto && fork_point=t
                ;;
        *)      upstream_name="$1"
+               if test "$upstream_name" = "-"
+               then
+                       upstream_name="@{-1}"
+               fi
                shift
                ;;
        esac
@@ -542,7 +547,7 @@ then
                        "${switch_to:-HEAD}")
        if test -n "$new_upstream"
        then
-               upstream=$new_upstream
+               restrict_revision=$new_upstream
        fi
 fi
 
@@ -568,7 +573,7 @@ require_clean_work_tree "rebase" "$(gettext "Please commit or stash them.")"
 # and if this is not an interactive rebase.
 mb=$(git merge-base "$onto" "$orig_head")
 if test "$type" != interactive && test "$upstream" = "$onto" &&
-       test "$mb" = "$onto" &&
+       test "$mb" = "$onto" && test -z "$restrict_revision" &&
        # linear history?
        ! (git rev-list --parents "$onto".."$orig_head" | sane_grep " .* ") > /dev/null
 then
@@ -622,7 +627,7 @@ if test -n "$rebase_root"
 then
        revisions="$onto..$orig_head"
 else
-       revisions="$upstream..$orig_head"
+       revisions="${restrict_revision-$upstream}..$orig_head"
 fi
 
 run_specific_rebase