rebase --keep-empty: always use interactive rebase

rebase --merge accepts --keep-empty but just ignores it, by using an implicit interactive rebase the user still gets the rename detection of a merge based rebase but with with --keep-empty support. If rebase --keep-empty without --interactive or --merge stops for the user to resolve merge conflicts then 'git rebase --continue' will fail. This is because it uses a different code path that does not create $git_dir/rebase-apply. As rebase --keep-empty was implemented using cherry-pick it has never supported the am options and now that interactive rebases support --signoff there is no loss of functionality by using an implicit interactive rebase. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phillip Wood committed Mar 20, 2018 at 11:10 UTC da27a6fbd50861149b32cfd1f9e5c36a935c575a
3 files changed +40 -47
git-rebase--am.sh
+33 -45
@@ -38,59 +38,47 @@ else
38 fi
39
40 ret=0
41 -if test -n "$keep_empty"
42 -then
43 - # we have to do this the hard way. git format-patch completely squashes
44 - # empty commits and even if it didn't the format doesn't really lend
45 - # itself well to recording empty patches. fortunately, cherry-pick
46 - # makes this easy
47 - git cherry-pick ${gpg_sign_opt:+"$gpg_sign_opt"} --allow-empty \
48 - $allow_rerere_autoupdate --right-only "$revisions" \
49 - ${restrict_revision+^$restrict_revision}
50 - ret=$?
51 -else
52 - rm -f "$GIT_DIR/rebased-patches"
41 +rm -f "$GIT_DIR/rebased-patches"
42
54 - git format-patch -k --stdout --full-index --cherry-pick --right-only \
55 - --src-prefix=a/ --dst-prefix=b/ --no-renames --no-cover-letter \
56 - --pretty=mboxrd \
57 - $git_format_patch_opt \
58 - "$revisions" ${restrict_revision+^$restrict_revision} \
59 - >"$GIT_DIR/rebased-patches"
60 - ret=$?
43 +git format-patch -k --stdout --full-index --cherry-pick --right-only \
44 + --src-prefix=a/ --dst-prefix=b/ --no-renames --no-cover-letter \
45 + --pretty=mboxrd \
46 + $git_format_patch_opt \
47 + "$revisions" ${restrict_revision+^$restrict_revision} \
48 + >"$GIT_DIR/rebased-patches"
49 +ret=$?
50
62 - if test 0 != $ret
63 - then
64 - rm -f "$GIT_DIR/rebased-patches"
65 - case "$head_name" in
66 - refs/heads/*)
67 - git checkout -q "$head_name"
68 - ;;
69 - *)
70 - git checkout -q "$orig_head"
71 - ;;
72 - esac
51 +if test 0 != $ret
52 +then
53 + rm -f "$GIT_DIR/rebased-patches"
54 + case "$head_name" in
55 + refs/heads/*)
56 + git checkout -q "$head_name"
57 + ;;
58 + *)
59 + git checkout -q "$orig_head"
60 + ;;
61 + esac
62
74 - cat >&2 <<-EOF
63 + cat >&2 <<-EOF
64
76 - git encountered an error while preparing the patches to replay
77 - these revisions:
65 + git encountered an error while preparing the patches to replay
66 + these revisions:
67
79 - $revisions
68 + $revisions
69
81 - As a result, git cannot rebase them.
82 - EOF
83 - return $ret
84 - fi
70 + As a result, git cannot rebase them.
71 + EOF
72 + return $ret
73 +fi
74
86 - git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" \
87 - --patch-format=mboxrd \
88 - $allow_rerere_autoupdate \
89 - ${gpg_sign_opt:+"$gpg_sign_opt"} <"$GIT_DIR/rebased-patches"
90 - ret=$?
75 +git am $git_am_opt --rebasing --resolvemsg="$resolvemsg" \
76 + --patch-format=mboxrd \
77 + $allow_rerere_autoupdate \
78 + ${gpg_sign_opt:+"$gpg_sign_opt"} <"$GIT_DIR/rebased-patches"
79 +ret=$?
80
92 - rm -f "$GIT_DIR/rebased-patches"
93 -fi
81 +rm -f "$GIT_DIR/rebased-patches"
82
83 if test 0 != $ret
84 then
git-rebase.sh
+5
@@ -452,6 +452,11 @@ then
452 test -z "$interactive_rebase" && interactive_rebase=implied
453 fi
454
455 +if test -n "$keep_empty"
456 +then
457 + test -z "$interactive_rebase" && interactive_rebase=implied
458 +fi
459 +
460 if test -n "$interactive_rebase"
461 then
462 type=interactive
t/t3421-rebase-topology-linear.sh
+2 -2
@@ -199,7 +199,7 @@ test_run_rebase () {
199 "
200 }
201 test_run_rebase success ''
202 -test_run_rebase failure -m
202 +test_run_rebase success -m
203 test_run_rebase success -i
204 test_run_rebase failure -p
205
@@ -214,7 +214,7 @@ test_run_rebase () {
214 "
215 }
216 test_run_rebase success ''
217 -test_run_rebase failure -m
217 +test_run_rebase success -m
218 test_run_rebase success -i
219 test_run_rebase failure -p
220