Skip to content

Commit 80ff479

Browse files
Martin von Zweigbergkgitster
authored andcommitted
rebase: remember strategy and strategy options
When a rebase is resumed, interactive rebase remembers any merge strategy passed when the rebase was initated. Make non-interactive rebase remember any merge strategy as well. Also make non-interactive rebase remember any merge strategy options. To be able to resume a rebase that was initiated with an older version of git (older than this commit), make sure not to expect the saved option files to exist. Test case idea taken from Junio's 71fc224 (t3402: test "rebase -s<strategy> -X<opt>", 2010-11-11). Signed-off-by: Martin von Zweigbergk <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7b37a7c commit 80ff479

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

git-rebase--interactive.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,6 @@ skip_unnecessary_picks () {
584584

585585
get_saved_options () {
586586
test -d "$rewritten" && preserve_merges=t
587-
test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
588587
test -f "$state_dir"/rebase-root && rebase_root=t
589588
}
590589

@@ -713,7 +712,6 @@ case "$rebase_root" in
713712
*)
714713
: >"$state_dir"/rebase-root ;;
715714
esac
716-
test -z "$strategy" || echo "$strategy" > "$state_dir"/strategy
717715
if test t = "$preserve_merges"
718716
then
719717
if test -z "$rebase_root"

git-rebase.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ read_basic_state () {
8181
fi &&
8282
GIT_QUIET=$(cat "$state_dir"/quiet) &&
8383
test -f "$state_dir"/verbose && verbose=t
84+
test -f "$state_dir"/strategy && strategy="$(cat "$state_dir"/strategy)"
85+
test -f "$state_dir"/strategy_opts &&
86+
strategy_opts="$(cat "$state_dir"/strategy_opts)"
8487
}
8588

8689
write_basic_state () {
@@ -89,6 +92,9 @@ write_basic_state () {
8992
echo "$orig_head" > "$state_dir"/orig-head &&
9093
echo "$GIT_QUIET" > "$state_dir"/quiet &&
9194
test t = "$verbose" && : > "$state_dir"/verbose
95+
test -n "$strategy" && echo "$strategy" > "$state_dir"/strategy
96+
test -n "$strategy_opts" && echo "$strategy_opts" > \
97+
"$state_dir"/strategy_opts
9298
}
9399

94100
output () {

t/t3418-rebase-continue.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,33 @@ test_expect_success 'rebase --continue can not be used with other options' '
4545
test_must_fail git rebase --continue -v
4646
'
4747

48+
test_expect_success 'rebase --continue remembers merge strategy and options' '
49+
rm -fr .git/rebase-* &&
50+
git reset --hard commit-new-file-F2-on-topic-branch &&
51+
test_commit "commit-new-file-F3-on-topic-branch" F3 32 &&
52+
test_when_finished "rm -fr test-bin funny.was.run" &&
53+
mkdir test-bin &&
54+
cat >test-bin/git-merge-funny <<-EOF
55+
#!$SHELL_PATH
56+
case "\$1" in --opt) ;; *) exit 2 ;; esac
57+
shift &&
58+
>funny.was.run &&
59+
exec git merge-recursive "\$@"
60+
EOF
61+
chmod +x test-bin/git-merge-funny &&
62+
(
63+
PATH=./test-bin:$PATH
64+
test_must_fail git rebase -s funny -Xopt master topic
65+
) &&
66+
test -f funny.was.run &&
67+
rm funny.was.run &&
68+
echo "Resolved" >F2 &&
69+
git add F2 &&
70+
(
71+
PATH=./test-bin:$PATH
72+
git rebase --continue
73+
) &&
74+
test -f funny.was.run
75+
'
76+
4877
test_done

0 commit comments

Comments
 (0)