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