3 test_description
='git am running'
7 test_expect_success
'setup: messages' '
11 Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy
12 eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
13 voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
14 kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
15 ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
16 tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
17 vero eos et accusam et justo duo dolores et ea rebum.
20 qz_to_tab_space <<-\EOF >>msg &&
21 QDuis autem vel eum iriure dolor in hendrerit in vulputate velit
22 Qesse molestie consequat, vel illum dolore eu feugiat nulla facilisis
23 Qat vero eros et accumsan et iusto odio dignissim qui blandit
24 Qpraesent luptatum zzril delenit augue duis dolore te feugait nulla
29 Lorem ipsum dolor sit amet,
30 consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
31 laoreet dolore magna aliquam erat volutpat.
37 Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
38 lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
39 dolor in hendrerit in vulputate velit esse molestie consequat, vel illum
40 dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio
41 dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te
42 feugait nulla facilisi.
45 cat >failmail <<-\EOF &&
46 From foo@example.com Fri May 23 10:43:49 2008
49 Subject: Re: [RFC/PATCH] git-foo.sh
50 Date: Fri, 23 May 2008 05:23:42 +0200
52 Sometimes we have to find out that there'\''s nothing left.
57 From MAILER-DAEMON Fri May 23 10:43:49 2008
58 Date: 23 May 2008 05:23:42 +0200
59 From: Mail System Internal Data <MAILER-DAEMON@example.com>
60 Subject: DON'\''T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
61 Message-ID: <foo-0001@example.com>
63 This text is part of the internal format of your mail folder, and is not
64 a real message. It is created automatically by the mail system software.
65 If deleted, important folder data will be lost, and it will be re-created
66 with the data reset to initial values.
70 signoff="Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
73 test_expect_success setup
'
77 git commit -m first &&
83 git commit -s -F msg &&
86 git format-patch --stdout first >patch1 &&
88 echo "Message-Id: <1226501681-24923-1-git-send-email-bda@mnsspb.ru>" &&
89 echo "X-Fake-Field: Line One" &&
90 echo "X-Fake-Field: Line Two" &&
91 echo "X-Fake-Field: Line Three" &&
92 git format-patch --stdout first | sed -e "1d"
95 echo "X-Fake-Field: Line One" &&
96 echo "X-Fake-Field: Line Two" &&
97 echo "X-Fake-Field: Line Three" &&
98 git format-patch --stdout first | sed -e "1d"
99 } | append_cr >patch1-crlf.eml &&
102 echo "X-Fake-Field: Line One" &&
103 echo "X-Fake-Field: Line Two" &&
104 echo "X-Fake-Field: Line Three" &&
105 git format-patch --stdout first | sed -e "1d"
108 sed -n -e "3,\$p" msg >file &&
111 git commit -m third &&
113 git format-patch --stdout first >patch2 &&
115 git checkout -b lorem &&
116 sed -n -e "11,\$p" msg >file &&
117 head -n 9 msg >>file &&
119 git commit -a -m "moved stuff" &&
121 echo goodbye >another &&
124 git commit -m "added another file" &&
126 git format-patch --stdout master >lorem-move.patch &&
127 git format-patch --no-prefix --stdout master >lorem-zero.patch &&
129 git checkout -b rename &&
130 git mv file renamed &&
131 git commit -m "renamed a file" &&
133 git format-patch -M --stdout lorem >rename.patch &&
135 git reset --soft lorem^ &&
136 git commit -m "renamed a file and added another" &&
138 git format-patch -M --stdout lorem^ >rename-add.patch &&
141 sane_unset test_tick &&
145 test_expect_success
'am applies patch correctly' '
146 rm -fr .git/rebase-apply &&
148 git checkout first &&
151 test_path_is_missing .git/rebase-apply &&
152 git diff --exit-code second &&
153 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
154 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
157 test_expect_success
'am fails if index is dirty' '
158 test_when_finished "rm -f dirtyfile" &&
159 rm -fr .git/rebase-apply &&
161 git checkout first &&
162 echo dirtyfile >dirtyfile &&
164 test_must_fail git am patch1 &&
165 test_path_is_dir .git/rebase-apply &&
166 test_cmp_rev first HEAD
169 test_expect_success
'am applies patch e-mail not in a mbox' '
170 rm -fr .git/rebase-apply &&
172 git checkout first &&
174 test_path_is_missing .git/rebase-apply &&
175 git diff --exit-code second &&
176 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
177 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
180 test_expect_success
'am applies patch e-mail not in a mbox with CRLF' '
181 rm -fr .git/rebase-apply &&
183 git checkout first &&
184 git am patch1-crlf.eml &&
185 test_path_is_missing .git/rebase-apply &&
186 git diff --exit-code second &&
187 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
188 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
191 test_expect_success
'am applies patch e-mail with preceding whitespace' '
192 rm -fr .git/rebase-apply &&
194 git checkout first &&
195 git am patch1-ws.eml &&
196 test_path_is_missing .git/rebase-apply &&
197 git diff --exit-code second &&
198 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
199 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
202 test_expect_success
'am with applypatch-msg hook' '
203 test_when_finished "rm -f .git/hooks/applypatch-msg" &&
204 rm -fr .git/rebase-apply &&
206 git checkout first &&
207 mkdir -p .git/hooks &&
208 write_script .git/hooks/applypatch-msg <<-\EOF &&
209 cat "$1" >actual-msg &&
210 echo hook-message >"$1"
213 test_path_is_missing .git/rebase-apply &&
214 git diff --exit-code second &&
215 echo hook-message >expected &&
216 git log -1 --format=format:%B >actual &&
217 test_cmp expected actual &&
218 git log -1 --format=format:%B second >expected &&
219 test_cmp expected actual-msg
222 test_expect_success
'am with failing applypatch-msg hook' '
223 test_when_finished "rm -f .git/hooks/applypatch-msg" &&
224 rm -fr .git/rebase-apply &&
226 git checkout first &&
227 mkdir -p .git/hooks &&
228 write_script .git/hooks/applypatch-msg <<-\EOF &&
231 test_must_fail git am patch1 &&
232 test_path_is_dir .git/rebase-apply &&
233 git diff --exit-code first &&
234 test_cmp_rev first HEAD
237 test_expect_success
'am with pre-applypatch hook' '
238 test_when_finished "rm -f .git/hooks/pre-applypatch" &&
239 rm -fr .git/rebase-apply &&
241 git checkout first &&
242 mkdir -p .git/hooks &&
243 write_script .git/hooks/pre-applypatch <<-\EOF &&
244 git diff first >diff.actual
248 test_path_is_missing .git/rebase-apply &&
249 git diff --exit-code second &&
250 test_cmp_rev second HEAD &&
251 git diff first..second >diff.expected &&
252 test_cmp diff.expected diff.actual
255 test_expect_success
'am with failing pre-applypatch hook' '
256 test_when_finished "rm -f .git/hooks/pre-applypatch" &&
257 rm -fr .git/rebase-apply &&
259 git checkout first &&
260 mkdir -p .git/hooks &&
261 write_script .git/hooks/pre-applypatch <<-\EOF &&
264 test_must_fail git am patch1 &&
265 test_path_is_dir .git/rebase-apply &&
266 git diff --exit-code second &&
267 test_cmp_rev first HEAD
270 test_expect_success
'setup: new author and committer' '
271 GIT_AUTHOR_NAME="Another Thor" &&
272 GIT_AUTHOR_EMAIL="a.thor@example.com" &&
273 GIT_COMMITTER_NAME="Co M Miter" &&
274 GIT_COMMITTER_EMAIL="c.miter@example.com" &&
275 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
279 a
=$
(git cat-file commit
"$2" |
grep "^$1 ") &&
280 b
=$
(git cat-file commit
"$3" |
grep "^$1 ") &&
284 test_expect_success
'am changes committer and keeps author' '
286 rm -fr .git/rebase-apply &&
288 git checkout first &&
290 test_path_is_missing .git/rebase-apply &&
291 test "$(git rev-parse master^^)" = "$(git rev-parse HEAD^^)" &&
292 git diff --exit-code master..HEAD &&
293 git diff --exit-code master^..HEAD^ &&
294 compare author master HEAD &&
295 compare author master^ HEAD^ &&
296 test "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" = \
297 "$(git log -1 --pretty=format:"%cn <%ce>" HEAD)"
300 test_expect_success
'am --signoff adds Signed-off-by: line' '
301 rm -fr .git/rebase-apply &&
303 git checkout -b master2 first &&
304 git am --signoff <patch2 &&
305 printf "%s\n" "$signoff" >expected &&
306 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected &&
307 git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
308 test_cmp expected actual &&
309 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected &&
310 git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
311 test_cmp expected actual
314 test_expect_success
'am stays in branch' '
315 echo refs/heads/master2 >expected &&
316 git symbolic-ref HEAD >actual &&
317 test_cmp expected actual
320 test_expect_success
'am --signoff does not add Signed-off-by: line if already there' '
321 git format-patch --stdout HEAD^ >patch3 &&
322 sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2] [foo," patch3 >patch4 &&
323 rm -fr .git/rebase-apply &&
325 git checkout HEAD^ &&
326 git am --signoff patch4 &&
327 git cat-file commit HEAD >actual &&
328 test $(grep -c "^Signed-off-by:" actual) -eq 1
331 test_expect_success
'am without --keep removes Re: and [PATCH] stuff' '
332 git rev-parse HEAD >expected &&
333 git rev-parse master2 >actual &&
334 test_cmp expected actual
337 test_expect_success
'am --keep really keeps the subject' '
338 rm -fr .git/rebase-apply &&
340 git checkout HEAD^ &&
341 git am --keep patch4 &&
342 test_path_is_missing .git/rebase-apply &&
343 git cat-file commit HEAD >actual &&
344 grep "Re: Re: Re: \[PATCH 1/5 v2\] \[foo\] third" actual
347 test_expect_success
'am --keep-non-patch really keeps the non-patch part' '
348 rm -fr .git/rebase-apply &&
350 git checkout HEAD^ &&
351 git am --keep-non-patch patch4 &&
352 test_path_is_missing .git/rebase-apply &&
353 git cat-file commit HEAD >actual &&
354 grep "^\[foo\] third" actual
357 test_expect_success
'setup am -3' '
358 rm -fr .git/rebase-apply &&
360 git checkout -b base3way master2 &&
361 sed -n -e "3,\$p" msg >file &&
362 head -n 9 msg >>file &&
365 git commit -m "copied stuff"
368 test_expect_success
'am -3 falls back to 3-way merge' '
369 rm -fr .git/rebase-apply &&
371 git checkout -b lorem2 base3way &&
372 git am -3 lorem-move.patch &&
373 test_path_is_missing .git/rebase-apply &&
374 git diff --exit-code lorem
377 test_expect_success
'am -3 -p0 can read --no-prefix patch' '
378 rm -fr .git/rebase-apply &&
380 git checkout -b lorem3 base3way &&
381 git am -3 -p0 lorem-zero.patch &&
382 test_path_is_missing .git/rebase-apply &&
383 git diff --exit-code lorem
386 test_expect_success
'am with config am.threeWay falls back to 3-way merge' '
387 rm -fr .git/rebase-apply &&
389 git checkout -b lorem4 base3way &&
390 test_config am.threeWay 1 &&
391 git am lorem-move.patch &&
392 test_path_is_missing .git/rebase-apply &&
393 git diff --exit-code lorem
396 test_expect_success
'am with config am.threeWay overridden by --no-3way' '
397 rm -fr .git/rebase-apply &&
399 git checkout -b lorem5 base3way &&
400 test_config am.threeWay 1 &&
401 test_must_fail git am --no-3way lorem-move.patch &&
402 test_path_is_dir .git/rebase-apply
405 test_expect_success
'am can rename a file' '
406 grep "^rename from" rename.patch &&
407 rm -fr .git/rebase-apply &&
409 git checkout lorem^0 &&
410 git am rename.patch &&
411 test_path_is_missing .git/rebase-apply &&
412 git update-index --refresh &&
413 git diff --exit-code rename
416 test_expect_success
'am -3 can rename a file' '
417 grep "^rename from" rename.patch &&
418 rm -fr .git/rebase-apply &&
420 git checkout lorem^0 &&
421 git am -3 rename.patch &&
422 test_path_is_missing .git/rebase-apply &&
423 git update-index --refresh &&
424 git diff --exit-code rename
427 test_expect_success
'am -3 can rename a file after falling back to 3-way merge' '
428 grep "^rename from" rename-add.patch &&
429 rm -fr .git/rebase-apply &&
431 git checkout lorem^0 &&
432 git am -3 rename-add.patch &&
433 test_path_is_missing .git/rebase-apply &&
434 git update-index --refresh &&
435 git diff --exit-code rename
438 test_expect_success
'am -3 -q is quiet' '
439 rm -fr .git/rebase-apply &&
440 git checkout -f lorem2 &&
441 git reset base3way --hard &&
442 git am -3 -q lorem-move.patch >output.out 2>&1 &&
446 test_expect_success
'am pauses on conflict' '
447 rm -fr .git/rebase-apply &&
449 git checkout lorem2^^ &&
450 test_must_fail git am lorem-move.patch &&
451 test -d .git/rebase-apply
454 test_expect_success
'am --skip works' '
455 echo goodbye >expected &&
457 test_path_is_missing .git/rebase-apply &&
458 git diff --exit-code lorem2^^ -- file &&
459 test_cmp expected another
462 test_expect_success
'am --abort removes a stray directory' '
463 mkdir .git/rebase-apply &&
465 test_path_is_missing .git/rebase-apply
468 test_expect_success
'am refuses patches when paused' '
469 rm -fr .git/rebase-apply &&
471 git checkout lorem2^^ &&
473 test_must_fail git am lorem-move.patch &&
474 test_path_is_dir .git/rebase-apply &&
475 test_cmp_rev lorem2^^ HEAD &&
477 test_must_fail git am <lorem-move.patch &&
478 test_path_is_dir .git/rebase-apply &&
479 test_cmp_rev lorem2^^ HEAD
482 test_expect_success
'am --resolved works' '
483 echo goodbye >expected &&
484 rm -fr .git/rebase-apply &&
486 git checkout lorem2^^ &&
487 test_must_fail git am lorem-move.patch &&
488 test -d .git/rebase-apply &&
489 echo resolved >>file &&
492 test_path_is_missing .git/rebase-apply &&
493 test_cmp expected another
496 test_expect_success
'am --resolved fails if index has no changes' '
497 rm -fr .git/rebase-apply &&
499 git checkout lorem2^^ &&
500 test_must_fail git am lorem-move.patch &&
501 test_path_is_dir .git/rebase-apply &&
502 test_cmp_rev lorem2^^ HEAD &&
503 test_must_fail git am --resolved &&
504 test_path_is_dir .git/rebase-apply &&
505 test_cmp_rev lorem2^^ HEAD
508 test_expect_success
'am --resolved fails if index has unmerged entries' '
509 rm -fr .git/rebase-apply &&
511 git checkout second &&
512 test_must_fail git am -3 lorem-move.patch &&
513 test_path_is_dir .git/rebase-apply &&
514 test_cmp_rev second HEAD &&
515 test_must_fail git am --resolved >err &&
516 test_path_is_dir .git/rebase-apply &&
517 test_cmp_rev second HEAD &&
518 test_i18ngrep "still have unmerged paths" err
521 test_expect_success
'am takes patches from a Pine mailbox' '
522 rm -fr .git/rebase-apply &&
524 git checkout first &&
525 cat pine patch1 | git am &&
526 test_path_is_missing .git/rebase-apply &&
527 git diff --exit-code master^..HEAD
530 test_expect_success
'am fails on mail without patch' '
531 rm -fr .git/rebase-apply &&
533 test_must_fail git am <failmail &&
535 test_path_is_missing .git/rebase-apply
538 test_expect_success
'am fails on empty patch' '
539 rm -fr .git/rebase-apply &&
541 echo "---" >>failmail &&
542 test_must_fail git am <failmail &&
544 test_path_is_missing .git/rebase-apply
547 test_expect_success
'am works from stdin in subdirectory' '
549 rm -fr .git/rebase-apply &&
551 git checkout first &&
557 git diff --exit-code second
560 test_expect_success
'am works from file (relative path given) in subdirectory' '
562 rm -fr .git/rebase-apply &&
564 git checkout first &&
570 git diff --exit-code second
573 test_expect_success
'am works from file (absolute path given) in subdirectory' '
575 rm -fr .git/rebase-apply &&
577 git checkout first &&
584 git diff --exit-code second
587 test_expect_success
'am --committer-date-is-author-date' '
588 rm -fr .git/rebase-apply &&
590 git checkout first &&
592 git am --committer-date-is-author-date patch1 &&
593 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
594 sed -ne "/^author /s/.*> //p" head1 >at &&
595 sed -ne "/^committer /s/.*> //p" head1 >ct &&
599 test_expect_success
'am without --committer-date-is-author-date' '
600 rm -fr .git/rebase-apply &&
602 git checkout first &&
605 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
606 sed -ne "/^author /s/.*> //p" head1 >at &&
607 sed -ne "/^committer /s/.*> //p" head1 >ct &&
611 # This checks for +0000 because TZ is set to UTC and that should
612 # show up when the current time is used. The date in message is set
613 # by test_tick that uses -0700 timezone; if this feature does not
614 # work, we will see that instead of +0000.
615 test_expect_success
'am --ignore-date' '
616 rm -fr .git/rebase-apply &&
618 git checkout first &&
620 git am --ignore-date patch1 &&
621 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
622 sed -ne "/^author /s/.*> //p" head1 >at &&
626 test_expect_success
'am into an unborn branch' '
627 git rev-parse first^{tree} >expected &&
628 rm -fr .git/rebase-apply &&
632 git format-patch --numbered-files -o subdir -1 first &&
640 git rev-parse HEAD^{tree} >../actual
642 test_cmp expected actual
645 test_expect_success
'am newline in subject' '
646 rm -fr .git/rebase-apply &&
648 git checkout first &&
650 sed -e "s/second/second \\\n foo/" patch1 >patchnl &&
651 git am <patchnl >output.out 2>&1 &&
652 test_i18ngrep "^Applying: second \\\n foo$" output.out
655 test_expect_success
'am -q is quiet' '
656 rm -fr .git/rebase-apply &&
658 git checkout first &&
660 git am -q <patch1 >output.out 2>&1 &&
664 test_expect_success
'am empty-file does not infloop' '
665 rm -fr .git/rebase-apply &&
669 test_must_fail git am empty-file 2>actual &&
670 echo Patch format detection failed. >expected &&
671 test_i18ncmp expected actual
674 test_expect_success
'am --message-id really adds the message id' '
675 rm -fr .git/rebase-apply &&
677 git checkout HEAD^ &&
678 git am --message-id patch1.eml &&
679 test_path_is_missing .git/rebase-apply &&
680 git cat-file commit HEAD | tail -n1 >actual &&
681 grep Message-Id patch1.eml >expected &&
682 test_cmp expected actual
685 test_expect_success
'am.messageid really adds the message id' '
686 rm -fr .git/rebase-apply &&
688 git checkout HEAD^ &&
689 test_config am.messageid true &&
691 test_path_is_missing .git/rebase-apply &&
692 git cat-file commit HEAD | tail -n1 >actual &&
693 grep Message-Id patch1.eml >expected &&
694 test_cmp expected actual
697 test_expect_success
'am --message-id -s signs off after the message id' '
698 rm -fr .git/rebase-apply &&
700 git checkout HEAD^ &&
701 git am -s --message-id patch1.eml &&
702 test_path_is_missing .git/rebase-apply &&
703 git cat-file commit HEAD | tail -n2 | head -n1 >actual &&
704 grep Message-Id patch1.eml >expected &&
705 test_cmp expected actual