X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-rebase.sh;h=20f74d416732e681d3b44ea610e428529af49235;hb=b3dc864c6d5ffb96513328f976c076c3a90331b0;hp=bce7bf84d6d1eca8c245e2ca89764ed8a4062191;hpb=58634dbff8221f158118342975f6cd281af14fd9;p=git.git diff --git a/git-rebase.sh b/git-rebase.sh index bce7bf84d..20f74d416 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -34,13 +34,14 @@ When you have resolved this problem run \"git rebase --continue\". If you would prefer to skip this patch, instead run \"git rebase --skip\". To restore the original branch and stop rebasing run \"git rebase --abort\". " - -MRESOLVEMSG=" -When you have resolved this problem run \"git rebase --continue\". -To restore the original branch and stop rebasing run \"git rebase --abort\". -" unset newbase -strategy=recursive +case "${GIT_USE_RECUR_FOR_RECURSIVE}" in +'') + strategy=recursive ;; +?*) + strategy=recur ;; +esac + do_merge= dotest=$GIT_DIR/.dotest-merge prec=4 @@ -54,43 +55,49 @@ continue_merge () { then echo "You still have unmerged paths in your index" echo "did you forget update-index?" - die "$MRESOLVEMSG" + die "$RESOLVEMSG" fi if test -n "`git-diff-index HEAD`" then - git-commit -C "`cat $dotest/current`" + if ! git-commit -C "`cat $dotest/current`" + then + echo "Commit failed, please do not call \"git commit\"" + echo "directly, but instead do one of the following: " + die "$RESOLVEMSG" + fi + printf "Committed: %0${prec}d" $msgnum else - echo "Previous merge succeeded automatically" + printf "Already applied: %0${prec}d" $msgnum fi + echo ' '`git-rev-list --pretty=oneline -1 HEAD | \ + sed 's/^[a-f0-9]\+ //'` prev_head=`git-rev-parse HEAD^0` - # save the resulting commit so we can read-tree on it later - echo "$prev_head" > "$dotest/`printf %0${prec}d $msgnum`.result" echo "$prev_head" > "$dotest/prev_head" # onto the next patch: msgnum=$(($msgnum + 1)) - printf "%0${prec}d" "$msgnum" > "$dotest/msgnum" + echo "$msgnum" >"$dotest/msgnum" } call_merge () { - cmt="$(cat $dotest/`printf %0${prec}d $1`)" + cmt="$(cat $dotest/cmt.$1)" echo "$cmt" > "$dotest/current" git-merge-$strategy "$cmt^" -- HEAD "$cmt" rv=$? case "$rv" in 0) - git-commit -C "$cmt" || die "commit failed: $MRESOLVEMSG" + return ;; 1) test -d "$GIT_DIR/rr-cache" && git-rerere - die "$MRESOLVEMSG" + die "$RESOLVEMSG" ;; 2) echo "Strategy: $rv $strategy failed, try another" 1>&2 - die "$MRESOLVEMSG" + die "$RESOLVEMSG" ;; *) die "Unknown exit code ($rv) from command:" \ @@ -100,26 +107,6 @@ call_merge () { } finish_rb_merge () { - set -e - - msgnum=1 - echo "Finalizing rebased commits..." - git-reset --hard "`cat $dotest/onto`" - end="`cat $dotest/end`" - while test "$msgnum" -le "$end" - do - msgnum=`printf "%0${prec}d" "$msgnum"` - printf "%0${prec}d" "$msgnum" > "$dotest/msgnum" - - git-read-tree `cat "$dotest/$msgnum.result"` - git-checkout-index -q -f -u -a - git-commit -C "`cat $dotest/$msgnum`" - - echo "Committed $msgnum" - echo ' '`git-rev-list --pretty=oneline -1 HEAD | \ - sed 's/^[a-f0-9]\+ //'` - msgnum=$(($msgnum + 1)) - done rm -r "$dotest" echo "All done." } @@ -150,15 +137,28 @@ do finish_rb_merge exit fi - git am --resolved --3way --resolvemsg="$RESOLVEMSG" + git am --resolved --3way --resolvemsg="$RESOLVEMSG" \ + --reflog-action=rebase exit ;; --skip) if test -d "$dotest" then - die "--skip is not supported when using --merge" + prev_head="`cat $dotest/prev_head`" + end="`cat $dotest/end`" + msgnum="`cat $dotest/msgnum`" + msgnum=$(($msgnum + 1)) + onto="`cat $dotest/onto`" + while test "$msgnum" -le "$end" + do + call_merge "$msgnum" + continue_merge + done + finish_rb_merge + exit fi - git am -3 --skip --resolvemsg="$RESOLVEMSG" + git am -3 --skip --resolvemsg="$RESOLVEMSG" \ + --reflog-action=rebase exit ;; --abort) @@ -187,7 +187,7 @@ do -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy) case "$#,$1" in *,*=*) - strategy=`expr "$1" : '-[^=]*=\(.*\)'` ;; + strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;; 1,*) usage ;; *) @@ -206,6 +206,11 @@ do shift done +case "$strategy,${GIT_USE_RECUR_FOR_RECURSIVE}" in +recursive,?*) + strategy=recur ;; +esac + # Make sure we do not have .dotest if test -z "$do_merge" then @@ -272,14 +277,11 @@ onto=$(git-rev-parse --verify "${onto_name}^0") || exit # Check if we are already based on $onto, but this should be # done only when upstream and onto are the same. -if test "$upstream" = "$onto" +mb=$(git-merge-base "$onto" "$branch") +if test "$upstream" = "$onto" && test "$mb" = "$onto" then - mb=$(git-merge-base "$onto" "$branch") - if test "$mb" = "$onto" - then - echo >&2 "Current branch $branch_name is up to date." - exit 0 - fi + echo >&2 "Current branch $branch_name is up to date." + exit 0 fi # Rewind the head to "$onto"; this saves our current head in ORIG_HEAD. @@ -287,19 +289,29 @@ git-reset --hard "$onto" # If the $onto is a proper descendant of the tip of the branch, then # we just fast forwarded. -if test "$mb" = "$onto" +if test "$mb" = "$branch" then - echo >&2 "Fast-forwarded $branch to $newbase." + echo >&2 "Fast-forwarded $branch_name to $onto_name." exit 0 fi if test -z "$do_merge" then git-format-patch -k --stdout --full-index "$upstream"..ORIG_HEAD | - git am --binary -3 -k --resolvemsg="$RESOLVEMSG" + git am --binary -3 -k --resolvemsg="$RESOLVEMSG" \ + --reflog-action=rebase exit $? fi +if test "@@NO_PYTHON@@" && test "$strategy" = "recursive" +then + die 'The recursive merge strategy currently relies on Python, +which this installation of git was not configured with. Please consider +a different merge strategy (e.g. octopus, resolve, stupid, ours) +or install Python and git with Python support.' + +fi + # start doing a rebase with git-merge # this is rename-aware if the recursive (default) strategy is used @@ -310,14 +322,14 @@ echo "$prev_head" > "$dotest/prev_head" msgnum=0 for cmt in `git-rev-list --no-merges "$upstream"..ORIG_HEAD \ - | perl -e 'print reverse <>'` + | @@PERL@@ -e 'print reverse <>'` do msgnum=$(($msgnum + 1)) - echo "$cmt" > "$dotest/`printf "%0${prec}d" $msgnum`" + echo "$cmt" > "$dotest/cmt.$msgnum" done -printf "%0${prec}d" 1 > "$dotest/msgnum" -printf "%0${prec}d" "$msgnum" > "$dotest/end" +echo 1 >"$dotest/msgnum" +echo $msgnum >"$dotest/end" end=$msgnum msgnum=1