]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4150-am.sh
Merge branch 'ea/blame-use-oideq'
[thirdparty/git.git] / t / t4150-am.sh
CommitLineData
d3a7b8f5
SB
1#!/bin/sh
2
3test_description='git am running'
4
5. ./test-lib.sh
6
800f1104
JN
7test_expect_success 'setup: messages' '
8 cat >msg <<-\EOF &&
9 second
10
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.
18
19 EOF
250b3c6c 20 qz_to_tab_space <<-\EOF >>msg &&
800f1104
JN
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
25 Qfacilisi.
26 EOF
27 cat >>msg <<-\EOF &&
28
29 Lorem ipsum dolor sit amet,
30 consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
31 laoreet dolore magna aliquam erat volutpat.
32
33 git
34 ---
35 +++
36
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.
735285b4
PW
43
44 Reported-by: A N Other <a.n.other@example.com>
800f1104
JN
45 EOF
46
47 cat >failmail <<-\EOF &&
48 From foo@example.com Fri May 23 10:43:49 2008
49 From: foo@example.com
50 To: bar@example.com
51 Subject: Re: [RFC/PATCH] git-foo.sh
52 Date: Fri, 23 May 2008 05:23:42 +0200
53
54 Sometimes we have to find out that there'\''s nothing left.
55
56 EOF
57
58 cat >pine <<-\EOF &&
59 From MAILER-DAEMON Fri May 23 10:43:49 2008
60 Date: 23 May 2008 05:23:42 +0200
61 From: Mail System Internal Data <MAILER-DAEMON@example.com>
62 Subject: DON'\''T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
63 Message-ID: <foo-0001@example.com>
64
65 This text is part of the internal format of your mail folder, and is not
66 a real message. It is created automatically by the mail system software.
67 If deleted, important folder data will be lost, and it will be re-created
68 with the data reset to initial values.
69
70 EOF
71
b7446fcf
AR
72 cat >msg-without-scissors-line <<-\EOF &&
73 Test that git-am --scissors cuts at the scissors line
bf72ac17
PT
74
75 This line should be included in the commit message.
76 EOF
77
b7446fcf
AR
78 printf "Subject: " >subject-prefix &&
79
e041d078 80 cat - subject-prefix msg-without-scissors-line >msg-with-scissors-line <<-\EOF
bf72ac17
PT
81 This line should not be included in the commit message with --scissors enabled.
82
83 - - >8 - - remove everything above this line - - >8 - -
84
85 EOF
800f1104 86'
d3a7b8f5
SB
87
88test_expect_success setup '
89 echo hello >file &&
90 git add file &&
91 test_tick &&
92 git commit -m first &&
93 git tag first &&
800f1104 94
d3a7b8f5
SB
95 echo world >>file &&
96 git add file &&
97 test_tick &&
735285b4 98 git commit -F msg &&
d3a7b8f5 99 git tag second &&
800f1104 100
d3a7b8f5 101 git format-patch --stdout first >patch1 &&
0fcb2caf 102 {
a078f732 103 echo "Message-Id: <1226501681-24923-1-git-send-email-bda@mnsspb.ru>" &&
0fcb2caf
JH
104 echo "X-Fake-Field: Line One" &&
105 echo "X-Fake-Field: Line Two" &&
106 echo "X-Fake-Field: Line Three" &&
107 git format-patch --stdout first | sed -e "1d"
108 } > patch1.eml &&
e3f67d30
SB
109 {
110 echo "X-Fake-Field: Line One" &&
111 echo "X-Fake-Field: Line Two" &&
112 echo "X-Fake-Field: Line Three" &&
113 git format-patch --stdout first | sed -e "1d"
114 } | append_cr >patch1-crlf.eml &&
0e8341f2
DB
115 {
116 printf "%255s\\n" ""
117 echo "X-Fake-Field: Line One" &&
118 echo "X-Fake-Field: Line Two" &&
119 echo "X-Fake-Field: Line Three" &&
120 git format-patch --stdout first | sed -e "1d"
121 } > patch1-ws.eml &&
1daaddd1
PT
122 {
123 sed -ne "1p" msg &&
124 echo &&
125 echo "From: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" &&
126 echo "Date: $GIT_AUTHOR_DATE" &&
127 echo &&
128 sed -e "1,2d" msg &&
1daaddd1
PT
129 echo "---" &&
130 git diff-tree --no-commit-id --stat -p second
131 } >patch1-stgit.eml &&
fcceef4e
PT
132 mkdir stgit-series &&
133 cp patch1-stgit.eml stgit-series/patch &&
134 {
135 echo "# This series applies on GIT commit $(git rev-parse first)" &&
136 echo "patch"
137 } >stgit-series/series &&
e9dfe253
PT
138 {
139 echo "# HG changeset patch" &&
140 echo "# User $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" &&
141 echo "# Date $test_tick 25200" &&
142 echo "# $(git show --pretty="%aD" -s second)" &&
8125a58b 143 echo "# Node ID $ZERO_OID" &&
144 echo "# Parent $ZERO_OID" &&
e9dfe253
PT
145 cat msg &&
146 echo &&
e9dfe253
PT
147 git diff-tree --no-commit-id -p second
148 } >patch1-hg.eml &&
fcceef4e 149
800f1104 150
b7446fcf
AR
151 echo file >file &&
152 git add file &&
153 git commit -F msg-without-scissors-line &&
154 git tag expected-for-scissors &&
bf72ac17
PT
155 git reset --hard HEAD^ &&
156
b7446fcf
AR
157 echo file >file &&
158 git add file &&
159 git commit -F msg-with-scissors-line &&
160 git tag expected-for-no-scissors &&
161 git format-patch --stdout expected-for-no-scissors^ >patch-with-scissors-line.eml &&
bf72ac17
PT
162 git reset --hard HEAD^ &&
163
d3a7b8f5
SB
164 sed -n -e "3,\$p" msg >file &&
165 git add file &&
166 test_tick &&
167 git commit -m third &&
800f1104 168
64d1022e 169 git format-patch --stdout first >patch2 &&
800f1104 170
d3a7b8f5
SB
171 git checkout -b lorem &&
172 sed -n -e "11,\$p" msg >file &&
173 head -n 9 msg >>file &&
174 test_tick &&
175 git commit -a -m "moved stuff" &&
800f1104 176
d3a7b8f5
SB
177 echo goodbye >another &&
178 git add another &&
179 test_tick &&
180 git commit -m "added another file" &&
d3a7b8f5 181
800f1104 182 git format-patch --stdout master >lorem-move.patch &&
a61ba26a 183 git format-patch --no-prefix --stdout master >lorem-zero.patch &&
18cdf802
JH
184
185 git checkout -b rename &&
186 git mv file renamed &&
187 git commit -m "renamed a file" &&
188
189 git format-patch -M --stdout lorem >rename.patch &&
190
191 git reset --soft lorem^ &&
192 git commit -m "renamed a file and added another" &&
193
194 git format-patch -M --stdout lorem^ >rename-add.patch &&
195
800f1104 196 # reset time
1f5ad6b1 197 sane_unset test_tick &&
800f1104
JN
198 test_tick
199'
d3a7b8f5
SB
200
201test_expect_success 'am applies patch correctly' '
5d274859
JN
202 rm -fr .git/rebase-apply &&
203 git reset --hard &&
d3a7b8f5
SB
204 git checkout first &&
205 test_tick &&
206 git am <patch1 &&
61e0eb9d 207 test_path_is_missing .git/rebase-apply &&
800f1104 208 git diff --exit-code second &&
d3a7b8f5
SB
209 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
210 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
0fcb2caf
JH
211'
212
ab156128
PT
213test_expect_success 'am fails if index is dirty' '
214 test_when_finished "rm -f dirtyfile" &&
215 rm -fr .git/rebase-apply &&
216 git reset --hard &&
217 git checkout first &&
218 echo dirtyfile >dirtyfile &&
219 git add dirtyfile &&
220 test_must_fail git am patch1 &&
221 test_path_is_dir .git/rebase-apply &&
222 test_cmp_rev first HEAD
223'
224
0fcb2caf 225test_expect_success 'am applies patch e-mail not in a mbox' '
5d274859
JN
226 rm -fr .git/rebase-apply &&
227 git reset --hard &&
0fcb2caf
JH
228 git checkout first &&
229 git am patch1.eml &&
61e0eb9d 230 test_path_is_missing .git/rebase-apply &&
800f1104 231 git diff --exit-code second &&
0fcb2caf
JH
232 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
233 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
e3f67d30
SB
234'
235
236test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '
5d274859
JN
237 rm -fr .git/rebase-apply &&
238 git reset --hard &&
e3f67d30
SB
239 git checkout first &&
240 git am patch1-crlf.eml &&
61e0eb9d 241 test_path_is_missing .git/rebase-apply &&
800f1104 242 git diff --exit-code second &&
e3f67d30
SB
243 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
244 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
d3a7b8f5
SB
245'
246
0e8341f2
DB
247test_expect_success 'am applies patch e-mail with preceding whitespace' '
248 rm -fr .git/rebase-apply &&
249 git reset --hard &&
250 git checkout first &&
251 git am patch1-ws.eml &&
61e0eb9d 252 test_path_is_missing .git/rebase-apply &&
0e8341f2
DB
253 git diff --exit-code second &&
254 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
255 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
256'
257
1daaddd1
PT
258test_expect_success 'am applies stgit patch' '
259 rm -fr .git/rebase-apply &&
260 git checkout -f first &&
261 git am patch1-stgit.eml &&
262 test_path_is_missing .git/rebase-apply &&
263 git diff --exit-code second &&
264 test_cmp_rev second HEAD &&
ab680dce
PT
265 test_cmp_rev second^ HEAD^
266'
267
268test_expect_success 'am --patch-format=stgit applies stgit patch' '
269 rm -fr .git/rebase-apply &&
270 git checkout -f first &&
271 git am --patch-format=stgit <patch1-stgit.eml &&
272 test_path_is_missing .git/rebase-apply &&
273 git diff --exit-code second &&
274 test_cmp_rev second HEAD &&
fcceef4e
PT
275 test_cmp_rev second^ HEAD^
276'
277
278test_expect_success 'am applies stgit series' '
279 rm -fr .git/rebase-apply &&
280 git checkout -f first &&
281 git am stgit-series/series &&
282 test_path_is_missing .git/rebase-apply &&
283 git diff --exit-code second &&
284 test_cmp_rev second HEAD &&
e9dfe253
PT
285 test_cmp_rev second^ HEAD^
286'
287
288test_expect_success 'am applies hg patch' '
289 rm -fr .git/rebase-apply &&
290 git checkout -f first &&
291 git am patch1-hg.eml &&
292 test_path_is_missing .git/rebase-apply &&
293 git diff --exit-code second &&
294 test_cmp_rev second HEAD &&
9f0aa6e6
PT
295 test_cmp_rev second^ HEAD^
296'
297
298test_expect_success 'am --patch-format=hg applies hg patch' '
299 rm -fr .git/rebase-apply &&
300 git checkout -f first &&
301 git am --patch-format=hg <patch1-hg.eml &&
302 test_path_is_missing .git/rebase-apply &&
303 git diff --exit-code second &&
304 test_cmp_rev second HEAD &&
1daaddd1
PT
305 test_cmp_rev second^ HEAD^
306'
307
f26bdf2d
PT
308test_expect_success 'am with applypatch-msg hook' '
309 test_when_finished "rm -f .git/hooks/applypatch-msg" &&
310 rm -fr .git/rebase-apply &&
311 git reset --hard &&
312 git checkout first &&
313 mkdir -p .git/hooks &&
314 write_script .git/hooks/applypatch-msg <<-\EOF &&
315 cat "$1" >actual-msg &&
316 echo hook-message >"$1"
317 EOF
318 git am patch1 &&
319 test_path_is_missing .git/rebase-apply &&
320 git diff --exit-code second &&
321 echo hook-message >expected &&
322 git log -1 --format=format:%B >actual &&
323 test_cmp expected actual &&
324 git log -1 --format=format:%B second >expected &&
325 test_cmp expected actual-msg
326'
327
328test_expect_success 'am with failing applypatch-msg hook' '
329 test_when_finished "rm -f .git/hooks/applypatch-msg" &&
330 rm -fr .git/rebase-apply &&
331 git reset --hard &&
332 git checkout first &&
333 mkdir -p .git/hooks &&
334 write_script .git/hooks/applypatch-msg <<-\EOF &&
335 exit 1
336 EOF
337 test_must_fail git am patch1 &&
338 test_path_is_dir .git/rebase-apply &&
339 git diff --exit-code first &&
340 test_cmp_rev first HEAD
341'
342
3bc6686b
PT
343test_expect_success 'am with pre-applypatch hook' '
344 test_when_finished "rm -f .git/hooks/pre-applypatch" &&
345 rm -fr .git/rebase-apply &&
346 git reset --hard &&
347 git checkout first &&
348 mkdir -p .git/hooks &&
349 write_script .git/hooks/pre-applypatch <<-\EOF &&
350 git diff first >diff.actual
351 exit 0
352 EOF
353 git am patch1 &&
354 test_path_is_missing .git/rebase-apply &&
355 git diff --exit-code second &&
356 test_cmp_rev second HEAD &&
357 git diff first..second >diff.expected &&
358 test_cmp diff.expected diff.actual
359'
360
361test_expect_success 'am with failing pre-applypatch hook' '
362 test_when_finished "rm -f .git/hooks/pre-applypatch" &&
363 rm -fr .git/rebase-apply &&
364 git reset --hard &&
365 git checkout first &&
366 mkdir -p .git/hooks &&
367 write_script .git/hooks/pre-applypatch <<-\EOF &&
368 exit 1
369 EOF
370 test_must_fail git am patch1 &&
371 test_path_is_dir .git/rebase-apply &&
372 git diff --exit-code second &&
373 test_cmp_rev first HEAD
374'
375
3ef4446b
PT
376test_expect_success 'am with post-applypatch hook' '
377 test_when_finished "rm -f .git/hooks/post-applypatch" &&
378 rm -fr .git/rebase-apply &&
379 git reset --hard &&
380 git checkout first &&
381 mkdir -p .git/hooks &&
382 write_script .git/hooks/post-applypatch <<-\EOF &&
383 git rev-parse HEAD >head.actual
384 git diff second >diff.actual
385 exit 0
386 EOF
387 git am patch1 &&
388 test_path_is_missing .git/rebase-apply &&
389 test_cmp_rev second HEAD &&
390 git rev-parse second >head.expected &&
391 test_cmp head.expected head.actual &&
392 git diff second >diff.expected &&
393 test_cmp diff.expected diff.actual
394'
395
396test_expect_success 'am with failing post-applypatch hook' '
397 test_when_finished "rm -f .git/hooks/post-applypatch" &&
398 rm -fr .git/rebase-apply &&
399 git reset --hard &&
400 git checkout first &&
401 mkdir -p .git/hooks &&
402 write_script .git/hooks/post-applypatch <<-\EOF &&
403 git rev-parse HEAD >head.actual
404 exit 1
405 EOF
406 git am patch1 &&
407 test_path_is_missing .git/rebase-apply &&
408 git diff --exit-code second &&
409 test_cmp_rev second HEAD &&
410 git rev-parse second >head.expected &&
411 test_cmp head.expected head.actual
412'
413
bf72ac17
PT
414test_expect_success 'am --scissors cuts the message at the scissors line' '
415 rm -fr .git/rebase-apply &&
416 git reset --hard &&
417 git checkout second &&
b7446fcf 418 git am --scissors patch-with-scissors-line.eml &&
bf72ac17 419 test_path_is_missing .git/rebase-apply &&
b7446fcf
AR
420 git diff --exit-code expected-for-scissors &&
421 test_cmp_rev expected-for-scissors HEAD
bf72ac17
PT
422'
423
424test_expect_success 'am --no-scissors overrides mailinfo.scissors' '
425 rm -fr .git/rebase-apply &&
426 git reset --hard &&
427 git checkout second &&
428 test_config mailinfo.scissors true &&
b7446fcf 429 git am --no-scissors patch-with-scissors-line.eml &&
bf72ac17 430 test_path_is_missing .git/rebase-apply &&
b7446fcf
AR
431 git diff --exit-code expected-for-no-scissors &&
432 test_cmp_rev expected-for-no-scissors HEAD
bf72ac17
PT
433'
434
800f1104
JN
435test_expect_success 'setup: new author and committer' '
436 GIT_AUTHOR_NAME="Another Thor" &&
437 GIT_AUTHOR_EMAIL="a.thor@example.com" &&
438 GIT_COMMITTER_NAME="Co M Miter" &&
439 GIT_COMMITTER_EMAIL="c.miter@example.com" &&
440 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
441'
d3a7b8f5
SB
442
443compare () {
800f1104
JN
444 a=$(git cat-file commit "$2" | grep "^$1 ") &&
445 b=$(git cat-file commit "$3" | grep "^$1 ") &&
446 test "$a" = "$b"
d3a7b8f5
SB
447}
448
449test_expect_success 'am changes committer and keeps author' '
450 test_tick &&
5d274859
JN
451 rm -fr .git/rebase-apply &&
452 git reset --hard &&
d3a7b8f5
SB
453 git checkout first &&
454 git am patch2 &&
61e0eb9d 455 test_path_is_missing .git/rebase-apply &&
d3a7b8f5 456 test "$(git rev-parse master^^)" = "$(git rev-parse HEAD^^)" &&
800f1104
JN
457 git diff --exit-code master..HEAD &&
458 git diff --exit-code master^..HEAD^ &&
d3a7b8f5
SB
459 compare author master HEAD &&
460 compare author master^ HEAD^ &&
461 test "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" = \
462 "$(git log -1 --pretty=format:"%cn <%ce>" HEAD)"
463'
464
465test_expect_success 'am --signoff adds Signed-off-by: line' '
5d274859
JN
466 rm -fr .git/rebase-apply &&
467 git reset --hard &&
d3a7b8f5
SB
468 git checkout -b master2 first &&
469 git am --signoff <patch2 &&
735285b4
PW
470 {
471 printf "third\n\nSigned-off-by: %s <%s>\n\n" \
472 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" &&
473 cat msg &&
474 printf "Signed-off-by: %s <%s>\n\n" \
475 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL"
476 } >expected-log &&
477 git log --pretty=%B -2 HEAD >actual &&
478 test_cmp expected-log actual
d3a7b8f5
SB
479'
480
481test_expect_success 'am stays in branch' '
800f1104
JN
482 echo refs/heads/master2 >expected &&
483 git symbolic-ref HEAD >actual &&
484 test_cmp expected actual
d3a7b8f5
SB
485'
486
487test_expect_success 'am --signoff does not add Signed-off-by: line if already there' '
735285b4
PW
488 git format-patch --stdout first >patch3 &&
489 git reset --hard first &&
490 git am --signoff <patch3 &&
491 git log --pretty=%B -2 HEAD >actual &&
492 test_cmp expected-log actual
493'
494
495test_expect_success 'am --signoff adds Signed-off-by: if another author is preset' '
496 NAME="A N Other" &&
497 EMAIL="a.n.other@example.com" &&
498 {
499 printf "third\n\nSigned-off-by: %s <%s>\nSigned-off-by: %s <%s>\n\n" \
500 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" \
501 "$NAME" "$EMAIL" &&
502 cat msg &&
503 printf "Signed-off-by: %s <%s>\nSigned-off-by: %s <%s>\n\n" \
504 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" \
505 "$NAME" "$EMAIL"
506 } >expected-log &&
507 git reset --hard first &&
508 GIT_COMMITTER_NAME="$NAME" GIT_COMMITTER_EMAIL="$EMAIL" \
509 git am --signoff <patch3 &&
510 git log --pretty=%B -2 HEAD >actual &&
511 test_cmp expected-log actual
512'
513
514test_expect_success 'am --signoff duplicates Signed-off-by: if it is not the last one' '
515 NAME="A N Other" &&
516 EMAIL="a.n.other@example.com" &&
517 {
518 printf "third\n\nSigned-off-by: %s <%s>\n\
519Signed-off-by: %s <%s>\nSigned-off-by: %s <%s>\n\n" \
520 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" \
521 "$NAME" "$EMAIL" \
522 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" &&
523 cat msg &&
524 printf "Signed-off-by: %s <%s>\nSigned-off-by: %s <%s>\n\
525Signed-off-by: %s <%s>\n\n" \
526 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL" \
527 "$NAME" "$EMAIL" \
528 "$GIT_COMMITTER_NAME" "$GIT_COMMITTER_EMAIL"
529 } >expected-log &&
530 git format-patch --stdout first >patch3 &&
531 git reset --hard first &&
532 git am --signoff <patch3 &&
533 git log --pretty=%B -2 HEAD >actual &&
534 test_cmp expected-log actual
d3a7b8f5
SB
535'
536
537test_expect_success 'am without --keep removes Re: and [PATCH] stuff' '
735285b4
PW
538 git format-patch --stdout HEAD^ >tmp &&
539 sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2] [foo," tmp >patch4 &&
540 git reset --hard HEAD^ &&
541 git am <patch4 &&
800f1104
JN
542 git rev-parse HEAD >expected &&
543 git rev-parse master2 >actual &&
544 test_cmp expected actual
d3a7b8f5
SB
545'
546
547test_expect_success 'am --keep really keeps the subject' '
5d274859
JN
548 rm -fr .git/rebase-apply &&
549 git reset --hard &&
d3a7b8f5
SB
550 git checkout HEAD^ &&
551 git am --keep patch4 &&
61e0eb9d 552 test_path_is_missing .git/rebase-apply &&
800f1104 553 git cat-file commit HEAD >actual &&
f7e5ea17
TR
554 grep "Re: Re: Re: \[PATCH 1/5 v2\] \[foo\] third" actual
555'
556
ee2d1cb4 557test_expect_success 'am --keep-non-patch really keeps the non-patch part' '
f7e5ea17
TR
558 rm -fr .git/rebase-apply &&
559 git reset --hard &&
560 git checkout HEAD^ &&
561 git am --keep-non-patch patch4 &&
61e0eb9d 562 test_path_is_missing .git/rebase-apply &&
f7e5ea17
TR
563 git cat-file commit HEAD >actual &&
564 grep "^\[foo\] third" actual
d3a7b8f5
SB
565'
566
8c8884ce 567test_expect_success 'setup am -3' '
5d274859
JN
568 rm -fr .git/rebase-apply &&
569 git reset --hard &&
8c8884ce 570 git checkout -b base3way master2 &&
d3a7b8f5
SB
571 sed -n -e "3,\$p" msg >file &&
572 head -n 9 msg >>file &&
573 git add file &&
574 test_tick &&
8c8884ce
RL
575 git commit -m "copied stuff"
576'
577
578test_expect_success 'am -3 falls back to 3-way merge' '
579 rm -fr .git/rebase-apply &&
580 git reset --hard &&
581 git checkout -b lorem2 base3way &&
d3a7b8f5 582 git am -3 lorem-move.patch &&
61e0eb9d 583 test_path_is_missing .git/rebase-apply &&
800f1104 584 git diff --exit-code lorem
d3a7b8f5
SB
585'
586
a61ba26a
JH
587test_expect_success 'am -3 -p0 can read --no-prefix patch' '
588 rm -fr .git/rebase-apply &&
589 git reset --hard &&
8c8884ce 590 git checkout -b lorem3 base3way &&
a61ba26a 591 git am -3 -p0 lorem-zero.patch &&
61e0eb9d 592 test_path_is_missing .git/rebase-apply &&
a61ba26a
JH
593 git diff --exit-code lorem
594'
595
e97a5e76
RL
596test_expect_success 'am with config am.threeWay falls back to 3-way merge' '
597 rm -fr .git/rebase-apply &&
598 git reset --hard &&
599 git checkout -b lorem4 base3way &&
600 test_config am.threeWay 1 &&
601 git am lorem-move.patch &&
602 test_path_is_missing .git/rebase-apply &&
603 git diff --exit-code lorem
604'
605
606test_expect_success 'am with config am.threeWay overridden by --no-3way' '
607 rm -fr .git/rebase-apply &&
608 git reset --hard &&
609 git checkout -b lorem5 base3way &&
610 test_config am.threeWay 1 &&
611 test_must_fail git am --no-3way lorem-move.patch &&
612 test_path_is_dir .git/rebase-apply
613'
614
18cdf802
JH
615test_expect_success 'am can rename a file' '
616 grep "^rename from" rename.patch &&
617 rm -fr .git/rebase-apply &&
618 git reset --hard &&
619 git checkout lorem^0 &&
620 git am rename.patch &&
61e0eb9d 621 test_path_is_missing .git/rebase-apply &&
18cdf802
JH
622 git update-index --refresh &&
623 git diff --exit-code rename
624'
625
626test_expect_success 'am -3 can rename a file' '
627 grep "^rename from" rename.patch &&
628 rm -fr .git/rebase-apply &&
629 git reset --hard &&
630 git checkout lorem^0 &&
631 git am -3 rename.patch &&
61e0eb9d 632 test_path_is_missing .git/rebase-apply &&
18cdf802
JH
633 git update-index --refresh &&
634 git diff --exit-code rename
635'
636
637test_expect_success 'am -3 can rename a file after falling back to 3-way merge' '
638 grep "^rename from" rename-add.patch &&
639 rm -fr .git/rebase-apply &&
640 git reset --hard &&
641 git checkout lorem^0 &&
642 git am -3 rename-add.patch &&
61e0eb9d 643 test_path_is_missing .git/rebase-apply &&
18cdf802
JH
644 git update-index --refresh &&
645 git diff --exit-code rename
646'
647
0e987a12 648test_expect_success 'am -3 -q is quiet' '
5d274859 649 rm -fr .git/rebase-apply &&
18cdf802 650 git checkout -f lorem2 &&
8c8884ce 651 git reset base3way --hard &&
800f1104 652 git am -3 -q lorem-move.patch >output.out 2>&1 &&
ec10b018 653 test_must_be_empty output.out
0e987a12
SB
654'
655
d3a7b8f5 656test_expect_success 'am pauses on conflict' '
5d274859
JN
657 rm -fr .git/rebase-apply &&
658 git reset --hard &&
d3a7b8f5 659 git checkout lorem2^^ &&
d492b31c 660 test_must_fail git am lorem-move.patch &&
51ef1daa 661 test -d .git/rebase-apply
d3a7b8f5
SB
662'
663
984913a2
NTND
664test_expect_success 'am --show-current-patch' '
665 git am --show-current-patch >actual.patch &&
666 test_cmp .git/rebase-apply/0001 actual.patch
667'
668
f3b48228
PB
669test_expect_success 'am --show-current-patch=raw' '
670 git am --show-current-patch=raw >actual.patch &&
671 test_cmp .git/rebase-apply/0001 actual.patch
672'
673
aa416b22
PB
674test_expect_success 'am --show-current-patch=diff' '
675 git am --show-current-patch=diff >actual.patch &&
676 test_cmp .git/rebase-apply/patch actual.patch
677'
678
f3b48228
PB
679test_expect_success 'am accepts repeated --show-current-patch' '
680 git am --show-current-patch --show-current-patch=raw >actual.patch &&
681 test_cmp .git/rebase-apply/0001 actual.patch
682'
683
aa416b22
PB
684test_expect_success 'am detects incompatible --show-current-patch' '
685 test_must_fail git am --show-current-patch=raw --show-current-patch=diff &&
686 test_must_fail git am --show-current-patch --show-current-patch=diff
687'
688
d3a7b8f5 689test_expect_success 'am --skip works' '
800f1104 690 echo goodbye >expected &&
d3a7b8f5 691 git am --skip &&
61e0eb9d 692 test_path_is_missing .git/rebase-apply &&
800f1104
JN
693 git diff --exit-code lorem2^^ -- file &&
694 test_cmp expected another
d3a7b8f5
SB
695'
696
b141f3c9
RR
697test_expect_success 'am --abort removes a stray directory' '
698 mkdir .git/rebase-apply &&
699 git am --abort &&
700 test_path_is_missing .git/rebase-apply
701'
702
b4967ab4
PT
703test_expect_success 'am refuses patches when paused' '
704 rm -fr .git/rebase-apply &&
705 git reset --hard &&
706 git checkout lorem2^^ &&
707
708 test_must_fail git am lorem-move.patch &&
709 test_path_is_dir .git/rebase-apply &&
710 test_cmp_rev lorem2^^ HEAD &&
711
712 test_must_fail git am <lorem-move.patch &&
713 test_path_is_dir .git/rebase-apply &&
714 test_cmp_rev lorem2^^ HEAD
715'
716
d3a7b8f5 717test_expect_success 'am --resolved works' '
800f1104 718 echo goodbye >expected &&
5d274859
JN
719 rm -fr .git/rebase-apply &&
720 git reset --hard &&
d3a7b8f5 721 git checkout lorem2^^ &&
d492b31c 722 test_must_fail git am lorem-move.patch &&
51ef1daa 723 test -d .git/rebase-apply &&
d3a7b8f5
SB
724 echo resolved >>file &&
725 git add file &&
726 git am --resolved &&
61e0eb9d 727 test_path_is_missing .git/rebase-apply &&
800f1104 728 test_cmp expected another
d3a7b8f5
SB
729'
730
60ff7f9f
PT
731test_expect_success 'am --resolved fails if index has no changes' '
732 rm -fr .git/rebase-apply &&
733 git reset --hard &&
734 git checkout lorem2^^ &&
735 test_must_fail git am lorem-move.patch &&
736 test_path_is_dir .git/rebase-apply &&
737 test_cmp_rev lorem2^^ HEAD &&
738 test_must_fail git am --resolved &&
739 test_path_is_dir .git/rebase-apply &&
740 test_cmp_rev lorem2^^ HEAD
741'
742
9e2a113d
PT
743test_expect_success 'am --resolved fails if index has unmerged entries' '
744 rm -fr .git/rebase-apply &&
745 git reset --hard &&
746 git checkout second &&
747 test_must_fail git am -3 lorem-move.patch &&
748 test_path_is_dir .git/rebase-apply &&
749 test_cmp_rev second HEAD &&
750 test_must_fail git am --resolved >err &&
751 test_path_is_dir .git/rebase-apply &&
752 test_cmp_rev second HEAD &&
753 test_i18ngrep "still have unmerged paths" err
754'
755
d3a7b8f5 756test_expect_success 'am takes patches from a Pine mailbox' '
5d274859
JN
757 rm -fr .git/rebase-apply &&
758 git reset --hard &&
d3a7b8f5
SB
759 git checkout first &&
760 cat pine patch1 | git am &&
61e0eb9d 761 test_path_is_missing .git/rebase-apply &&
800f1104 762 git diff --exit-code master^..HEAD
d3a7b8f5
SB
763'
764
765test_expect_success 'am fails on mail without patch' '
5d274859
JN
766 rm -fr .git/rebase-apply &&
767 git reset --hard &&
d492b31c 768 test_must_fail git am <failmail &&
5d274859 769 git am --abort &&
61e0eb9d 770 test_path_is_missing .git/rebase-apply
d3a7b8f5
SB
771'
772
773test_expect_success 'am fails on empty patch' '
5d274859
JN
774 rm -fr .git/rebase-apply &&
775 git reset --hard &&
d3a7b8f5 776 echo "---" >>failmail &&
d492b31c 777 test_must_fail git am <failmail &&
d3a7b8f5 778 git am --skip &&
61e0eb9d 779 test_path_is_missing .git/rebase-apply
d3a7b8f5
SB
780'
781
8ec00d05
SB
782test_expect_success 'am works from stdin in subdirectory' '
783 rm -fr subdir &&
5d274859
JN
784 rm -fr .git/rebase-apply &&
785 git reset --hard &&
8ec00d05
SB
786 git checkout first &&
787 (
788 mkdir -p subdir &&
789 cd subdir &&
790 git am <../patch1
791 ) &&
800f1104 792 git diff --exit-code second
8ec00d05
SB
793'
794
795test_expect_success 'am works from file (relative path given) in subdirectory' '
796 rm -fr subdir &&
5d274859
JN
797 rm -fr .git/rebase-apply &&
798 git reset --hard &&
8ec00d05
SB
799 git checkout first &&
800 (
801 mkdir -p subdir &&
802 cd subdir &&
803 git am ../patch1
804 ) &&
800f1104 805 git diff --exit-code second
8ec00d05
SB
806'
807
808test_expect_success 'am works from file (absolute path given) in subdirectory' '
809 rm -fr subdir &&
5d274859
JN
810 rm -fr .git/rebase-apply &&
811 git reset --hard &&
8ec00d05
SB
812 git checkout first &&
813 P=$(pwd) &&
814 (
815 mkdir -p subdir &&
816 cd subdir &&
817 git am "$P/patch1"
818 ) &&
800f1104 819 git diff --exit-code second
8ec00d05
SB
820'
821
3f01ad66 822test_expect_success 'am --committer-date-is-author-date' '
5d274859
JN
823 rm -fr .git/rebase-apply &&
824 git reset --hard &&
3f01ad66
JH
825 git checkout first &&
826 test_tick &&
827 git am --committer-date-is-author-date patch1 &&
9524cf29 828 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
800f1104
JN
829 sed -ne "/^author /s/.*> //p" head1 >at &&
830 sed -ne "/^committer /s/.*> //p" head1 >ct &&
831 test_cmp at ct
3f01ad66
JH
832'
833
834test_expect_success 'am without --committer-date-is-author-date' '
5d274859
JN
835 rm -fr .git/rebase-apply &&
836 git reset --hard &&
3f01ad66
JH
837 git checkout first &&
838 test_tick &&
839 git am patch1 &&
9524cf29 840 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
800f1104
JN
841 sed -ne "/^author /s/.*> //p" head1 >at &&
842 sed -ne "/^committer /s/.*> //p" head1 >ct &&
843 ! test_cmp at ct
3f01ad66
JH
844'
845
a79ec62d
NS
846# This checks for +0000 because TZ is set to UTC and that should
847# show up when the current time is used. The date in message is set
848# by test_tick that uses -0700 timezone; if this feature does not
849# work, we will see that instead of +0000.
850test_expect_success 'am --ignore-date' '
5d274859
JN
851 rm -fr .git/rebase-apply &&
852 git reset --hard &&
a79ec62d
NS
853 git checkout first &&
854 test_tick &&
855 git am --ignore-date patch1 &&
9524cf29 856 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
800f1104
JN
857 sed -ne "/^author /s/.*> //p" head1 >at &&
858 grep "+0000" at
a79ec62d
NS
859'
860
f79d4c8a 861test_expect_success 'am into an unborn branch' '
800f1104 862 git rev-parse first^{tree} >expected &&
5d274859
JN
863 rm -fr .git/rebase-apply &&
864 git reset --hard &&
f79d4c8a 865 rm -fr subdir &&
800f1104 866 mkdir subdir &&
f79d4c8a
NS
867 git format-patch --numbered-files -o subdir -1 first &&
868 (
869 cd subdir &&
870 git init &&
871 git am 1
872 ) &&
800f1104
JN
873 (
874 cd subdir &&
875 git rev-parse HEAD^{tree} >../actual
f79d4c8a 876 ) &&
800f1104 877 test_cmp expected actual
f79d4c8a
NS
878'
879
b3c32ead 880test_expect_success 'am newline in subject' '
5d274859
JN
881 rm -fr .git/rebase-apply &&
882 git reset --hard &&
b3c32ead
SB
883 git checkout first &&
884 test_tick &&
800f1104
JN
885 sed -e "s/second/second \\\n foo/" patch1 >patchnl &&
886 git am <patchnl >output.out 2>&1 &&
dff1a983 887 test_i18ngrep "^Applying: second \\\n foo$" output.out
b3c32ead
SB
888'
889
0e987a12 890test_expect_success 'am -q is quiet' '
5d274859
JN
891 rm -fr .git/rebase-apply &&
892 git reset --hard &&
0e987a12
SB
893 git checkout first &&
894 test_tick &&
800f1104 895 git am -q <patch1 >output.out 2>&1 &&
ec10b018 896 test_must_be_empty output.out
0e987a12
SB
897'
898
f0c5793b
JM
899test_expect_success 'am empty-file does not infloop' '
900 rm -fr .git/rebase-apply &&
901 git reset --hard &&
902 touch empty-file &&
903 test_tick &&
948065a4 904 test_must_fail git am empty-file 2>actual &&
f0c5793b 905 echo Patch format detection failed. >expected &&
b1f5b783 906 test_i18ncmp expected actual
f0c5793b
JM
907'
908
a078f732
PB
909test_expect_success 'am --message-id really adds the message id' '
910 rm -fr .git/rebase-apply &&
911 git reset --hard &&
912 git checkout HEAD^ &&
913 git am --message-id patch1.eml &&
914 test_path_is_missing .git/rebase-apply &&
915 git cat-file commit HEAD | tail -n1 >actual &&
916 grep Message-Id patch1.eml >expected &&
917 test_cmp expected actual
918'
919
8528bf4b
PT
920test_expect_success 'am.messageid really adds the message id' '
921 rm -fr .git/rebase-apply &&
922 git reset --hard &&
923 git checkout HEAD^ &&
924 test_config am.messageid true &&
925 git am patch1.eml &&
926 test_path_is_missing .git/rebase-apply &&
927 git cat-file commit HEAD | tail -n1 >actual &&
928 grep Message-Id patch1.eml >expected &&
929 test_cmp expected actual
930'
931
a078f732
PB
932test_expect_success 'am --message-id -s signs off after the message id' '
933 rm -fr .git/rebase-apply &&
934 git reset --hard &&
935 git checkout HEAD^ &&
936 git am -s --message-id patch1.eml &&
937 test_path_is_missing .git/rebase-apply &&
938 git cat-file commit HEAD | tail -n2 | head -n1 >actual &&
939 grep Message-Id patch1.eml >expected &&
940 test_cmp expected actual
941'
942
9dd330e6
JK
943test_expect_success 'am -3 works with rerere' '
944 rm -fr .git/rebase-apply &&
945 git reset --hard &&
946
947 # make patches one->two and two->three...
948 test_commit one file &&
949 test_commit two file &&
950 test_commit three file &&
951 git format-patch -2 --stdout >seq.patch &&
952
953 # and create a situation that conflicts...
954 git reset --hard one &&
955 test_commit other file &&
956
957 # enable rerere...
958 test_config rerere.enabled true &&
959 test_when_finished "rm -rf .git/rr-cache" &&
960
961 # ...and apply. Our resolution is to skip the first
962 # patch, and the rerere the second one.
963 test_must_fail git am -3 seq.patch &&
964 test_must_fail git am --skip &&
965 echo resolved >file &&
966 git add file &&
967 git am --resolved &&
968
969 # now apply again, and confirm that rerere engaged (we still
970 # expect failure from am because rerere does not auto-commit
971 # for us).
972 git reset --hard other &&
973 test_must_fail git am -3 seq.patch &&
974 test_must_fail git am --skip &&
975 echo resolved >expect &&
976 test_cmp expect file
977'
978
aab84542
JH
979test_expect_success 'am -s unexpected trailer block' '
980 rm -fr .git/rebase-apply &&
981 git reset --hard &&
982 echo signed >file &&
983 git add file &&
984 cat >msg <<-EOF &&
985 subject here
986
987 Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
988 [jc: tweaked log message]
989 Signed-off-by: J C H <j@c.h>
990 EOF
991 git commit -F msg &&
c76b84a1 992 git cat-file commit HEAD | sed -e "1,/^$/d" >original &&
aab84542
JH
993 git format-patch --stdout -1 >patch &&
994
995 git reset --hard HEAD^ &&
996 git am -s patch &&
997 (
998 cat original &&
999 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
1000 ) >expect &&
c76b84a1 1001 git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
aab84542
JH
1002 test_cmp expect actual &&
1003
1004 cat >msg <<-\EOF &&
1005 subject here
1006
1007 We make sure that there is a blank line between the log
1008 message proper and Signed-off-by: line added.
1009 EOF
1010 git reset HEAD^ &&
1011 git commit -F msg file &&
c76b84a1 1012 git cat-file commit HEAD | sed -e "1,/^$/d" >original &&
aab84542
JH
1013 git format-patch --stdout -1 >patch &&
1014
1015 git reset --hard HEAD^ &&
1016 git am -s patch &&
1017
1018 (
1019 cat original &&
1020 echo &&
1021 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
1022 ) >expect &&
c76b84a1 1023 git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
aab84542
JH
1024 test_cmp expect actual
1025'
1026
d9925d1a
EW
1027test_expect_success 'am --patch-format=mboxrd handles mboxrd' '
1028 rm -fr .git/rebase-apply &&
1029 git checkout -f first &&
1030 echo mboxrd >>file &&
1031 git add file &&
1032 cat >msg <<-\INPUT_END &&
1033 mboxrd should escape the body
1034
1035 From could trip up a loose mbox parser
1036 >From extra escape for reversibility
1037 INPUT_END
1038 git commit -F msg &&
1039 git format-patch --pretty=mboxrd --stdout -1 >mboxrd1 &&
1040 grep "^>From could trip up a loose mbox parser" mboxrd1 &&
1041 git checkout -f first &&
1042 git am --patch-format=mboxrd mboxrd1 &&
1043 git cat-file commit HEAD | tail -n4 >out &&
1044 test_cmp msg out
1045'
1046
6b4b013f
JT
1047test_expect_success 'am works with multi-line in-body headers' '
1048 FORTY="String that has a length of more than forty characters" &&
1049 LONG="$FORTY $FORTY" &&
1050 rm -fr .git/rebase-apply &&
1051 git checkout -f first &&
1052 echo one >> file &&
fd1062e5
LT
1053 git commit -am "$LONG
1054
1055 Body test" --author="$LONG <long@example.com>" &&
6b4b013f
JT
1056 git format-patch --stdout -1 >patch &&
1057 # bump from, date, and subject down to in-body header
1058 perl -lpe "
1059 if (/^From:/) {
1060 print \"From: x <x\@example.com>\";
1061 print \"Date: Sat, 1 Jan 2000 00:00:00 +0000\";
1062 print \"Subject: x\n\";
1063 }
1064 " patch >msg &&
1065 git checkout HEAD^ &&
1066 git am msg &&
1067 # Ensure that the author and full message are present
1068 git cat-file commit HEAD | grep "^author.*long@example.com" &&
fd1062e5 1069 git cat-file commit HEAD | grep "^$LONG$"
6b4b013f
JT
1070'
1071
65ed8ff3
NTND
1072test_expect_success 'am --quit keeps HEAD where it is' '
1073 mkdir .git/rebase-apply &&
1074 >.git/rebase-apply/last &&
1075 >.git/rebase-apply/next &&
1076 git rev-parse HEAD^ >.git/ORIG_HEAD &&
1077 git rev-parse HEAD >expected &&
1078 git am --quit &&
1079 test_path_is_missing .git/rebase-apply &&
1080 git rev-parse HEAD >actual &&
1081 test_cmp expected actual
1082'
1083
2c65d90f 1084test_expect_success 'am and .gitattibutes' '
1085 test_create_repo attributes &&
1086 (
1087 cd attributes &&
1088 test_commit init &&
1089 git config filter.test.clean "sed -e '\''s/smudged/clean/g'\''" &&
1090 git config filter.test.smudge "sed -e '\''s/clean/smudged/g'\''" &&
1091
1092 test_commit second &&
1093 git checkout -b test HEAD^ &&
1094
1095 echo "*.txt filter=test conflict-marker-size=10" >.gitattributes &&
1096 git add .gitattributes &&
1097 test_commit third &&
1098
1099 echo "This text is smudged." >a.txt &&
1100 git add a.txt &&
1101 test_commit fourth &&
1102
1103 git checkout -b removal HEAD^ &&
1104 git rm .gitattributes &&
1105 git add -u &&
1106 test_commit fifth &&
1107 git cherry-pick test &&
1108
1109 git checkout -b conflict third &&
1110 echo "This text is different." >a.txt &&
1111 git add a.txt &&
1112 test_commit sixth &&
1113
1114 git checkout test &&
1115 git format-patch --stdout master..HEAD >patches &&
1116 git reset --hard master &&
1117 git am patches &&
1118 grep "smudged" a.txt &&
1119
1120 git checkout removal &&
1121 git reset --hard &&
1122 git format-patch --stdout master..HEAD >patches &&
1123 git reset --hard master &&
1124 git am patches &&
1125 grep "clean" a.txt &&
1126
1127 git checkout conflict &&
1128 git reset --hard &&
1129 git format-patch --stdout master..HEAD >patches &&
1130 git reset --hard fourth &&
1131 test_must_fail git am -3 patches &&
1132 grep "<<<<<<<<<<" a.txt
1133 )
1134'
1135
3318238d
JT
1136test_expect_success 'apply binary blob in partial clone' '
1137 printf "\\000" >binary &&
1138 git add binary &&
1139 git commit -m "binary blob" &&
1140 git format-patch --stdout -m HEAD^ >patch &&
1141
1142 test_create_repo server &&
1143 test_config -C server uploadpack.allowfilter 1 &&
1144 test_config -C server uploadpack.allowanysha1inwant 1 &&
1145 git clone --filter=blob:none "file://$(pwd)/server" client &&
1146 test_when_finished "rm -rf client" &&
1147
1148 # Exercise to make sure that it works
1149 git -C client am ../patch
1150'
1151
d3a7b8f5 1152test_done