rerere: mention caveat about unmatched conflict markers
[gitweb.git] / git-rebase.sh
index ded5de085a87505b244b7449b1977c3779650640..19bdebb48025e236c596d554768012951d348632 100755 (executable)
@@ -17,6 +17,7 @@ q,quiet!           be quiet. implies --no-stat
 autostash          automatically stash/stash pop before and after
 fork-point         use 'merge-base --fork-point' to refine upstream
 onto=!             rebase onto given branch instead of upstream
+r,rebase-merges?   try to rebase merges instead of skipping them
 p,preserve-merges! try to recreate merges instead of ignoring them
 s,strategy=!       use the given merge strategy
 no-ff!             cherry-pick all commits, even if unchanged
@@ -89,6 +90,8 @@ type=
 state_dir=
 # One of {'', continue, skip, abort}, as parsed from command line
 action=
+rebase_merges=
+rebase_cousins=
 preserve_merges=
 autosquash=
 keep_empty=
@@ -204,7 +207,14 @@ run_specific_rebase () {
                autosquash=
        fi
        . git-rebase--$type
-       git_rebase__$type${preserve_merges:+__preserve_merges}
+
+       if test -z "$preserve_merges"
+       then
+               git_rebase__$type
+       else
+               git_rebase__preserve_merges
+       fi
+
        ret=$?
        if test $ret -eq 0
        then
@@ -236,7 +246,12 @@ then
        state_dir="$apply_dir"
 elif test -d "$merge_dir"
 then
-       if test -f "$merge_dir"/interactive
+       if test -d "$merge_dir"/rewritten
+       then
+               type=preserve-merges
+               interactive_rebase=explicit
+               preserve_merges=t
+       elif test -f "$merge_dir"/interactive
        then
                type=interactive
                interactive_rebase=explicit
@@ -280,6 +295,19 @@ do
        --no-keep-empty)
                keep_empty=
                ;;
+       --rebase-merges)
+               rebase_merges=t
+               test -z "$interactive_rebase" && interactive_rebase=implied
+               ;;
+       --rebase-merges=*)
+               rebase_merges=t
+               case "${1#*=}" in
+               rebase-cousins) rebase_cousins=t;;
+               no-rebase-cousins) rebase_cousins=;;
+               *) die "Unknown mode: $1";;
+               esac
+               test -z "$interactive_rebase" && interactive_rebase=implied
+               ;;
        --preserve-merges)
                preserve_merges=t
                test -z "$interactive_rebase" && interactive_rebase=implied
@@ -386,14 +414,14 @@ if test -n "$action"
 then
        test -z "$in_progress" && die "$(gettext "No rebase in progress?")"
        # Only interactive rebase uses detailed reflog messages
-       if test "$type" = interactive && test "$GIT_REFLOG_ACTION" = rebase
+       if test -n "$interactive_rebase" && test "$GIT_REFLOG_ACTION" = rebase
        then
                GIT_REFLOG_ACTION="rebase -i ($action)"
                export GIT_REFLOG_ACTION
        fi
 fi
 
-if test "$action" = "edit-todo" && test "$type" != "interactive"
+if test "$action" = "edit-todo" && test -z "$interactive_rebase"
 then
        die "$(gettext "The --edit-todo action can only be used during interactive rebase.")"
 fi
@@ -471,7 +499,13 @@ fi
 
 if test -n "$interactive_rebase"
 then
-       type=interactive
+       if test -z "$preserve_merges"
+       then
+               type=interactive
+       else
+               type=preserve-merges
+       fi
+
        state_dir="$merge_dir"
 elif test -n "$do_merge"
 then
@@ -631,7 +665,7 @@ require_clean_work_tree "rebase" "$(gettext "Please commit or stash them.")"
 # but this should be done only when upstream and onto are the same
 # and if this is not an interactive rebase.
 mb=$(git merge-base "$onto" "$orig_head")
-if test "$type" != interactive && test "$upstream" = "$onto" &&
+if test -z "$interactive_rebase" && test "$upstream" = "$onto" &&
        test "$mb" = "$onto" && test -z "$restrict_revision" &&
        # linear history?
        ! (git rev-list --parents "$onto".."$orig_head" | sane_grep " .* ") > /dev/null
@@ -675,7 +709,7 @@ then
        GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
 fi
 
-test "$type" = interactive && run_specific_rebase
+test -n "$interactive_rebase" && run_specific_rebase
 
 # Detach HEAD and reset the tree
 say "$(gettext "First, rewinding head to replay your work on top of it...")"