]>
Commit | Line | Data |
---|---|---|
f59baa50 NS |
1 | #!/bin/sh |
2 | ||
3 | test_description='auto squash' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
22c5b136 AP |
7 | . "$TEST_DIRECTORY"/lib-rebase.sh |
8 | ||
f59baa50 NS |
9 | test_expect_success setup ' |
10 | echo 0 >file0 && | |
11 | git add . && | |
12 | test_tick && | |
13 | git commit -m "initial commit" && | |
14 | echo 0 >file1 && | |
15 | echo 2 >file2 && | |
16 | git add . && | |
17 | test_tick && | |
18 | git commit -m "first commit" && | |
b1a6c0a9 | 19 | git tag first-commit && |
f59baa50 NS |
20 | echo 3 >file3 && |
21 | git add . && | |
22 | test_tick && | |
23 | git commit -m "second commit" && | |
24 | git tag base | |
25 | ' | |
26 | ||
b1a6c0a9 | 27 | test_auto_fixup () { |
c232ffa8 DL |
28 | no_squash= && |
29 | if test "x$1" = 'x!' | |
30 | then | |
31 | no_squash=true | |
32 | shift | |
33 | fi && | |
34 | ||
f59baa50 NS |
35 | git reset --hard base && |
36 | echo 1 >file1 && | |
37 | git add -u && | |
38 | test_tick && | |
7c6eafa3 | 39 | git commit -m "fixup! first" && |
f59baa50 | 40 | |
dd1e5b31 | 41 | git tag $1 && |
f59baa50 | 42 | test_tick && |
dd1e5b31 | 43 | git rebase $2 -i HEAD^^^ && |
f59baa50 | 44 | git log --oneline >actual && |
c232ffa8 DL |
45 | if test -n "$no_squash" |
46 | then | |
47 | test_line_count = 4 actual | |
48 | else | |
49 | test_line_count = 3 actual && | |
50 | git diff --exit-code $1 && | |
51 | echo 1 >expect && | |
52 | git cat-file blob HEAD^:file1 >actual && | |
53 | test_cmp expect actual && | |
54 | git cat-file commit HEAD^ >commit && | |
55 | grep first commit >actual && | |
56 | test_line_count = 1 actual | |
57 | fi | |
dd1e5b31 HV |
58 | } |
59 | ||
60 | test_expect_success 'auto fixup (option)' ' | |
61 | test_auto_fixup final-fixup-option --autosquash | |
62 | ' | |
63 | ||
64 | test_expect_success 'auto fixup (config)' ' | |
65 | git config rebase.autosquash true && | |
66 | test_auto_fixup final-fixup-config-true && | |
c232ffa8 | 67 | test_auto_fixup ! fixup-config-true-no --no-autosquash && |
dd1e5b31 | 68 | git config rebase.autosquash false && |
c232ffa8 | 69 | test_auto_fixup ! final-fixup-config-false |
f59baa50 NS |
70 | ' |
71 | ||
b1a6c0a9 | 72 | test_auto_squash () { |
c232ffa8 DL |
73 | no_squash= && |
74 | if test "x$1" = 'x!' | |
75 | then | |
76 | no_squash=true | |
77 | shift | |
78 | fi && | |
79 | ||
f59baa50 NS |
80 | git reset --hard base && |
81 | echo 1 >file1 && | |
82 | git add -u && | |
83 | test_tick && | |
7c6eafa3 | 84 | git commit -m "squash! first" && |
f59baa50 | 85 | |
dd1e5b31 | 86 | git tag $1 && |
f59baa50 | 87 | test_tick && |
dd1e5b31 | 88 | git rebase $2 -i HEAD^^^ && |
f59baa50 | 89 | git log --oneline >actual && |
c232ffa8 DL |
90 | if test -n "$no_squash" |
91 | then | |
92 | test_line_count = 4 actual | |
93 | else | |
94 | test_line_count = 3 actual && | |
95 | git diff --exit-code $1 && | |
96 | echo 1 >expect && | |
97 | git cat-file blob HEAD^:file1 >actual && | |
98 | test_cmp expect actual && | |
99 | git cat-file commit HEAD^ >commit && | |
100 | grep first commit >actual && | |
101 | test_line_count = 2 actual | |
102 | fi | |
dd1e5b31 HV |
103 | } |
104 | ||
105 | test_expect_success 'auto squash (option)' ' | |
106 | test_auto_squash final-squash --autosquash | |
107 | ' | |
108 | ||
109 | test_expect_success 'auto squash (config)' ' | |
110 | git config rebase.autosquash true && | |
111 | test_auto_squash final-squash-config-true && | |
c232ffa8 | 112 | test_auto_squash ! squash-config-true-no --no-autosquash && |
dd1e5b31 | 113 | git config rebase.autosquash false && |
c232ffa8 | 114 | test_auto_squash ! final-squash-config-false |
f59baa50 NS |
115 | ' |
116 | ||
117 | test_expect_success 'misspelled auto squash' ' | |
118 | git reset --hard base && | |
119 | echo 1 >file1 && | |
120 | git add -u && | |
121 | test_tick && | |
7c6eafa3 | 122 | git commit -m "squash! forst" && |
f59baa50 NS |
123 | git tag final-missquash && |
124 | test_tick && | |
125 | git rebase --autosquash -i HEAD^^^ && | |
126 | git log --oneline >actual && | |
3fb0459b | 127 | test_line_count = 4 actual && |
f59baa50 | 128 | git diff --exit-code final-missquash && |
a781cd6f DL |
129 | git rev-list final-missquash...HEAD >list && |
130 | test_must_be_empty list | |
f59baa50 NS |
131 | ' |
132 | ||
d3d7a421 KB |
133 | test_expect_success 'auto squash that matches 2 commits' ' |
134 | git reset --hard base && | |
135 | echo 4 >file4 && | |
136 | git add file4 && | |
137 | test_tick && | |
138 | git commit -m "first new commit" && | |
139 | echo 1 >file1 && | |
140 | git add -u && | |
141 | test_tick && | |
142 | git commit -m "squash! first" && | |
143 | git tag final-multisquash && | |
144 | test_tick && | |
145 | git rebase --autosquash -i HEAD~4 && | |
146 | git log --oneline >actual && | |
3fb0459b | 147 | test_line_count = 4 actual && |
d3d7a421 | 148 | git diff --exit-code final-multisquash && |
a781cd6f DL |
149 | echo 1 >expect && |
150 | git cat-file blob HEAD^^:file1 >actual && | |
151 | test_cmp expect actual && | |
152 | git cat-file commit HEAD^^ >commit && | |
153 | grep first commit >actual && | |
154 | test_line_count = 2 actual && | |
155 | git cat-file commit HEAD >commit && | |
156 | grep first commit >actual && | |
157 | test_line_count = 1 actual | |
d3d7a421 KB |
158 | ' |
159 | ||
160 | test_expect_success 'auto squash that matches a commit after the squash' ' | |
161 | git reset --hard base && | |
162 | echo 1 >file1 && | |
163 | git add -u && | |
164 | test_tick && | |
165 | git commit -m "squash! third" && | |
166 | echo 4 >file4 && | |
167 | git add file4 && | |
168 | test_tick && | |
169 | git commit -m "third commit" && | |
170 | git tag final-presquash && | |
171 | test_tick && | |
172 | git rebase --autosquash -i HEAD~4 && | |
173 | git log --oneline >actual && | |
3fb0459b | 174 | test_line_count = 5 actual && |
d3d7a421 | 175 | git diff --exit-code final-presquash && |
a781cd6f DL |
176 | echo 0 >expect && |
177 | git cat-file blob HEAD^^:file1 >actual && | |
178 | test_cmp expect actual && | |
179 | echo 1 >expect && | |
180 | git cat-file blob HEAD^:file1 >actual && | |
181 | test_cmp expect actual && | |
182 | git cat-file commit HEAD >commit && | |
183 | grep third commit >actual && | |
184 | test_line_count = 1 actual && | |
185 | git cat-file commit HEAD^ >commit && | |
186 | grep third commit >actual && | |
187 | test_line_count = 1 actual | |
d3d7a421 | 188 | ' |
68d5d03b KB |
189 | test_expect_success 'auto squash that matches a sha1' ' |
190 | git reset --hard base && | |
191 | echo 1 >file1 && | |
192 | git add -u && | |
193 | test_tick && | |
a781cd6f DL |
194 | oid=$(git rev-parse --short HEAD^) && |
195 | git commit -m "squash! $oid" && | |
68d5d03b KB |
196 | git tag final-shasquash && |
197 | test_tick && | |
198 | git rebase --autosquash -i HEAD^^^ && | |
199 | git log --oneline >actual && | |
3fb0459b | 200 | test_line_count = 3 actual && |
68d5d03b | 201 | git diff --exit-code final-shasquash && |
a781cd6f DL |
202 | echo 1 >expect && |
203 | git cat-file blob HEAD^:file1 >actual && | |
204 | test_cmp expect actual && | |
205 | git cat-file commit HEAD^ >commit && | |
206 | grep squash commit >actual && | |
207 | test_line_count = 1 actual | |
68d5d03b KB |
208 | ' |
209 | ||
210 | test_expect_success 'auto squash that matches longer sha1' ' | |
211 | git reset --hard base && | |
212 | echo 1 >file1 && | |
213 | git add -u && | |
214 | test_tick && | |
a781cd6f DL |
215 | oid=$(git rev-parse --short=11 HEAD^) && |
216 | git commit -m "squash! $oid" && | |
68d5d03b KB |
217 | git tag final-longshasquash && |
218 | test_tick && | |
219 | git rebase --autosquash -i HEAD^^^ && | |
220 | git log --oneline >actual && | |
3fb0459b | 221 | test_line_count = 3 actual && |
68d5d03b | 222 | git diff --exit-code final-longshasquash && |
a781cd6f DL |
223 | echo 1 >expect && |
224 | git cat-file blob HEAD^:file1 >actual && | |
225 | test_cmp expect actual && | |
226 | git cat-file commit HEAD^ >commit && | |
227 | grep squash commit >actual && | |
228 | test_line_count = 1 actual | |
68d5d03b | 229 | ' |
d3d7a421 | 230 | |
b1a6c0a9 PN |
231 | test_auto_commit_flags () { |
232 | git reset --hard base && | |
233 | echo 1 >file1 && | |
234 | git add -u && | |
235 | test_tick && | |
236 | git commit --$1 first-commit && | |
237 | git tag final-commit-$1 && | |
238 | test_tick && | |
239 | git rebase --autosquash -i HEAD^^^ && | |
240 | git log --oneline >actual && | |
3fb0459b | 241 | test_line_count = 3 actual && |
b1a6c0a9 | 242 | git diff --exit-code final-commit-$1 && |
a781cd6f DL |
243 | echo 1 >expect && |
244 | git cat-file blob HEAD^:file1 >actual && | |
245 | test_cmp expect actual && | |
246 | git cat-file commit HEAD^ >commit && | |
247 | grep first commit >actual && | |
248 | test_line_count = $2 actual | |
b1a6c0a9 PN |
249 | } |
250 | ||
251 | test_expect_success 'use commit --fixup' ' | |
252 | test_auto_commit_flags fixup 1 | |
253 | ' | |
254 | ||
7951bd30 PN |
255 | test_expect_success 'use commit --squash' ' |
256 | test_auto_commit_flags squash 2 | |
257 | ' | |
258 | ||
22c5b136 AP |
259 | test_auto_fixup_fixup () { |
260 | git reset --hard base && | |
261 | echo 1 >file1 && | |
262 | git add -u && | |
263 | test_tick && | |
264 | git commit -m "$1! first" && | |
265 | echo 2 >file1 && | |
266 | git add -u && | |
267 | test_tick && | |
268 | git commit -m "$1! $2! first" && | |
269 | git tag "final-$1-$2" && | |
270 | test_tick && | |
271 | ( | |
272 | set_cat_todo_editor && | |
273 | test_must_fail git rebase --autosquash -i HEAD^^^^ >actual && | |
a781cd6f DL |
274 | head=$(git rev-parse --short HEAD) && |
275 | parent1=$(git rev-parse --short HEAD^) && | |
276 | parent2=$(git rev-parse --short HEAD^^) && | |
277 | parent3=$(git rev-parse --short HEAD^^^) && | |
22c5b136 | 278 | cat >expected <<-EOF && |
a781cd6f DL |
279 | pick $parent3 first commit |
280 | $1 $parent1 $1! first | |
281 | $1 $head $1! $2! first | |
282 | pick $parent2 second commit | |
22c5b136 AP |
283 | EOF |
284 | test_cmp expected actual | |
285 | ) && | |
286 | git rebase --autosquash -i HEAD^^^^ && | |
287 | git log --oneline >actual && | |
288 | test_line_count = 3 actual | |
289 | git diff --exit-code "final-$1-$2" && | |
a781cd6f DL |
290 | echo 2 >expect && |
291 | git cat-file blob HEAD^:file1 >actual && | |
292 | test_cmp expect actual && | |
293 | git cat-file commit HEAD^ >commit && | |
294 | grep first commit >actual && | |
22c5b136 AP |
295 | if test "$1" = "fixup" |
296 | then | |
a781cd6f | 297 | test_line_count = 1 actual |
22c5b136 AP |
298 | elif test "$1" = "squash" |
299 | then | |
a781cd6f | 300 | test_line_count = 3 actual |
22c5b136 AP |
301 | else |
302 | false | |
303 | fi | |
304 | } | |
305 | ||
0d75bfe6 | 306 | test_expect_success C_LOCALE_OUTPUT 'fixup! fixup!' ' |
22c5b136 AP |
307 | test_auto_fixup_fixup fixup fixup |
308 | ' | |
309 | ||
0d75bfe6 | 310 | test_expect_success C_LOCALE_OUTPUT 'fixup! squash!' ' |
22c5b136 AP |
311 | test_auto_fixup_fixup fixup squash |
312 | ' | |
313 | ||
0d75bfe6 | 314 | test_expect_success C_LOCALE_OUTPUT 'squash! squash!' ' |
22c5b136 AP |
315 | test_auto_fixup_fixup squash squash |
316 | ' | |
317 | ||
0d75bfe6 | 318 | test_expect_success C_LOCALE_OUTPUT 'squash! fixup!' ' |
22c5b136 AP |
319 | test_auto_fixup_fixup squash fixup |
320 | ' | |
321 | ||
0d75bfe6 | 322 | test_expect_success C_LOCALE_OUTPUT 'autosquash with custom inst format' ' |
16cf51c7 MR |
323 | git reset --hard base && |
324 | git config --add rebase.instructionFormat "[%an @ %ar] %s" && | |
325 | echo 2 >file1 && | |
326 | git add -u && | |
327 | test_tick && | |
a781cd6f DL |
328 | oid=$(git rev-parse --short HEAD^) && |
329 | git commit -m "squash! $oid" && | |
16cf51c7 MR |
330 | echo 1 >file1 && |
331 | git add -u && | |
332 | test_tick && | |
a781cd6f DL |
333 | subject=$(git log -n 1 --format=%s HEAD~2) && |
334 | git commit -m "squash! $subject" && | |
16cf51c7 MR |
335 | git tag final-squash-instFmt && |
336 | test_tick && | |
337 | git rebase --autosquash -i HEAD~4 && | |
338 | git log --oneline >actual && | |
339 | test_line_count = 3 actual && | |
340 | git diff --exit-code final-squash-instFmt && | |
a781cd6f DL |
341 | echo 1 >expect && |
342 | git cat-file blob HEAD^:file1 >actual && | |
343 | test_cmp expect actual && | |
344 | git cat-file commit HEAD^ >commit && | |
345 | grep squash commit >actual && | |
346 | test_line_count = 2 actual | |
16cf51c7 MR |
347 | ' |
348 | ||
4e7524e0 JS |
349 | test_expect_success 'autosquash with empty custom instructionFormat' ' |
350 | git reset --hard base && | |
351 | test_commit empty-instructionFormat-test && | |
352 | ( | |
353 | set_cat_todo_editor && | |
354 | test_must_fail git -c rebase.instructionFormat= \ | |
f927ae6c | 355 | rebase --autosquash --force-rebase -i HEAD^ >actual && |
4e7524e0 JS |
356 | git log -1 --format="pick %h %s" >expect && |
357 | test_cmp expect actual | |
358 | ) | |
359 | ' | |
360 | ||
c94e963b JS |
361 | set_backup_editor () { |
362 | write_script backup-editor.sh <<-\EOF | |
363 | cp "$1" .git/backup-"$(basename "$1")" | |
364 | EOF | |
365 | test_set_editor "$PWD/backup-editor.sh" | |
366 | } | |
367 | ||
c44a4c65 | 368 | test_expect_success 'autosquash with multiple empty patches' ' |
c94e963b JS |
369 | test_tick && |
370 | git commit --allow-empty -m "empty" && | |
371 | test_tick && | |
372 | git commit --allow-empty -m "empty2" && | |
373 | test_tick && | |
374 | >fixup && | |
375 | git add fixup && | |
376 | git commit --fixup HEAD^^ && | |
377 | ( | |
378 | set_backup_editor && | |
379 | GIT_USE_REBASE_HELPER=false \ | |
380 | git rebase -i --force-rebase --autosquash HEAD~4 && | |
381 | grep empty2 .git/backup-git-rebase-todo | |
382 | ) | |
383 | ' | |
384 | ||
cbcd2cbd JS |
385 | test_expect_success 'extra spaces after fixup!' ' |
386 | base=$(git rev-parse HEAD) && | |
387 | test_commit to-fixup && | |
388 | git commit --allow-empty -m "fixup! to-fixup" && | |
389 | git rebase -i --autosquash --keep-empty HEAD~2 && | |
390 | parent=$(git rev-parse HEAD^) && | |
391 | test $base = $parent | |
392 | ' | |
393 | ||
b174ae7d JS |
394 | test_expect_success 'wrapped original subject' ' |
395 | if test -d .git/rebase-merge; then git rebase --abort; fi && | |
396 | base=$(git rev-parse HEAD) && | |
397 | echo "wrapped subject" >wrapped && | |
398 | git add wrapped && | |
399 | test_tick && | |
400 | git commit --allow-empty -m "$(printf "To\nfixup")" && | |
401 | test_tick && | |
402 | git commit --allow-empty -m "fixup! To fixup" && | |
403 | git rebase -i --autosquash --keep-empty HEAD~2 && | |
404 | parent=$(git rev-parse HEAD^) && | |
405 | test $base = $parent | |
406 | ' | |
407 | ||
10d2f354 | 408 | test_expect_success 'abort last squash' ' |
2f3eb68f JS |
409 | test_when_finished "test_might_fail git rebase --abort" && |
410 | test_when_finished "git checkout master" && | |
411 | ||
412 | git checkout -b some-squashes && | |
413 | git commit --allow-empty -m first && | |
414 | git commit --allow-empty --squash HEAD && | |
415 | git commit --allow-empty -m second && | |
416 | git commit --allow-empty --squash HEAD && | |
417 | ||
418 | test_must_fail git -c core.editor="grep -q ^pick" \ | |
419 | rebase -ki --autosquash HEAD~4 && | |
420 | : do not finish the squash, but resolve it manually && | |
421 | git commit --allow-empty --amend -m edited-first && | |
422 | git rebase --skip && | |
423 | git show >actual && | |
424 | ! grep first actual | |
425 | ' | |
426 | ||
02471e7e JS |
427 | test_expect_success 'fixup a fixup' ' |
428 | echo 0to-fixup >file0 && | |
429 | test_tick && | |
430 | git commit -m "to-fixup" file0 && | |
431 | test_tick && | |
432 | git commit --squash HEAD -m X --allow-empty && | |
433 | test_tick && | |
434 | git commit --squash HEAD^ -m Y --allow-empty && | |
435 | test_tick && | |
436 | git commit -m "squash! $(git rev-parse HEAD^)" -m Z --allow-empty && | |
437 | test_tick && | |
438 | git commit -m "squash! $(git rev-parse HEAD^^)" -m W --allow-empty && | |
439 | git rebase -ki --autosquash HEAD~5 && | |
440 | test XZWY = $(git show | tr -cd W-Z) | |
441 | ' | |
442 | ||
f59baa50 | 443 | test_done |