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