3 test_description
='git am running'
7 test_expect_success
'setup: messages' '
11 Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy
12 eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
13 voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
14 kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
15 ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
16 tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
17 vero eos et accusam et justo duo dolores et ea rebum.
20 q_to_tab <<-\EOF >>msg &&
21 QDuis autem vel eum iriure dolor in hendrerit in vulputate velit
22 Qesse molestie consequat, vel illum dolore eu feugiat nulla facilisis
23 Qat vero eros et accumsan et iusto odio dignissim qui blandit
24 Qpraesent luptatum zzril delenit augue duis dolore te feugait nulla
29 Lorem ipsum dolor sit amet,
30 consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
31 laoreet dolore magna aliquam erat volutpat.
37 Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
38 lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
39 dolor in hendrerit in vulputate velit esse molestie consequat, vel illum
40 dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio
41 dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te
42 feugait nulla facilisi.
45 cat >failmail <<-\EOF &&
46 From foo@example.com Fri May 23 10:43:49 2008
49 Subject: Re: [RFC/PATCH] git-foo.sh
50 Date: Fri, 23 May 2008 05:23:42 +0200
52 Sometimes we have to find out that there'\''s nothing left.
57 From MAILER-DAEMON Fri May 23 10:43:49 2008
58 Date: 23 May 2008 05:23:42 +0200
59 From: Mail System Internal Data <MAILER-DAEMON@example.com>
60 Subject: DON'\''T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
61 Message-ID: <foo-0001@example.com>
63 This text is part of the internal format of your mail folder, and is not
64 a real message. It is created automatically by the mail system software.
65 If deleted, important folder data will be lost, and it will be re-created
66 with the data reset to initial values.
70 signoff="Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
73 test_expect_success setup
'
77 git commit -m first &&
83 git commit -s -F msg &&
86 git format-patch --stdout first >patch1 &&
88 echo "X-Fake-Field: Line One" &&
89 echo "X-Fake-Field: Line Two" &&
90 echo "X-Fake-Field: Line Three" &&
91 git format-patch --stdout first | sed -e "1d"
94 echo "X-Fake-Field: Line One" &&
95 echo "X-Fake-Field: Line Two" &&
96 echo "X-Fake-Field: Line Three" &&
97 git format-patch --stdout first | sed -e "1d"
98 } | append_cr >patch1-crlf.eml &&
101 echo "X-Fake-Field: Line One" &&
102 echo "X-Fake-Field: Line Two" &&
103 echo "X-Fake-Field: Line Three" &&
104 git format-patch --stdout first | sed -e "1d"
107 sed -n -e "3,\$p" msg >file &&
110 git commit -m third &&
112 git format-patch --stdout first >patch2 &&
114 git checkout -b lorem &&
115 sed -n -e "11,\$p" msg >file &&
116 head -n 9 msg >>file &&
118 git commit -a -m "moved stuff" &&
120 echo goodbye >another &&
123 git commit -m "added another file" &&
125 git format-patch --stdout master >lorem-move.patch &&
127 git checkout -b rename &&
128 git mv file renamed &&
129 git commit -m "renamed a file" &&
131 git format-patch -M --stdout lorem >rename.patch &&
133 git reset --soft lorem^ &&
134 git commit -m "renamed a file and added another" &&
136 git format-patch -M --stdout lorem^ >rename-add.patch &&
139 sane_unset test_tick &&
143 test_expect_success
'am applies patch correctly' '
144 rm -fr .git/rebase-apply &&
146 git checkout first &&
149 ! test -d .git/rebase-apply &&
150 git diff --exit-code second &&
151 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
152 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
155 test_expect_success
'am applies patch e-mail not in a mbox' '
156 rm -fr .git/rebase-apply &&
158 git checkout first &&
160 ! test -d .git/rebase-apply &&
161 git diff --exit-code second &&
162 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
163 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
166 test_expect_success
'am applies patch e-mail not in a mbox with CRLF' '
167 rm -fr .git/rebase-apply &&
169 git checkout first &&
170 git am patch1-crlf.eml &&
171 ! test -d .git/rebase-apply &&
172 git diff --exit-code second &&
173 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
174 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
177 test_expect_success
'am applies patch e-mail with preceding whitespace' '
178 rm -fr .git/rebase-apply &&
180 git checkout first &&
181 git am patch1-ws.eml &&
182 ! test -d .git/rebase-apply &&
183 git diff --exit-code second &&
184 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
185 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
188 test_expect_success
'setup: new author and committer' '
189 GIT_AUTHOR_NAME="Another Thor" &&
190 GIT_AUTHOR_EMAIL="a.thor@example.com" &&
191 GIT_COMMITTER_NAME="Co M Miter" &&
192 GIT_COMMITTER_EMAIL="c.miter@example.com" &&
193 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
197 a
=$
(git cat-file commit
"$2" |
grep "^$1 ") &&
198 b
=$
(git cat-file commit
"$3" |
grep "^$1 ") &&
202 test_expect_success
'am changes committer and keeps author' '
204 rm -fr .git/rebase-apply &&
206 git checkout first &&
208 ! test -d .git/rebase-apply &&
209 test "$(git rev-parse master^^)" = "$(git rev-parse HEAD^^)" &&
210 git diff --exit-code master..HEAD &&
211 git diff --exit-code master^..HEAD^ &&
212 compare author master HEAD &&
213 compare author master^ HEAD^ &&
214 test "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" = \
215 "$(git log -1 --pretty=format:"%cn <%ce>" HEAD)"
218 test_expect_success
'am --signoff adds Signed-off-by: line' '
219 rm -fr .git/rebase-apply &&
221 git checkout -b master2 first &&
222 git am --signoff <patch2 &&
223 printf "%s\n" "$signoff" >expected &&
224 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected &&
225 git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
226 test_cmp expected actual &&
227 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected &&
228 git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
229 test_cmp expected actual
232 test_expect_success
'am stays in branch' '
233 echo refs/heads/master2 >expected &&
234 git symbolic-ref HEAD >actual &&
235 test_cmp expected actual
238 test_expect_success
'am --signoff does not add Signed-off-by: line if already there' '
239 git format-patch --stdout HEAD^ >patch3 &&
240 sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2] [foo," patch3 >patch4 &&
241 rm -fr .git/rebase-apply &&
243 git checkout HEAD^ &&
244 git am --signoff patch4 &&
245 git cat-file commit HEAD >actual &&
246 test $(grep -c "^Signed-off-by:" actual) -eq 1
249 test_expect_success
'am without --keep removes Re: and [PATCH] stuff' '
250 git rev-parse HEAD >expected &&
251 git rev-parse master2 >actual &&
252 test_cmp expected actual
255 test_expect_success
'am --keep really keeps the subject' '
256 rm -fr .git/rebase-apply &&
258 git checkout HEAD^ &&
259 git am --keep patch4 &&
260 ! test -d .git/rebase-apply &&
261 git cat-file commit HEAD >actual &&
262 grep "Re: Re: Re: \[PATCH 1/5 v2\] \[foo\] third" actual
265 test_expect_success
'am --keep-non-patch really keeps the non-patch part' '
266 rm -fr .git/rebase-apply &&
268 git checkout HEAD^ &&
269 git am --keep-non-patch patch4 &&
270 ! test -d .git/rebase-apply &&
271 git cat-file commit HEAD >actual &&
272 grep "^\[foo\] third" actual
275 test_expect_success
'am -3 falls back to 3-way merge' '
276 rm -fr .git/rebase-apply &&
278 git checkout -b lorem2 master2 &&
279 sed -n -e "3,\$p" msg >file &&
280 head -n 9 msg >>file &&
283 git commit -m "copied stuff" &&
284 git am -3 lorem-move.patch &&
285 ! test -d .git/rebase-apply &&
286 git diff --exit-code lorem
289 test_expect_success
'am can rename a file' '
290 grep "^rename from" rename.patch &&
291 rm -fr .git/rebase-apply &&
293 git checkout lorem^0 &&
294 git am rename.patch &&
295 ! test -d .git/rebase-apply &&
296 git update-index --refresh &&
297 git diff --exit-code rename
300 test_expect_success
'am -3 can rename a file' '
301 grep "^rename from" rename.patch &&
302 rm -fr .git/rebase-apply &&
304 git checkout lorem^0 &&
305 git am -3 rename.patch &&
306 ! test -d .git/rebase-apply &&
307 git update-index --refresh &&
308 git diff --exit-code rename
311 test_expect_success
'am -3 can rename a file after falling back to 3-way merge' '
312 grep "^rename from" rename-add.patch &&
313 rm -fr .git/rebase-apply &&
315 git checkout lorem^0 &&
316 git am -3 rename-add.patch &&
317 ! test -d .git/rebase-apply &&
318 git update-index --refresh &&
319 git diff --exit-code rename
322 test_expect_success
'am -3 -q is quiet' '
323 rm -fr .git/rebase-apply &&
324 git checkout -f lorem2 &&
325 git reset master2 --hard &&
326 sed -n -e "3,\$p" msg >file &&
327 head -n 9 msg >>file &&
330 git commit -m "copied stuff" &&
331 git am -3 -q lorem-move.patch >output.out 2>&1 &&
335 test_expect_success
'am pauses on conflict' '
336 rm -fr .git/rebase-apply &&
338 git checkout lorem2^^ &&
339 test_must_fail git am lorem-move.patch &&
340 test -d .git/rebase-apply
343 test_expect_success
'am --skip works' '
344 echo goodbye >expected &&
346 ! test -d .git/rebase-apply &&
347 git diff --exit-code lorem2^^ -- file &&
348 test_cmp expected another
351 test_expect_success
'am --resolved works' '
352 echo goodbye >expected &&
353 rm -fr .git/rebase-apply &&
355 git checkout lorem2^^ &&
356 test_must_fail git am lorem-move.patch &&
357 test -d .git/rebase-apply &&
358 echo resolved >>file &&
361 ! test -d .git/rebase-apply &&
362 test_cmp expected another
365 test_expect_success
'am takes patches from a Pine mailbox' '
366 rm -fr .git/rebase-apply &&
368 git checkout first &&
369 cat pine patch1 | git am &&
370 ! test -d .git/rebase-apply &&
371 git diff --exit-code master^..HEAD
374 test_expect_success
'am fails on mail without patch' '
375 rm -fr .git/rebase-apply &&
377 test_must_fail git am <failmail &&
379 ! test -d .git/rebase-apply
382 test_expect_success
'am fails on empty patch' '
383 rm -fr .git/rebase-apply &&
385 echo "---" >>failmail &&
386 test_must_fail git am <failmail &&
388 ! test -d .git/rebase-apply
391 test_expect_success
'am works from stdin in subdirectory' '
393 rm -fr .git/rebase-apply &&
395 git checkout first &&
401 git diff --exit-code second
404 test_expect_success
'am works from file (relative path given) in subdirectory' '
406 rm -fr .git/rebase-apply &&
408 git checkout first &&
414 git diff --exit-code second
417 test_expect_success
'am works from file (absolute path given) in subdirectory' '
419 rm -fr .git/rebase-apply &&
421 git checkout first &&
428 git diff --exit-code second
431 test_expect_success
'am --committer-date-is-author-date' '
432 rm -fr .git/rebase-apply &&
434 git checkout first &&
436 git am --committer-date-is-author-date patch1 &&
437 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
438 sed -ne "/^author /s/.*> //p" head1 >at &&
439 sed -ne "/^committer /s/.*> //p" head1 >ct &&
443 test_expect_success
'am without --committer-date-is-author-date' '
444 rm -fr .git/rebase-apply &&
446 git checkout first &&
449 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
450 sed -ne "/^author /s/.*> //p" head1 >at &&
451 sed -ne "/^committer /s/.*> //p" head1 >ct &&
455 # This checks for +0000 because TZ is set to UTC and that should
456 # show up when the current time is used. The date in message is set
457 # by test_tick that uses -0700 timezone; if this feature does not
458 # work, we will see that instead of +0000.
459 test_expect_success
'am --ignore-date' '
460 rm -fr .git/rebase-apply &&
462 git checkout first &&
464 git am --ignore-date patch1 &&
465 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
466 sed -ne "/^author /s/.*> //p" head1 >at &&
470 test_expect_success
'am into an unborn branch' '
471 git rev-parse first^{tree} >expected &&
472 rm -fr .git/rebase-apply &&
476 git format-patch --numbered-files -o subdir -1 first &&
484 git rev-parse HEAD^{tree} >../actual
486 test_cmp expected actual
489 test_expect_success
'am newline in subject' '
490 rm -fr .git/rebase-apply &&
492 git checkout first &&
494 sed -e "s/second/second \\\n foo/" patch1 >patchnl &&
495 git am <patchnl >output.out 2>&1 &&
496 test_i18ngrep "^Applying: second \\\n foo$" output.out
499 test_expect_success
'am -q is quiet' '
500 rm -fr .git/rebase-apply &&
502 git checkout first &&
504 git am -q <patch1 >output.out 2>&1 &&
508 test_expect_success
'am empty-file does not infloop' '
509 rm -fr .git/rebase-apply &&
513 { git am empty-file > actual 2>&1 && false || :; } &&
514 echo Patch format detection failed. >expected &&
515 test_cmp expected actual