3 test_description
='auto squash'
7 .
"$TEST_DIRECTORY"/lib-rebase.sh
9 test_expect_success setup
'
13 git commit -m "initial commit" &&
18 git commit -m "first commit" &&
19 git tag first-commit &&
23 git commit -m "second commit" &&
35 git
reset --hard base
&&
39 git commit
-m "fixup! first" &&
43 git rebase
$2 -i HEAD^^^
&&
44 git log
--oneline >actual
&&
45 if test -n "$no_squash"
47 test_line_count
= 4 actual
49 test_line_count
= 3 actual
&&
50 git
diff --exit-code $1 &&
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
60 test_expect_success
'auto fixup (option)' '
61 test_auto_fixup final-fixup-option --autosquash
64 test_expect_success
'auto fixup (config)' '
65 git config rebase.autosquash true &&
66 test_auto_fixup final-fixup-config-true &&
67 test_auto_fixup ! fixup-config-true-no --no-autosquash &&
68 git config rebase.autosquash false &&
69 test_auto_fixup ! final-fixup-config-false
80 git
reset --hard base
&&
84 git commit
-m "squash! first" &&
88 git rebase
$2 -i HEAD^^^
&&
89 git log
--oneline >actual
&&
90 if test -n "$no_squash"
92 test_line_count
= 4 actual
94 test_line_count
= 3 actual
&&
95 git
diff --exit-code $1 &&
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
105 test_expect_success
'auto squash (option)' '
106 test_auto_squash final-squash --autosquash
109 test_expect_success
'auto squash (config)' '
110 git config rebase.autosquash true &&
111 test_auto_squash final-squash-config-true &&
112 test_auto_squash ! squash-config-true-no --no-autosquash &&
113 git config rebase.autosquash false &&
114 test_auto_squash ! final-squash-config-false
117 test_expect_success
'misspelled auto squash' '
118 git reset --hard base &&
122 git commit -m "squash! forst" &&
123 git tag final-missquash &&
125 git rebase --autosquash -i HEAD^^^ &&
126 git log --oneline >actual &&
127 test_line_count = 4 actual &&
128 git diff --exit-code final-missquash &&
129 git rev-list final-missquash...HEAD >list &&
130 test_must_be_empty list
133 test_expect_success
'auto squash that matches 2 commits' '
134 git reset --hard base &&
138 git commit -m "first new commit" &&
142 git commit -m "squash! first" &&
143 git tag final-multisquash &&
145 git rebase --autosquash -i HEAD~4 &&
146 git log --oneline >actual &&
147 test_line_count = 4 actual &&
148 git diff --exit-code final-multisquash &&
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
160 test_expect_success
'auto squash that matches a commit after the squash' '
161 git reset --hard base &&
165 git commit -m "squash! third" &&
169 git commit -m "third commit" &&
170 git tag final-presquash &&
172 git rebase --autosquash -i HEAD~4 &&
173 git log --oneline >actual &&
174 test_line_count = 5 actual &&
175 git diff --exit-code final-presquash &&
177 git cat-file blob HEAD^^:file1 >actual &&
178 test_cmp expect actual &&
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
189 test_expect_success
'auto squash that matches a sha1' '
190 git reset --hard base &&
194 oid=$(git rev-parse --short HEAD^) &&
195 git commit -m "squash! $oid" &&
196 git tag final-shasquash &&
198 git rebase --autosquash -i HEAD^^^ &&
199 git log --oneline >actual &&
200 test_line_count = 3 actual &&
201 git diff --exit-code final-shasquash &&
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
210 test_expect_success
'auto squash that matches longer sha1' '
211 git reset --hard base &&
215 oid=$(git rev-parse --short=11 HEAD^) &&
216 git commit -m "squash! $oid" &&
217 git tag final-longshasquash &&
219 git rebase --autosquash -i HEAD^^^ &&
220 git log --oneline >actual &&
221 test_line_count = 3 actual &&
222 git diff --exit-code final-longshasquash &&
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
231 test_auto_commit_flags
() {
232 git
reset --hard base
&&
236 git commit
--$1 first-commit
&&
237 git tag final-commit-
$1 &&
239 git rebase
--autosquash -i HEAD^^^
&&
240 git log
--oneline >actual
&&
241 test_line_count
= 3 actual
&&
242 git
diff --exit-code final-commit-
$1 &&
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
251 test_expect_success
'use commit --fixup' '
252 test_auto_commit_flags fixup 1
255 test_expect_success
'use commit --squash' '
256 test_auto_commit_flags squash 2
259 test_auto_fixup_fixup
() {
260 git
reset --hard base
&&
264 git commit
-m "$1! first" &&
268 git commit
-m "$1! $2! first" &&
269 git tag
"final-$1-$2" &&
272 set_cat_todo_editor
&&
273 test_must_fail git rebase
--autosquash -i HEAD^^^^
>actual
&&
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^^^
) &&
278 cat >expected
<<-EOF &&
279 pick $parent3 first commit
280 $1 $parent1 $1! first
281 $1 $head $1! $2! first
282 pick $parent2 second commit
284 test_cmp expected actual
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" &&
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
&&
295 if test "$1" = "fixup"
297 test_line_count
= 1 actual
298 elif test "$1" = "squash"
300 test_line_count
= 3 actual
306 test_expect_success C_LOCALE_OUTPUT
'fixup! fixup!' '
307 test_auto_fixup_fixup fixup fixup
310 test_expect_success C_LOCALE_OUTPUT
'fixup! squash!' '
311 test_auto_fixup_fixup fixup squash
314 test_expect_success C_LOCALE_OUTPUT
'squash! squash!' '
315 test_auto_fixup_fixup squash squash
318 test_expect_success C_LOCALE_OUTPUT
'squash! fixup!' '
319 test_auto_fixup_fixup squash fixup
322 test_expect_success C_LOCALE_OUTPUT
'autosquash with custom inst format' '
323 git reset --hard base &&
324 git config --add rebase.instructionFormat "[%an @ %ar] %s" &&
328 oid=$(git rev-parse --short HEAD^) &&
329 git commit -m "squash! $oid" &&
333 subject=$(git log -n 1 --format=%s HEAD~2) &&
334 git commit -m "squash! $subject" &&
335 git tag final-squash-instFmt &&
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 &&
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
349 test_expect_success
'autosquash with empty custom instructionFormat' '
350 git reset --hard base &&
351 test_commit empty-instructionFormat-test &&
353 set_cat_todo_editor &&
354 test_must_fail git -c rebase.instructionFormat= \
355 rebase --autosquash --force-rebase -i HEAD^ >actual &&
356 git log -1 --format="pick %h %s" >expect &&
357 test_cmp expect actual
361 set_backup_editor
() {
362 write_script backup-editor.sh
<<-\EOF
363 cp "$1" .git/backup-"$(basename "$1")"
365 test_set_editor "$PWD/backup-editor.sh"
368 test_expect_success 'autosquash with multiple empty patches' '
370 git commit --allow-empty -m "empty" &&
372 git commit --allow-empty -m "empty2" &&
376 git commit --fixup HEAD^^ &&
379 GIT_USE_REBASE_HELPER=false \
380 git rebase -i --force-rebase --autosquash HEAD~4 &&
381 grep empty2 .git/backup-git-rebase-todo
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^) &&
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 &&
400 git commit --allow-empty -m "$(printf "To\nfixup")" &&
402 git commit --allow-empty -m "fixup! To fixup" &&
403 git rebase -i --autosquash --keep-empty HEAD~2 &&
404 parent=$(git rev-parse HEAD^) &&
408 test_expect_success 'abort last squash' '
409 test_when_finished "test_might_fail git rebase --abort" &&
410 test_when_finished "git checkout master" &&
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 &&
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 &&
427 test_expect_success 'fixup a fixup' '
428 echo 0to-fixup >file0 &&
430 git commit -m "to-fixup" file0 &&
432 git commit --squash HEAD -m X --allow-empty &&
434 git commit --squash HEAD^ -m Y --allow-empty &&
436 git commit -m "squash! $(git rev-parse HEAD^)" -m Z --allow-empty &&
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)