3 test_description
='git am running'
10 Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy
11 eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
12 voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
13 kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
14 ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
15 tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
16 vero eos et accusam et justo duo dolores et ea rebum.
18 Duis autem vel eum iriure dolor in hendrerit in vulputate velit
19 esse molestie consequat, vel illum dolore eu feugiat nulla facilisis
20 at vero eros et accumsan et iusto odio dignissim qui blandit
21 praesent luptatum zzril delenit augue duis dolore te feugait nulla
25 Lorem ipsum dolor sit amet,
26 consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
27 laoreet dolore magna aliquam erat volutpat.
33 Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
34 lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
35 dolor in hendrerit in vulputate velit esse molestie consequat, vel illum
36 dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio
37 dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te
38 feugait nulla facilisi.
42 From foo@example.com Fri May 23 10:43:49 2008
45 Subject: Re: [RFC/PATCH] git-foo.sh
46 Date: Fri, 23 May 2008 05:23:42 +0200
48 Sometimes we have to find out that there's nothing left.
53 From MAILER-DAEMON Fri May 23 10:43:49 2008
54 Date: 23 May 2008 05:23:42 +0200
55 From: Mail System Internal Data <MAILER-DAEMON@example.com>
56 Subject: DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
57 Message-ID: <foo-0001@example.com>
59 This text is part of the internal format of your mail folder, and is not
60 a real message. It is created automatically by the mail system software.
61 If deleted, important folder data will be lost, and it will be re-created
62 with the data reset to initial values.
66 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected
68 test_expect_success setup
'
72 git commit -m first &&
77 git commit -s -F msg &&
79 git format-patch --stdout first >patch1 &&
80 sed -n -e "3,\$p" msg >file &&
83 git commit -m third &&
84 git format-patch --stdout first >patch2 &&
85 git checkout -b lorem &&
86 sed -n -e "11,\$p" msg >file &&
87 head -n 9 msg >>file &&
89 git commit -a -m "moved stuff" &&
90 echo goodbye >another &&
93 git commit -m "added another file" &&
94 git format-patch --stdout master >lorem-move.patch
101 test_expect_success
'am applies patch correctly' '
102 git checkout first &&
105 ! test -d .git/rebase-apply &&
106 test -z "$(git diff second)" &&
107 test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
108 test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
111 GIT_AUTHOR_NAME
="Another Thor"
112 GIT_AUTHOR_EMAIL
="a.thor@example.com"
113 GIT_COMMITTER_NAME
="Co M Miter"
114 GIT_COMMITTER_EMAIL
="c.miter@example.com"
115 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
118 test "$(git cat-file commit "$2" | grep "^
$1 ")" = \
119 "$(git cat-file commit "$3" | grep "^
$1 ")"
122 test_expect_success
'am changes committer and keeps author' '
124 git checkout first &&
126 ! test -d .git/rebase-apply &&
127 test "$(git rev-parse master^^)" = "$(git rev-parse HEAD^^)" &&
128 test -z "$(git diff master..HEAD)" &&
129 test -z "$(git diff master^..HEAD^)" &&
130 compare author master HEAD &&
131 compare author master^ HEAD^ &&
132 test "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" = \
133 "$(git log -1 --pretty=format:"%cn <%ce>" HEAD)"
136 test_expect_success
'am --signoff adds Signed-off-by: line' '
137 git checkout -b master2 first &&
138 git am --signoff <patch2 &&
139 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected &&
140 git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
141 test_cmp actual expected &&
142 echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected &&
143 git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
144 test_cmp actual expected
147 test_expect_success
'am stays in branch' '
148 test "refs/heads/master2" = "$(git symbolic-ref HEAD)"
151 test_expect_success
'am --signoff does not add Signed-off-by: line if already there' '
152 git format-patch --stdout HEAD^ >patch3 &&
153 sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2," patch3 >patch4
154 git checkout HEAD^ &&
155 git am --signoff patch4 &&
156 test "$(git cat-file commit HEAD | grep -c "^Signed-off-by:")" -eq 1
159 test_expect_success
'am without --keep removes Re: and [PATCH] stuff' '
160 test "$(git rev-parse HEAD)" = "$(git rev-parse master2)"
163 test_expect_success
'am --keep really keeps the subject' '
164 git checkout HEAD^ &&
165 git am --keep patch4 &&
166 ! test -d .git/rebase-apply &&
167 git cat-file commit HEAD |
168 fgrep "Re: Re: Re: [PATCH 1/5 v2] third"
171 test_expect_success
'am -3 falls back to 3-way merge' '
172 git checkout -b lorem2 master2 &&
173 sed -n -e "3,\$p" msg >file &&
174 head -n 9 msg >>file &&
177 git commit -m "copied stuff" &&
178 git am -3 lorem-move.patch &&
179 ! test -d .git/rebase-apply &&
180 test -z "$(git diff lorem)"
183 test_expect_success
'am pauses on conflict' '
184 git checkout lorem2^^ &&
185 test_must_fail git am lorem-move.patch &&
186 test -d .git/rebase-apply
189 test_expect_success
'am --skip works' '
191 ! test -d .git/rebase-apply &&
192 test -z "$(git diff lorem2^^ -- file)" &&
193 test goodbye = "$(cat another)"
196 test_expect_success
'am --resolved works' '
197 git checkout lorem2^^ &&
198 test_must_fail git am lorem-move.patch &&
199 test -d .git/rebase-apply &&
200 echo resolved >>file &&
203 ! test -d .git/rebase-apply &&
204 test goodbye = "$(cat another)"
207 test_expect_success
'am takes patches from a Pine mailbox' '
208 git checkout first &&
209 cat pine patch1 | git am &&
210 ! test -d .git/rebase-apply &&
211 test -z "$(git diff master^..HEAD)"
214 test_expect_success
'am fails on mail without patch' '
215 test_must_fail git am <failmail &&
216 rm -r .git/rebase-apply/
219 test_expect_success
'am fails on empty patch' '
220 echo "---" >>failmail &&
221 test_must_fail git am <failmail &&
223 ! test -d .git/rebase-apply
226 test_expect_success
'am works from stdin in subdirectory' '
228 git checkout first &&
234 test -z "$(git diff second)"
237 test_expect_success
'am works from file (relative path given) in subdirectory' '
239 git checkout first &&
245 test -z "$(git diff second)"
249 *MINGW
*) test_expect
=test_expect_failure
;;
250 *) test_expect
=test_expect_success
;;
252 $test_expect 'am works from file (absolute path given) in subdirectory' '
254 git checkout first &&
261 test -z "$(git diff second)"
264 test_expect_success
'am --committer-date-is-author-date' '
265 git checkout first &&
267 git am --committer-date-is-author-date patch1 &&
268 git cat-file commit HEAD | sed -e "/^$/q" >head1 &&
269 at=$(sed -ne "/^author /s/.*> //p" head1) &&
270 ct=$(sed -ne "/^committer /s/.*> //p" head1) &&
274 test_expect_success
'am without --committer-date-is-author-date' '
275 git checkout first &&
278 git cat-file commit HEAD | sed -e "/^$/q" >head1 &&
279 at=$(sed -ne "/^author /s/.*> //p" head1) &&
280 ct=$(sed -ne "/^committer /s/.*> //p" head1) &&
284 # This checks for +0000 because TZ is set to UTC and that should
285 # show up when the current time is used. The date in message is set
286 # by test_tick that uses -0700 timezone; if this feature does not
287 # work, we will see that instead of +0000.
288 test_expect_success
'am --ignore-date' '
289 git checkout first &&
291 git am --ignore-date patch1 &&
292 git cat-file commit HEAD | sed -e "/^$/q" >head1 &&
293 at=$(sed -ne "/^author /s/.*> //p" head1) &&
294 echo "$at" | grep "+0000"
297 test_expect_success
'am into an unborn branch' '
300 git format-patch --numbered-files -o subdir -1 first &&
307 cd subdir && git rev-parse HEAD^{tree}
309 test "z$result" = "z$(git rev-parse first^{tree})"