summaryrefslogtreecommitdiff
path: root/t/t4150-am.sh
blob: 722ae96cd5d320e3a8d5771e81d76165b3166b3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/bin/sh

test_description='git am running'

. ./test-lib.sh

cat >msg <<EOF
second

Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy
eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita
kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem
ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum.

	Duis autem vel eum iriure dolor in hendrerit in vulputate velit
	esse molestie consequat, vel illum dolore eu feugiat nulla facilisis
	at vero eros et accumsan et iusto odio dignissim qui blandit
	praesent luptatum zzril delenit augue duis dolore te feugait nulla
	facilisi.


Lorem ipsum dolor sit amet,
consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
laoreet dolore magna aliquam erat volutpat.

  git
  ---
  +++

Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
dolor in hendrerit in vulputate velit esse molestie consequat, vel illum
dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio
dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te
feugait nulla facilisi.
EOF

cat >failmail <<EOF
From foo@example.com Fri May 23 10:43:49 2008
From:	foo@example.com
To:	bar@example.com
Subject: Re: [RFC/PATCH] git-foo.sh
Date:	Fri, 23 May 2008 05:23:42 +0200

Sometimes we have to find out that there's nothing left.

EOF

cat >pine <<EOF
From MAILER-DAEMON Fri May 23 10:43:49 2008
Date: 23 May 2008 05:23:42 +0200
From: Mail System Internal Data <MAILER-DAEMON@example.com>
Subject: DON'T DELETE THIS MESSAGE -- FOLDER INTERNAL DATA
Message-ID: <foo-0001@example.com>

This text is part of the internal format of your mail folder, and is not
a real message.  It is created automatically by the mail system software.
If deleted, important folder data will be lost, and it will be re-created
with the data reset to initial values.

EOF

echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected

test_expect_success setup '
	echo hello >file &&
	git add file &&
	test_tick &&
	git commit -m first &&
	git tag first &&
	echo world >>file &&
	git add file &&
	test_tick &&
	git commit -s -F msg &&
	git tag second &&
	git format-patch --stdout first >patch1 &&
	sed -n -e "3,\$p" msg >file &&
	git add file &&
	test_tick &&
	git commit -m third &&
	git format-patch --stdout first >patch2	&&
	git checkout -b lorem &&
	sed -n -e "11,\$p" msg >file &&
	head -n 9 msg >>file &&
	test_tick &&
	git commit -a -m "moved stuff" &&
	echo goodbye >another &&
	git add another &&
	test_tick &&
	git commit -m "added another file" &&
	git format-patch --stdout master >lorem-move.patch
'

# reset time
unset test_tick
test_tick

test_expect_success 'am applies patch correctly' '
	git checkout first &&
	test_tick &&
	git am <patch1 &&
	! test -d .dotest &&
	test -z "$(git diff second)" &&
	test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
	test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
'

GIT_AUTHOR_NAME="Another Thor"
GIT_AUTHOR_EMAIL="a.thor@example.com"
GIT_COMMITTER_NAME="Co M Miter" 
GIT_COMMITTER_EMAIL="c.miter@example.com"
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL

compare () {
	test "$(git cat-file commit "$2" | grep "^$1 ")" = \
	     "$(git cat-file commit "$3" | grep "^$1 ")"
}

test_expect_success 'am changes committer and keeps author' '
	test_tick &&
	git checkout first &&
	git am patch2 &&
	! test -d .dotest &&
	test "$(git rev-parse master^^)" = "$(git rev-parse HEAD^^)" &&
	test -z "$(git diff master..HEAD)" &&
	test -z "$(git diff master^..HEAD^)" &&
	compare author master HEAD &&
	compare author master^ HEAD^ &&
	test "$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" = \
	     "$(git log -1 --pretty=format:"%cn <%ce>" HEAD)"
'

test_expect_success 'am --signoff adds Signed-off-by: line' '
	git checkout -b master2 first &&
	git am --signoff <patch2 &&
	echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >>expected &&
	git cat-file commit HEAD^ | grep "Signed-off-by:" >actual &&
	test_cmp actual expected &&
	echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" >expected &&
	git cat-file commit HEAD | grep "Signed-off-by:" >actual &&
	test_cmp actual expected
'

test_expect_success 'am stays in branch' '
	test "refs/heads/master2" = "$(git symbolic-ref HEAD)"
'

test_expect_success 'am --signoff does not add Signed-off-by: line if already there' '
	git format-patch --stdout HEAD^ >patch3 &&
	sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2," patch3 >patch4
	git checkout HEAD^ &&
	git am --signoff patch4 &&
	test "$(git cat-file commit HEAD | grep -c "^Signed-off-by:")" -eq 1
'

test_expect_success 'am without --keep removes Re: and [PATCH] stuff' '
	test "$(git rev-parse HEAD)" = "$(git rev-parse master2)"
'

test_expect_success 'am --keep really keeps the subject' '
	git checkout HEAD^ &&
	git am --keep patch4 &&
	! test -d .dotest &&
	git-cat-file commit HEAD |
		grep -q -F "Re: Re: Re: [PATCH 1/5 v2] third"
'

test_expect_success 'am -3 falls back to 3-way merge' '
	git checkout -b lorem2 master2 &&
	sed -n -e "3,\$p" msg >file &&
	head -n 9 msg >>file &&
	git add file &&
	test_tick &&
	git commit -m "copied stuff" &&
	git am -3 lorem-move.patch &&
	! test -d .dotest &&
	test -z "$(git diff lorem)"
'

test_expect_success 'am pauses on conflict' '
	git checkout lorem2^^ &&
	! git am lorem-move.patch &&
	test -d .dotest
'

test_expect_success 'am --skip works' '
	git am --skip &&
	! test -d .dotest &&
	test -z "$(git diff lorem2^^ -- file)" &&
	test goodbye = "$(cat another)"
'

test_expect_success 'am --resolved works' '
	git checkout lorem2^^ &&
	! git am lorem-move.patch &&
	test -d .dotest &&
	echo resolved >>file &&
	git add file &&
	git am --resolved &&
	! test -d .dotest &&
	test goodbye = "$(cat another)"
'

test_expect_success 'am takes patches from a Pine mailbox' '
	git checkout first &&
	cat pine patch1 | git am &&
	! test -d .dotest &&
	test -z "$(git diff master^..HEAD)"
'

test_expect_success 'am fails on mail without patch' '
	! git am <failmail &&
	rm -r .dotest/
'

test_expect_success 'am fails on empty patch' '
	echo "---" >>failmail &&
	! git am <failmail &&
	git am --skip &&
	! test -d .dotest
'

test_expect_success 'am works from stdin in subdirectory' '
	rm -fr subdir &&
	git checkout first &&
	(
		mkdir -p subdir &&
		cd subdir &&
		git am <../patch1
	) &&
	test -z "$(git diff second)"
'

test_expect_success 'am works from file (relative path given) in subdirectory' '
	rm -fr subdir &&
	git checkout first &&
	(
		mkdir -p subdir &&
		cd subdir &&
		git am ../patch1
	) &&
	test -z "$(git diff second)"
'

test_expect_success 'am works from file (absolute path given) in subdirectory' '
	rm -fr subdir &&
	git checkout first &&
	P=$(pwd) &&
	(
		mkdir -p subdir &&
		cd subdir &&
		git am "$P/patch1"
	) &&
	test -z "$(git diff second)"
'

test_done