Code

Porcelain scripts: Rewrite cryptic "needs update" error message
[git.git] / git-rebase.sh
index 1b9ea48cd713d7f6b25e529d09743447635f6432..988b3d8142c80fc58008025b4301c303502ce1a2 100755 (executable)
@@ -44,6 +44,7 @@ To restore the original branch and stop rebasing run \"git rebase --abort\".
 "
 unset newbase
 strategy=recursive
+strategy_opts=
 do_merge=
 dotest="$GIT_DIR"/rebase-merge
 prec=4
@@ -110,9 +111,9 @@ call_merge () {
        export GITHEAD_$cmt GITHEAD_$hd
        if test -n "$GIT_QUIET"
        then
-               export GIT_MERGE_VERBOSITY=1
+               GIT_MERGE_VERBOSITY=1 && export GIT_MERGE_VERBOSITY
        fi
-       git-merge-$strategy "$cmt^" -- "$hd" "$cmt"
+       eval 'git-merge-$strategy' $strategy_opts '"$cmt^" -- "$hd" "$cmt"'
        rv=$?
        case "$rv" in
        0)
@@ -294,6 +295,27 @@ do
        -M|-m|--m|--me|--mer|--merg|--merge)
                do_merge=t
                ;;
+       -X*|--strategy-option*)
+               case "$#,$1" in
+               1,-X|1,--strategy-option)
+                       usage ;;
+               *,-X|*,--strategy-option)
+                       newopt="$2"
+                       shift ;;
+               *,--strategy-option=*)
+                       newopt="$(expr " $1" : ' --strategy-option=\(.*\)')" ;;
+               *,-X*)
+                       newopt="$(expr " $1" : ' -X\(.*\)')" ;;
+               1,*)
+                       usage ;;
+               esac
+               strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$newopt")"
+               do_merge=t
+               if test -n "$strategy"
+               then
+                       strategy=recursive
+               fi
+               ;;
        -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
                --strateg=*|--strategy=*|\
        -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
@@ -394,19 +416,7 @@ else
        fi
 fi
 
-# The tree must be really really clean.
-if ! git update-index --ignore-submodules --refresh > /dev/null; then
-       echo >&2 "cannot rebase: you have unstaged changes"
-       git diff-files --name-status -r --ignore-submodules -- >&2
-       exit 1
-fi
-diff=$(git diff-index --cached --name-status -r --ignore-submodules HEAD --)
-case "$diff" in
-?*)    echo >&2 "cannot rebase: your index contains uncommitted changes"
-       echo >&2 "$diff"
-       exit 1
-       ;;
-esac
+require_clean_work_tree "rebase" "Please commit or stash them."
 
 if test -z "$rebase_root"
 then
@@ -544,6 +554,7 @@ fi
 if test -z "$do_merge"
 then
        git format-patch -k --stdout --full-index --ignore-if-in-upstream \
+               --src-prefix=a/ --dst-prefix=b/ \
                --no-renames $root_flag "$revisions" |
        git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
        move_to_original_branch