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 &&
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," 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\] third" actual
265 test_expect_success 'am -3 falls back to 3-way merge' '
266 rm -fr .git/rebase-apply &&
268 git checkout -b lorem2 master2 &&
269 sed -n -e "3,\$p" msg >file &&
270 head -n 9 msg >>file &&
273 git commit -m "copied stuff" &&
274 git am -3 lorem-move.patch &&
275 ! test -d .git/rebase-apply &&
276 git diff --exit-code lorem
279 test_expect_success 'am can rename a file' '
280 grep "^rename from" rename.patch &&
281 rm -fr .git/rebase-apply &&
283 git checkout lorem^0 &&
284 git am rename.patch &&
285 ! test -d .git/rebase-apply &&
286 git update-index --refresh &&
287 git diff --exit-code rename
290 test_expect_success 'am -3 can rename a file' '
291 grep "^rename from" rename.patch &&
292 rm -fr .git/rebase-apply &&
294 git checkout lorem^0 &&
295 git am -3 rename.patch &&
296 ! test -d .git/rebase-apply &&
297 git update-index --refresh &&
298 git diff --exit-code rename
301 test_expect_success 'am -3 can rename a file after falling back to 3-way merge' '
302 grep "^rename from" rename-add.patch &&
303 rm -fr .git/rebase-apply &&
305 git checkout lorem^0 &&
306 git am -3 rename-add.patch &&
307 ! test -d .git/rebase-apply &&
308 git update-index --refresh &&
309 git diff --exit-code rename
312 test_expect_success 'am -3 -q is quiet' '
313 rm -fr .git/rebase-apply &&
314 git checkout -f lorem2 &&
315 git reset master2 --hard &&
316 sed -n -e "3,\$p" msg >file &&
317 head -n 9 msg >>file &&
320 git commit -m "copied stuff" &&
321 git am -3 -q lorem-move.patch >output.out 2>&1 &&
325 test_expect_success 'am pauses on conflict' '
326 rm -fr .git/rebase-apply &&
328 git checkout lorem2^^ &&
329 test_must_fail git am lorem-move.patch &&
330 test -d .git/rebase-apply
333 test_expect_success 'am --skip works' '
334 echo goodbye >expected &&
336 ! test -d .git/rebase-apply &&
337 git diff --exit-code lorem2^^ -- file &&
338 test_cmp expected another
341 test_expect_success 'am --resolved works' '
342 echo goodbye >expected &&
343 rm -fr .git/rebase-apply &&
345 git checkout lorem2^^ &&
346 test_must_fail git am lorem-move.patch &&
347 test -d .git/rebase-apply &&
348 echo resolved >>file &&
351 ! test -d .git/rebase-apply &&
352 test_cmp expected another
355 test_expect_success 'am takes patches from a Pine mailbox' '
356 rm -fr .git/rebase-apply &&
358 git checkout first &&
359 cat pine patch1 | git am &&
360 ! test -d .git/rebase-apply &&
361 git diff --exit-code master^..HEAD
364 test_expect_success 'am fails on mail without patch' '
365 rm -fr .git/rebase-apply &&
367 test_must_fail git am <failmail &&
369 ! test -d .git/rebase-apply
372 test_expect_success 'am fails on empty patch' '
373 rm -fr .git/rebase-apply &&
375 echo "---" >>failmail &&
376 test_must_fail git am <failmail &&
378 ! test -d .git/rebase-apply
381 test_expect_success 'am works from stdin in subdirectory' '
383 rm -fr .git/rebase-apply &&
385 git checkout first &&
391 git diff --exit-code second
394 test_expect_success 'am works from file (relative path given) in subdirectory' '
396 rm -fr .git/rebase-apply &&
398 git checkout first &&
404 git diff --exit-code second
407 test_expect_success 'am works from file (absolute path given) in subdirectory' '
409 rm -fr .git/rebase-apply &&
411 git checkout first &&
418 git diff --exit-code second
421 test_expect_success 'am --committer-date-is-author-date' '
422 rm -fr .git/rebase-apply &&
424 git checkout first &&
426 git am --committer-date-is-author-date patch1 &&
427 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
428 sed -ne "/^author /s/.*> //p" head1 >at &&
429 sed -ne "/^committer /s/.*> //p" head1 >ct &&
433 test_expect_success 'am without --committer-date-is-author-date' '
434 rm -fr .git/rebase-apply &&
436 git checkout first &&
439 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
440 sed -ne "/^author /s/.*> //p" head1 >at &&
441 sed -ne "/^committer /s/.*> //p" head1 >ct &&
445 # This checks for +0000 because TZ is set to UTC and that should
446 # show up when the current time is used. The date in message is set
447 # by test_tick that uses -0700 timezone; if this feature does not
448 # work, we will see that instead of +0000.
449 test_expect_success 'am --ignore-date' '
450 rm -fr .git/rebase-apply &&
452 git checkout first &&
454 git am --ignore-date patch1 &&
455 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
456 sed -ne "/^author /s/.*> //p" head1 >at &&
460 test_expect_success 'am into an unborn branch' '
461 git rev-parse first^{tree} >expected &&
462 rm -fr .git/rebase-apply &&
466 git format-patch --numbered-files -o subdir -1 first &&
474 git rev-parse HEAD^{tree} >../actual
476 test_cmp expected actual
479 test_expect_success 'am newline in subject' '
480 rm -fr .git/rebase-apply &&
482 git checkout first &&
484 sed -e "s/second/second \\\n foo/" patch1 >patchnl &&
485 git am <patchnl >output.out 2>&1 &&
486 test_i18ngrep "^Applying: second \\\n foo$" output.out
489 test_expect_success 'am -q is quiet' '
490 rm -fr .git/rebase-apply &&
492 git checkout first &&
494 git am -q <patch1 >output.out 2>&1 &&