Skip to content

Commit da27a6f

Browse files
phillipwoodgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b79966a commit da27a6f

File tree

3 files changed

+40
-47
lines changed

3 files changed

+40
-47
lines changed

git-rebase--am.sh

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -38,59 +38,47 @@ else
3838
fi
3939

4040
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"
5342

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=$?
6150

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
7362

74-
cat >&2 <<-EOF
63+
cat >&2 <<-EOF
7564
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:
7867
79-
$revisions
68+
$revisions
8069
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
8574

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=$?
9180

92-
rm -f "$GIT_DIR/rebased-patches"
93-
fi
81+
rm -f "$GIT_DIR/rebased-patches"
9482

9583
if test 0 != $ret
9684
then

git-rebase.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ then
452452
test -z "$interactive_rebase" && interactive_rebase=implied
453453
fi
454454

455+
if test -n "$keep_empty"
456+
then
457+
test -z "$interactive_rebase" && interactive_rebase=implied
458+
fi
459+
455460
if test -n "$interactive_rebase"
456461
then
457462
type=interactive

t/t3421-rebase-topology-linear.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ test_run_rebase () {
199199
"
200200
}
201201
test_run_rebase success ''
202-
test_run_rebase failure -m
202+
test_run_rebase success -m
203203
test_run_rebase success -i
204204
test_run_rebase failure -p
205205

@@ -214,7 +214,7 @@ test_run_rebase () {
214214
"
215215
}
216216
test_run_rebase success ''
217-
test_run_rebase failure -m
217+
test_run_rebase success -m
218218
test_run_rebase success -i
219219
test_run_rebase failure -p
220220

0 commit comments

Comments
 (0)