Commit | Line | Data |
---|---|---|
25e93250 DK |
1 | #!/bin/sh |
2 | ||
3 | test_description='git rebase --continue tests' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | . "$TEST_DIRECTORY"/lib-rebase.sh | |
8 | ||
9 | set_fake_editor | |
10 | ||
11 | test_expect_success 'setup' ' | |
12 | test_commit "commit-new-file-F1" F1 1 && | |
13 | test_commit "commit-new-file-F2" F2 2 && | |
14 | ||
15 | git checkout -b topic HEAD^ && | |
16 | test_commit "commit-new-file-F2-on-topic-branch" F2 22 && | |
17 | ||
18 | git checkout master | |
19 | ' | |
20 | ||
21 | test_expect_success 'interactive rebase --continue works with touched file' ' | |
22 | rm -fr .git/rebase-* && | |
23 | git reset --hard && | |
24 | git checkout master && | |
25 | ||
26 | FAKE_LINES="edit 1" git rebase -i HEAD^ && | |
0e496492 | 27 | test-tool chmtime =-60 F1 && |
25e93250 DK |
28 | git rebase --continue |
29 | ' | |
30 | ||
31 | test_expect_success 'non-interactive rebase --continue works with touched file' ' | |
32 | rm -fr .git/rebase-* && | |
33 | git reset --hard && | |
34 | git checkout master && | |
35 | ||
36 | test_must_fail git rebase --onto master master topic && | |
37 | echo "Resolved" >F2 && | |
38 | git add F2 && | |
0e496492 | 39 | test-tool chmtime =-60 F1 && |
25e93250 DK |
40 | git rebase --continue |
41 | ' | |
42 | ||
95135b06 MZ |
43 | test_expect_success 'rebase --continue can not be used with other options' ' |
44 | test_must_fail git rebase -v --continue && | |
45 | test_must_fail git rebase --continue -v | |
46 | ' | |
47 | ||
80ff4795 MZ |
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 && | |
02380389 | 54 | cat >test-bin/git-merge-funny <<-EOF && |
80ff4795 MZ |
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 | ( | |
3ea67379 | 63 | PATH=./test-bin:$PATH && |
80ff4795 MZ |
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 | ( | |
3ea67379 | 71 | PATH=./test-bin:$PATH && |
80ff4795 MZ |
72 | git rebase --continue |
73 | ) && | |
74 | test -f funny.was.run | |
75 | ' | |
dd6fb005 | 76 | |
0060041d | 77 | test_expect_success 'rebase -i --continue handles merge strategy and options' ' |
a5a959d9 EN |
78 | rm -fr .git/rebase-* && |
79 | git reset --hard commit-new-file-F2-on-topic-branch && | |
80 | test_commit "commit-new-file-F3-on-topic-branch-for-dash-i" F3 32 && | |
81 | test_when_finished "rm -fr test-bin funny.was.run funny.args" && | |
82 | mkdir test-bin && | |
83 | cat >test-bin/git-merge-funny <<-EOF && | |
84 | #!$SHELL_PATH | |
85 | echo "\$@" >>funny.args | |
86 | case "\$1" in --opt) ;; *) exit 2 ;; esac | |
87 | case "\$2" in --foo) ;; *) exit 2 ;; esac | |
88 | case "\$4" in --) ;; *) exit 2 ;; esac | |
89 | shift 2 && | |
90 | >funny.was.run && | |
91 | exec git merge-recursive "\$@" | |
92 | EOF | |
93 | chmod +x test-bin/git-merge-funny && | |
94 | ( | |
95 | PATH=./test-bin:$PATH && | |
96 | test_must_fail git rebase -i -s funny -Xopt -Xfoo master topic | |
97 | ) && | |
98 | test -f funny.was.run && | |
99 | rm funny.was.run && | |
100 | echo "Resolved" >F2 && | |
101 | git add F2 && | |
102 | ( | |
103 | PATH=./test-bin:$PATH && | |
104 | git rebase --continue | |
105 | ) && | |
106 | test -f funny.was.run | |
107 | ' | |
108 | ||
11aad464 | 109 | test_expect_success REBASE_P 'rebase passes merge strategy options correctly' ' |
dd6fb005 JS |
110 | rm -fr .git/rebase-* && |
111 | git reset --hard commit-new-file-F3-on-topic-branch && | |
112 | test_commit theirs-to-merge && | |
113 | git reset --hard HEAD^ && | |
114 | test_commit some-commit && | |
115 | test_tick && | |
116 | git merge --no-ff theirs-to-merge && | |
117 | FAKE_LINES="1 edit 2 3" git rebase -i -f -p -m \ | |
118 | -s recursive --strategy-option=theirs HEAD~2 && | |
119 | test_commit force-change && | |
120 | git rebase --continue | |
121 | ' | |
d5bc6f29 | 122 | |
a63f990d JS |
123 | test_expect_success 'rebase -r passes merge strategy options correctly' ' |
124 | rm -fr .git/rebase-* && | |
125 | git reset --hard commit-new-file-F3-on-topic-branch && | |
126 | test_commit merge-theirs && | |
127 | git reset --hard HEAD^ && | |
128 | test_commit some-other-commit && | |
129 | test_tick && | |
130 | git merge --no-ff merge-theirs && | |
131 | FAKE_LINES="1 3 edit 4 5 7 8 9" git rebase -i -f -r -m \ | |
132 | -s recursive --strategy-option=theirs HEAD~2 && | |
133 | test_commit force-change-ours && | |
134 | git rebase --continue | |
dd6fb005 | 135 | ' |
d5bc6f29 | 136 | |
15ef6931 | 137 | test_expect_success '--skip after failed fixup cleans commit message' ' |
d5bc6f29 JS |
138 | test_when_finished "test_might_fail git rebase --abort" && |
139 | git checkout -b with-conflicting-fixup && | |
140 | test_commit wants-fixup && | |
141 | test_commit "fixup! wants-fixup" wants-fixup.t 1 wants-fixup-1 && | |
142 | test_commit "fixup! wants-fixup" wants-fixup.t 2 wants-fixup-2 && | |
143 | test_commit "fixup! wants-fixup" wants-fixup.t 3 wants-fixup-3 && | |
15ef6931 | 144 | test_must_fail env FAKE_LINES="1 fixup 2 squash 4" \ |
d5bc6f29 JS |
145 | git rebase -i HEAD~4 && |
146 | ||
147 | : now there is a conflict, and comments in the commit message && | |
148 | git show HEAD >out && | |
149 | grep "fixup! wants-fixup" out && | |
150 | ||
151 | : skip and continue && | |
15ef6931 JS |
152 | echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh && |
153 | (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) && | |
154 | ||
155 | : the user should not have had to edit the commit message && | |
156 | test_path_is_missing .git/copy.txt && | |
d5bc6f29 JS |
157 | |
158 | : now the comments in the commit message should have been cleaned up && | |
159 | git show HEAD >out && | |
15ef6931 JS |
160 | ! grep "fixup! wants-fixup" out && |
161 | ||
162 | : now, let us ensure that "squash" is handled correctly && | |
163 | git reset --hard wants-fixup-3 && | |
164 | test_must_fail env FAKE_LINES="1 squash 4 squash 2 squash 4" \ | |
165 | git rebase -i HEAD~4 && | |
166 | ||
167 | : the first squash failed, but there are two more in the chain && | |
168 | (test_set_editor "$PWD/copy-editor.sh" && | |
169 | test_must_fail git rebase --skip) && | |
170 | ||
171 | : not the final squash, no need to edit the commit message && | |
172 | test_path_is_missing .git/copy.txt && | |
173 | ||
174 | : The first squash was skipped, therefore: && | |
175 | git show HEAD >out && | |
176 | test_i18ngrep "# This is a combination of 2 commits" out && | |
dd2e36eb | 177 | test_i18ngrep "# This is the commit message #2:" out && |
15ef6931 JS |
178 | |
179 | (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) && | |
180 | git show HEAD >out && | |
181 | test_i18ngrep ! "# This is a combination" out && | |
182 | ||
183 | : Final squash failed, but there was still a squash && | |
dd2e36eb PW |
184 | test_i18ngrep "# This is a combination of 2 commits" .git/copy.txt && |
185 | test_i18ngrep "# This is the commit message #2:" .git/copy.txt | |
d5bc6f29 | 186 | ' |
80ff4795 | 187 | |
5fb415b5 | 188 | test_expect_success 'setup rerere database' ' |
b3e4847e MZ |
189 | rm -fr .git/rebase-* && |
190 | git reset --hard commit-new-file-F3-on-topic-branch && | |
02380389 | 191 | git checkout master && |
b3e4847e | 192 | test_commit "commit-new-file-F3" F3 3 && |
5fb415b5 | 193 | test_config rerere.enabled true && |
5ee4ef8b | 194 | git update-ref refs/heads/topic commit-new-file-F3-on-topic-branch && |
b3e4847e MZ |
195 | test_must_fail git rebase -m master topic && |
196 | echo "Resolved" >F2 && | |
5fb415b5 | 197 | cp F2 expected-F2 && |
b3e4847e MZ |
198 | git add F2 && |
199 | test_must_fail git rebase --continue && | |
200 | echo "Resolved" >F3 && | |
5fb415b5 | 201 | cp F3 expected-F3 && |
b3e4847e MZ |
202 | git add F3 && |
203 | git rebase --continue && | |
5fb415b5 | 204 | git reset --hard topic@{1} |
b3e4847e MZ |
205 | ' |
206 | ||
5fb415b5 PW |
207 | prepare () { |
208 | rm -fr .git/rebase-* && | |
209 | git reset --hard commit-new-file-F3-on-topic-branch && | |
210 | git checkout master && | |
211 | test_config rerere.enabled true | |
212 | } | |
213 | ||
214 | test_rerere_autoupdate () { | |
215 | action=$1 && | |
216 | test_expect_success "rebase $action --continue remembers --rerere-autoupdate" ' | |
217 | prepare && | |
218 | test_must_fail git rebase $action --rerere-autoupdate master topic && | |
219 | test_cmp expected-F2 F2 && | |
220 | git diff-files --quiet && | |
221 | test_must_fail git rebase --continue && | |
222 | test_cmp expected-F3 F3 && | |
223 | git diff-files --quiet && | |
224 | git rebase --continue | |
225 | ' | |
226 | ||
227 | test_expect_success "rebase $action --continue honors rerere.autoUpdate" ' | |
228 | prepare && | |
229 | test_config rerere.autoupdate true && | |
230 | test_must_fail git rebase $action master topic && | |
231 | test_cmp expected-F2 F2 && | |
232 | git diff-files --quiet && | |
233 | test_must_fail git rebase --continue && | |
234 | test_cmp expected-F3 F3 && | |
235 | git diff-files --quiet && | |
236 | git rebase --continue | |
237 | ' | |
238 | ||
239 | test_expect_success "rebase $action --continue remembers --no-rerere-autoupdate" ' | |
240 | prepare && | |
241 | test_config rerere.autoupdate true && | |
242 | test_must_fail git rebase $action --no-rerere-autoupdate master topic && | |
243 | test_cmp expected-F2 F2 && | |
244 | test_must_fail git diff-files --quiet && | |
245 | git add F2 && | |
246 | test_must_fail git rebase --continue && | |
247 | test_cmp expected-F3 F3 && | |
248 | test_must_fail git diff-files --quiet && | |
249 | git add F3 && | |
250 | git rebase --continue | |
251 | ' | |
252 | } | |
253 | ||
254 | test_rerere_autoupdate | |
255 | test_rerere_autoupdate -m | |
9b6d7a62 PW |
256 | GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR |
257 | test_rerere_autoupdate -i | |
11aad464 | 258 | test_have_prereq !REBASE_P || test_rerere_autoupdate --preserve-merges |
71f82465 JS |
259 | unset GIT_SEQUENCE_EDITOR |
260 | ||
261 | test_expect_success 'the todo command "break" works' ' | |
262 | rm -f execed && | |
3a4a4cab JS |
263 | FAKE_LINES="break b exec_>execed" git rebase -i HEAD && |
264 | test_path_is_missing execed && | |
265 | git rebase --continue && | |
71f82465 JS |
266 | test_path_is_missing execed && |
267 | git rebase --continue && | |
268 | test_path_is_file execed | |
269 | ' | |
5fb415b5 | 270 | |
d421afa0 JS |
271 | test_expect_success '--reschedule-failed-exec' ' |
272 | test_when_finished "git rebase --abort" && | |
273 | test_must_fail git rebase -x false --reschedule-failed-exec HEAD^ && | |
969de3ff JS |
274 | grep "^exec false" .git/rebase-merge/git-rebase-todo && |
275 | git rebase --abort && | |
276 | test_must_fail git -c rebase.rescheduleFailedExec=true \ | |
277 | rebase -x false HEAD^ 2>err && | |
278 | grep "^exec false" .git/rebase-merge/git-rebase-todo && | |
279 | test_i18ngrep "has been rescheduled" err | |
d421afa0 JS |
280 | ' |
281 | ||
906b6394 JS |
282 | test_expect_success 'rebase.reschedulefailedexec only affects `rebase -i`' ' |
283 | test_config rebase.reschedulefailedexec true && | |
284 | test_must_fail git rebase -x false HEAD^ && | |
285 | grep "^exec false" .git/rebase-merge/git-rebase-todo && | |
286 | git rebase --abort && | |
287 | git rebase HEAD^ | |
288 | ' | |
289 | ||
25e93250 | 290 | test_done |