Skip to content

Commit 040fd39

Browse files
bafaingitster
authored andcommitted
rebase -i: remember merge options beyond continue actions
If the user explicitly specified a merge strategy or strategy options, continue to use that strategy/option after "rebase --continue". Add a test of the corrected behavior. If --merge is specified or implied by -s or -X, then "strategy and "strategy_opts" are set to values from which "strategy_args" can be derived; otherwise they are set to empty strings. Either way, their values are propagated from one step of an interactive rebase to the next via state files. "do_merge", on the other hand, is *not* propagated to later steps of an interactive rebase. Therefore, making the initialization of "strategy_args" conditional on "do_merge" being set prevents later steps of an interactive rebase from setting it correctly. Luckily, we don't need the "do_merge" guard at all. If the rebase was started without --merge, then "strategy" and "strategy_opts" are both the empty string, which results in "strategy_args" also being set to the empty string, which is just what we want in that situation. So remove the "do_merge" guard and derive "strategy_args" from "strategy" and "strategy_opts" every time. Reported-by: Diogo de Campos <[email protected]> Signed-off-by: Fabian Ruch <[email protected]> Helped-by: Michael Haggerty <[email protected]> Signed-off-by: Ralf Thielow <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 49e863b commit 040fd39

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

git-rebase--interactive.sh

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,13 @@ rewritten_pending="$state_dir"/rewritten-pending
8181
# and leaves CR at the end instead.
8282
cr=$(printf "\015")
8383

84-
strategy_args=
85-
if test -n "$do_merge"
86-
then
87-
strategy_args=${strategy:+--strategy=$strategy}
88-
eval '
89-
for strategy_opt in '"$strategy_opts"'
90-
do
91-
strategy_args="$strategy_args -X$(git rev-parse --sq-quote "${strategy_opt#--}")"
92-
done
93-
'
94-
fi
84+
strategy_args=${strategy:+--strategy=$strategy}
85+
eval '
86+
for strategy_opt in '"$strategy_opts"'
87+
do
88+
strategy_args="$strategy_args -X$(git rev-parse --sq-quote "${strategy_opt#--}")"
89+
done
90+
'
9591

9692
GIT_CHERRY_PICK_HELP="$resolvemsg"
9793
export GIT_CHERRY_PICK_HELP

t/t3404-rebase-interactive.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,22 @@ test_expect_success 'rebase -i with --strategy and -X' '
10061006
test $(cat file1) = Z
10071007
'
10081008

1009+
test_expect_success 'interrupted rebase -i with --strategy and -X' '
1010+
git checkout -b conflict-merge-use-theirs-interrupted conflict-branch &&
1011+
git reset --hard HEAD^ &&
1012+
>breakpoint &&
1013+
git add breakpoint &&
1014+
git commit -m "breakpoint for interactive mode" &&
1015+
echo five >conflict &&
1016+
echo Z >file1 &&
1017+
git commit -a -m "one file conflict" &&
1018+
set_fake_editor &&
1019+
FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive -Xours conflict-branch &&
1020+
git rebase --continue &&
1021+
test $(git show conflict-branch:conflict) = $(cat conflict) &&
1022+
test $(cat file1) = Z
1023+
'
1024+
10091025
test_expect_success 'rebase -i error on commits with \ in message' '
10101026
current_head=$(git rev-parse HEAD) &&
10111027
test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&

0 commit comments

Comments
 (0)