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 &&
100 sed -n -e "3,\$p" msg >file &&
103 git commit -m third &&
105 git format-patch --stdout first >patch2 &&
107 git checkout -b lorem &&
108 sed -n -e "11,\$p" msg >file &&
109 head -n 9 msg >>file &&
111 git commit -a -m "moved stuff" &&
113 echo goodbye >another &&
116 git commit -m "added another file" &&
118 git format-patch --stdout master >lorem-move.patch &&
124 test_expect_success 'am applies patch correctly' '
125 rm -fr .git/rebase-apply &&
127 git checkout first &&
130 ! test -d .git/rebase-apply &&
131 git diff --exit-code second &&
132 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
133 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
136 test_expect_success 'am applies patch e-mail not in a mbox' '
137 rm -fr .git/rebase-apply &&
139 git checkout first &&
141 ! test -d .git/rebase-apply &&
142 git diff --exit-code second &&
143 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
144 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
147 test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '
148 rm -fr .git/rebase-apply &&
150 git checkout first &&
151 git am patch1-crlf.eml &&
152 ! test -d .git/rebase-apply &&
153 git diff --exit-code second &&
154 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
155 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
158 test_expect_success 'setup: new author and committer' '
159 GIT_AUTHOR_NAME="Another Thor" &&
160 GIT_AUTHOR_EMAIL="a.thor@example.com" &&
161 GIT_COMMITTER_NAME="Co M Miter" &&
162 GIT_COMMITTER_EMAIL="c.miter@example.com" &&
163 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
167 a=$(git cat-file commit "$2" | grep "^$1 ") &&
168 b=$(git cat-file commit "$3" | grep "^$1 ") &&
172 test_expect_success 'am changes committer and keeps author' '
174 rm -fr .git/rebase-apply &&
176 git checkout first &&
178 ! test -d .git/rebase-apply &&
179 test "$(git rev-parse master^^)" = "$(git rev-parse HEAD^^)" &&
180 git diff --exit-code master..HEAD &&
181 git diff --exit-code master^..HEAD^ &&
182 compare author master HEAD &&
183 compare author master^ HEAD^ &&
184 test "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" = \
185 "$(git log -1 --pretty=format:"%cn <%ce>" HEAD)"
188 test_expect_success 'am --signoff adds Signed-off-by: line' '
189 rm -fr .git/rebase-apply &&
191 git checkout -b master2 first &&
192 git am --signoff <patch2 &&
193 printf "%s\n" "$signoff" >expected &&
194 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected &&
195 git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
196 test_cmp expected actual &&
197 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected &&
198 git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
199 test_cmp expected actual
202 test_expect_success 'am stays in branch' '
203 echo refs/heads/master2 >expected &&
204 git symbolic-ref HEAD >actual &&
205 test_cmp expected actual
208 test_expect_success 'am --signoff does not add Signed-off-by: line if already there' '
209 git format-patch --stdout HEAD^ >patch3 &&
210 sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2," patch3 >patch4
211 rm -fr .git/rebase-apply &&
213 git checkout HEAD^ &&
214 git am --signoff patch4 &&
215 git cat-file commit HEAD >actual &&
216 test $(grep -c "^Signed-off-by:" actual) -eq 1
219 test_expect_success 'am without --keep removes Re: and [PATCH] stuff' '
220 git rev-parse HEAD >expected &&
221 git rev-parse master2 >actual &&
222 test_cmp expected actual
225 test_expect_success 'am --keep really keeps the subject' '
226 rm -fr .git/rebase-apply &&
228 git checkout HEAD^ &&
229 git am --keep patch4 &&
230 ! test -d .git/rebase-apply &&
231 git cat-file commit HEAD >actual &&
232 grep "Re: Re: Re: \[PATCH 1/5 v2\] third" actual
235 test_expect_success 'am -3 falls back to 3-way merge' '
236 rm -fr .git/rebase-apply &&
238 git checkout -b lorem2 master2 &&
239 sed -n -e "3,\$p" msg >file &&
240 head -n 9 msg >>file &&
243 git commit -m "copied stuff" &&
244 git am -3 lorem-move.patch &&
245 ! test -d .git/rebase-apply &&
246 git diff --exit-code lorem
249 test_expect_success 'am -3 -q is quiet' '
250 rm -fr .git/rebase-apply &&
251 git reset master2 --hard &&
252 sed -n -e "3,\$p" msg >file &&
253 head -n 9 msg >>file &&
256 git commit -m "copied stuff" &&
257 git am -3 -q lorem-move.patch >output.out 2>&1 &&
261 test_expect_success 'am pauses on conflict' '
262 rm -fr .git/rebase-apply &&
264 git checkout lorem2^^ &&
265 test_must_fail git am lorem-move.patch &&
266 test -d .git/rebase-apply
269 test_expect_success 'am --skip works' '
270 echo goodbye >expected &&
272 ! test -d .git/rebase-apply &&
273 git diff --exit-code lorem2^^ -- file &&
274 test_cmp expected another
277 test_expect_success 'am --resolved works' '
278 echo goodbye >expected &&
279 rm -fr .git/rebase-apply &&
281 git checkout lorem2^^ &&
282 test_must_fail git am lorem-move.patch &&
283 test -d .git/rebase-apply &&
284 echo resolved >>file &&
287 ! test -d .git/rebase-apply &&
288 test_cmp expected another
291 test_expect_success 'am takes patches from a Pine mailbox' '
292 rm -fr .git/rebase-apply &&
294 git checkout first &&
295 cat pine patch1 | git am &&
296 ! test -d .git/rebase-apply &&
297 git diff --exit-code master^..HEAD
300 test_expect_success 'am fails on mail without patch' '
301 rm -fr .git/rebase-apply &&
303 test_must_fail git am <failmail &&
305 ! test -d .git/rebase-apply
308 test_expect_success 'am fails on empty patch' '
309 rm -fr .git/rebase-apply &&
311 echo "---" >>failmail &&
312 test_must_fail git am <failmail &&
314 ! test -d .git/rebase-apply
317 test_expect_success 'am works from stdin in subdirectory' '
319 rm -fr .git/rebase-apply &&
321 git checkout first &&
327 git diff --exit-code second
330 test_expect_success 'am works from file (relative path given) in subdirectory' '
332 rm -fr .git/rebase-apply &&
334 git checkout first &&
340 git diff --exit-code second
343 test_expect_success 'am works from file (absolute path given) in subdirectory' '
345 rm -fr .git/rebase-apply &&
347 git checkout first &&
354 git diff --exit-code second
357 test_expect_success 'am --committer-date-is-author-date' '
358 rm -fr .git/rebase-apply &&
360 git checkout first &&
362 git am --committer-date-is-author-date patch1 &&
363 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
364 sed -ne "/^author /s/.*> //p" head1 >at &&
365 sed -ne "/^committer /s/.*> //p" head1 >ct &&
369 test_expect_success 'am without --committer-date-is-author-date' '
370 rm -fr .git/rebase-apply &&
372 git checkout first &&
375 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
376 sed -ne "/^author /s/.*> //p" head1 >at &&
377 sed -ne "/^committer /s/.*> //p" head1 >ct &&
381 # This checks for +0000 because TZ is set to UTC and that should
382 # show up when the current time is used. The date in message is set
383 # by test_tick that uses -0700 timezone; if this feature does not
384 # work, we will see that instead of +0000.
385 test_expect_success 'am --ignore-date' '
386 rm -fr .git/rebase-apply &&
388 git checkout first &&
390 git am --ignore-date patch1 &&
391 git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
392 sed -ne "/^author /s/.*> //p" head1 >at &&
396 test_expect_success 'am into an unborn branch' '
397 git rev-parse first^{tree} >expected &&
398 rm -fr .git/rebase-apply &&
402 git format-patch --numbered-files -o subdir -1 first &&
410 git rev-parse HEAD^{tree} >../actual
412 test_cmp expected actual
415 test_expect_success 'am newline in subject' '
416 rm -fr .git/rebase-apply &&
418 git checkout first &&
420 sed -e "s/second/second \\\n foo/" patch1 >patchnl &&
421 git am <patchnl >output.out 2>&1 &&
422 grep "^Applying: second \\\n foo$" output.out
425 test_expect_success 'am -q is quiet' '
426 rm -fr .git/rebase-apply &&
428 git checkout first &&
430 git am -q <patch1 >output.out 2>&1 &&