rebase: use the new git-rebase--preserve-merges.sh

Create a new type of rebase, "preserve-merges", used when rebase is called with -p. Before that, the type for preserve-merges was "interactive", and some places of this script compared $type to "interactive". Instead, the code now checks if $interactive_rebase is empty or not, as it is set to "explicit" when calling an interactive rebase (and, possibly, one of its submodes), and "implied" when calling one of its submodes (eg. preserve-merges) *without* interactive rebase. It also detects the presence of the directory "$merge_dir"/rewritten left by the preserve-merges script when calling rebase --continue, --skip, etc., and, if it exists, sets the rebase mode to preserve-merges. In this case, interactive_rebase is set to "explicit", as "implied" would break some tests. Signed-off-by: Alban Gruin <alban.gruin@gmail.com>

Alban Gruin committed May 28, 2018 at 14:34 UTC 6d98d0c018cc8008af386f19a43a8b823a5a08d8
1 file changed +25 -7
git-rebase.sh
+25 -7
@@ -207,7 +207,14 @@ run_specific_rebase () {
207 autosquash=
208 fi
209 . git-rebase--$type
210 - git_rebase__$type${preserve_merges:+__preserve_merges}
210 +
211 + if test -z "$preserve_merges"
212 + then
213 + git_rebase__$type
214 + else
215 + git_rebase__preserve_merges
216 + fi
217 +
218 ret=$?
219 if test $ret -eq 0
220 then
@@ -239,7 +246,12 @@ then
246 state_dir="$apply_dir"
247 elif test -d "$merge_dir"
248 then
242 - if test -f "$merge_dir"/interactive
249 + if test -d "$merge_dir"/rewritten
250 + then
251 + type=preserve-merges
252 + interactive_rebase=explicit
253 + preserve_merges=t
254 + elif test -f "$merge_dir"/interactive
255 then
256 type=interactive
257 interactive_rebase=explicit
@@ -402,14 +414,14 @@ if test -n "$action"
414 then
415 test -z "$in_progress" && die "$(gettext "No rebase in progress?")"
416 # Only interactive rebase uses detailed reflog messages
405 - if test "$type" = interactive && test "$GIT_REFLOG_ACTION" = rebase
417 + if test -n "$interactive_rebase" && test "$GIT_REFLOG_ACTION" = rebase
418 then
419 GIT_REFLOG_ACTION="rebase -i ($action)"
420 export GIT_REFLOG_ACTION
421 fi
422 fi
423
412 -if test "$action" = "edit-todo" && test "$type" != "interactive"
424 +if test "$action" = "edit-todo" && test -z "$interactive_rebase"
425 then
426 die "$(gettext "The --edit-todo action can only be used during interactive rebase.")"
427 fi
@@ -487,7 +499,13 @@ fi
499
500 if test -n "$interactive_rebase"
501 then
490 - type=interactive
502 + if test -z "$preserve_merges"
503 + then
504 + type=interactive
505 + else
506 + type=preserve-merges
507 + fi
508 +
509 state_dir="$merge_dir"
510 elif test -n "$do_merge"
511 then
@@ -647,7 +665,7 @@ require_clean_work_tree "rebase" "$(gettext "Please commit or stash them.")"
665 # but this should be done only when upstream and onto are the same
666 # and if this is not an interactive rebase.
667 mb=$(git merge-base "$onto" "$orig_head")
650 -if test "$type" != interactive && test "$upstream" = "$onto" &&
668 +if test -z "$interactive_rebase" && test "$upstream" = "$onto" &&
669 test "$mb" = "$onto" && test -z "$restrict_revision" &&
670 # linear history?
671 ! (git rev-list --parents "$onto".."$orig_head" | sane_grep " .* ") > /dev/null
@@ -691,7 +709,7 @@ then
709 GIT_PAGER='' git diff --stat --summary "$mb" "$onto"
710 fi
711
694 -test "$type" = interactive && run_specific_rebase
712 +test -n "$interactive_rebase" && run_specific_rebase
713
714 # Detach HEAD and reset the tree
715 say "$(gettext "First, rewinding head to replay your work on top of it...")"