]>
Commit | Line | Data |
---|---|---|
d551a488 MSO |
1 | #!/bin/sh |
2 | ||
3 | test_description='.mailmap configurations' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
bfdfa3d4 JN |
7 | fuzz_blame () { |
8 | sed " | |
9 | s/$_x05[0-9a-f][0-9a-f][0-9a-f]/OBJID/g | |
10 | s/$_x05[0-9a-f][0-9a-f]/OBJI/g | |
11 | s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g | |
12 | " "$@" | |
13 | } | |
14 | ||
d551a488 MSO |
15 | test_expect_success setup ' |
16 | echo one >one && | |
17 | git add one && | |
18 | test_tick && | |
19 | git commit -m initial && | |
20 | echo two >>one && | |
21 | git add one && | |
d8d2eb7d | 22 | test_tick && |
d551a488 MSO |
23 | git commit --author "nick1 <bugs@company.xx>" -m second |
24 | ' | |
25 | ||
26 | cat >expect <<\EOF | |
27 | A U Thor (1): | |
28 | initial | |
29 | ||
30 | nick1 (1): | |
31 | second | |
32 | ||
33 | EOF | |
34 | ||
35 | test_expect_success 'No mailmap' ' | |
36 | git shortlog HEAD >actual && | |
37 | test_cmp expect actual | |
38 | ' | |
39 | ||
40 | cat >expect <<\EOF | |
41 | Repo Guy (1): | |
42 | initial | |
43 | ||
44 | nick1 (1): | |
45 | second | |
46 | ||
47 | EOF | |
48 | ||
49 | test_expect_success 'default .mailmap' ' | |
50 | echo "Repo Guy <author@example.com>" > .mailmap && | |
51 | git shortlog HEAD >actual && | |
52 | test_cmp expect actual | |
53 | ' | |
54 | ||
55 | # Using a mailmap file in a subdirectory of the repo here, but | |
56 | # could just as well have been a file outside of the repository | |
57 | cat >expect <<\EOF | |
58 | Internal Guy (1): | |
59 | second | |
60 | ||
61 | Repo Guy (1): | |
62 | initial | |
63 | ||
64 | EOF | |
65 | test_expect_success 'mailmap.file set' ' | |
d8d2eb7d | 66 | mkdir -p internal_mailmap && |
d551a488 MSO |
67 | echo "Internal Guy <bugs@company.xx>" > internal_mailmap/.mailmap && |
68 | git config mailmap.file internal_mailmap/.mailmap && | |
69 | git shortlog HEAD >actual && | |
70 | test_cmp expect actual | |
71 | ' | |
72 | ||
73 | cat >expect <<\EOF | |
74 | External Guy (1): | |
75 | initial | |
76 | ||
77 | Internal Guy (1): | |
78 | second | |
79 | ||
80 | EOF | |
81 | test_expect_success 'mailmap.file override' ' | |
82 | echo "External Guy <author@example.com>" >> internal_mailmap/.mailmap && | |
83 | git config mailmap.file internal_mailmap/.mailmap && | |
84 | git shortlog HEAD >actual && | |
85 | test_cmp expect actual | |
86 | ' | |
87 | ||
88 | cat >expect <<\EOF | |
89 | Repo Guy (1): | |
90 | initial | |
91 | ||
92 | nick1 (1): | |
93 | second | |
94 | ||
95 | EOF | |
96 | ||
7be8b3ba | 97 | test_expect_success 'mailmap.file non-existent' ' |
d551a488 MSO |
98 | rm internal_mailmap/.mailmap && |
99 | rmdir internal_mailmap && | |
100 | git shortlog HEAD >actual && | |
101 | test_cmp expect actual | |
102 | ' | |
103 | ||
d8d2eb7d JM |
104 | cat >expect <<\EOF |
105 | Internal Guy (1): | |
106 | second | |
107 | ||
108 | Repo Guy (1): | |
109 | initial | |
110 | ||
111 | EOF | |
112 | ||
113 | test_expect_success 'name entry after email entry' ' | |
114 | mkdir -p internal_mailmap && | |
115 | echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap && | |
116 | echo "Internal Guy <bugs@company.xx>" >>internal_mailmap/.mailmap && | |
3e3e1ef5 | 117 | git shortlog HEAD >actual && |
d8d2eb7d JM |
118 | test_cmp expect actual |
119 | ' | |
120 | ||
121 | cat >expect <<\EOF | |
122 | Internal Guy (1): | |
123 | second | |
124 | ||
125 | Repo Guy (1): | |
126 | initial | |
127 | ||
128 | EOF | |
129 | ||
130 | test_expect_success 'name entry after email entry, case-insensitive' ' | |
131 | mkdir -p internal_mailmap && | |
132 | echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap && | |
133 | echo "Internal Guy <BUGS@Company.xx>" >>internal_mailmap/.mailmap && | |
3e3e1ef5 | 134 | git shortlog HEAD >actual && |
d8d2eb7d JM |
135 | test_cmp expect actual |
136 | ' | |
137 | ||
d551a488 MSO |
138 | cat >expect <<\EOF |
139 | A U Thor (1): | |
140 | initial | |
141 | ||
142 | nick1 (1): | |
143 | second | |
144 | ||
145 | EOF | |
146 | test_expect_success 'No mailmap files, but configured' ' | |
d8d2eb7d | 147 | rm -f .mailmap internal_mailmap/.mailmap && |
d551a488 MSO |
148 | git shortlog HEAD >actual && |
149 | test_cmp expect actual | |
150 | ' | |
151 | ||
08610900 JK |
152 | test_expect_success 'setup mailmap blob tests' ' |
153 | git checkout -b map && | |
154 | test_when_finished "git checkout master" && | |
155 | cat >just-bugs <<-\EOF && | |
156 | Blob Guy <bugs@company.xx> | |
157 | EOF | |
158 | cat >both <<-\EOF && | |
159 | Blob Guy <author@example.com> | |
160 | Blob Guy <bugs@company.xx> | |
161 | EOF | |
162 | git add just-bugs both && | |
163 | git commit -m "my mailmaps" && | |
164 | echo "Repo Guy <author@example.com>" >.mailmap && | |
165 | echo "Internal Guy <author@example.com>" >internal.map | |
166 | ' | |
167 | ||
168 | test_expect_success 'mailmap.blob set' ' | |
169 | cat >expect <<-\EOF && | |
170 | Blob Guy (1): | |
171 | second | |
172 | ||
173 | Repo Guy (1): | |
174 | initial | |
175 | ||
176 | EOF | |
177 | git -c mailmap.blob=map:just-bugs shortlog HEAD >actual && | |
178 | test_cmp expect actual | |
179 | ' | |
180 | ||
181 | test_expect_success 'mailmap.blob overrides .mailmap' ' | |
182 | cat >expect <<-\EOF && | |
183 | Blob Guy (2): | |
184 | initial | |
185 | second | |
186 | ||
187 | EOF | |
188 | git -c mailmap.blob=map:both shortlog HEAD >actual && | |
189 | test_cmp expect actual | |
190 | ' | |
191 | ||
192 | test_expect_success 'mailmap.file overrides mailmap.blob' ' | |
193 | cat >expect <<-\EOF && | |
194 | Blob Guy (1): | |
195 | second | |
196 | ||
197 | Internal Guy (1): | |
198 | initial | |
199 | ||
200 | EOF | |
201 | git \ | |
202 | -c mailmap.blob=map:both \ | |
203 | -c mailmap.file=internal.map \ | |
204 | shortlog HEAD >actual && | |
205 | test_cmp expect actual | |
206 | ' | |
207 | ||
208 | test_expect_success 'mailmap.blob can be missing' ' | |
209 | cat >expect <<-\EOF && | |
210 | Repo Guy (1): | |
211 | initial | |
212 | ||
213 | nick1 (1): | |
214 | second | |
215 | ||
216 | EOF | |
217 | git -c mailmap.blob=map:nonexistent shortlog HEAD >actual && | |
218 | test_cmp expect actual | |
219 | ' | |
220 | ||
8c473cec JK |
221 | test_expect_success 'mailmap.blob defaults to off in non-bare repo' ' |
222 | git init non-bare && | |
223 | ( | |
224 | cd non-bare && | |
225 | test_commit one .mailmap "Fake Name <author@example.com>" && | |
226 | echo " 1 Fake Name" >expect && | |
227 | git shortlog -ns HEAD >actual && | |
228 | test_cmp expect actual && | |
229 | rm .mailmap && | |
230 | echo " 1 A U Thor" >expect && | |
231 | git shortlog -ns HEAD >actual && | |
232 | test_cmp expect actual | |
233 | ) | |
234 | ' | |
235 | ||
236 | test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' ' | |
237 | git clone --bare non-bare bare && | |
238 | ( | |
239 | cd bare && | |
240 | echo " 1 Fake Name" >expect && | |
241 | git shortlog -ns HEAD >actual && | |
242 | test_cmp expect actual | |
243 | ) | |
244 | ' | |
245 | ||
08610900 JK |
246 | test_expect_success 'cleanup after mailmap.blob tests' ' |
247 | rm -f .mailmap | |
248 | ' | |
249 | ||
8c381151 | 250 | test_expect_success 'single-character name' ' |
109025b4 ES |
251 | echo " 1 A <author@example.com>" >expect && |
252 | echo " 1 nick1 <bugs@company.xx>" >>expect && | |
253 | echo "A <author@example.com>" >.mailmap && | |
254 | test_when_finished "rm .mailmap" && | |
255 | git shortlog -es HEAD >actual && | |
256 | test_cmp expect actual | |
3aff56dd ES |
257 | ' |
258 | ||
259 | test_expect_failure 'preserve canonical email case' ' | |
260 | echo " 1 A U Thor <AUTHOR@example.com>" >expect && | |
261 | echo " 1 nick1 <bugs@company.xx>" >>expect && | |
262 | echo "<AUTHOR@example.com> <author@example.com>" >.mailmap && | |
263 | test_when_finished "rm .mailmap" && | |
264 | git shortlog -es HEAD >actual && | |
265 | test_cmp expect actual | |
109025b4 ES |
266 | ' |
267 | ||
d20d654f MSO |
268 | # Extended mailmap configurations should give us the following output for shortlog |
269 | cat >expect <<\EOF | |
270 | A U Thor <author@example.com> (1): | |
271 | initial | |
272 | ||
273 | CTO <cto@company.xx> (1): | |
274 | seventh | |
275 | ||
276 | Other Author <other@author.xx> (2): | |
277 | third | |
278 | fourth | |
279 | ||
280 | Santa Claus <santa.claus@northpole.xx> (2): | |
281 | fifth | |
282 | sixth | |
283 | ||
284 | Some Dude <some@dude.xx> (1): | |
285 | second | |
286 | ||
287 | EOF | |
288 | ||
289 | test_expect_success 'Shortlog output (complex mapping)' ' | |
290 | echo three >>one && | |
291 | git add one && | |
292 | test_tick && | |
293 | git commit --author "nick2 <bugs@company.xx>" -m third && | |
294 | ||
295 | echo four >>one && | |
296 | git add one && | |
297 | test_tick && | |
298 | git commit --author "nick2 <nick2@company.xx>" -m fourth && | |
299 | ||
300 | echo five >>one && | |
301 | git add one && | |
302 | test_tick && | |
303 | git commit --author "santa <me@company.xx>" -m fifth && | |
304 | ||
305 | echo six >>one && | |
306 | git add one && | |
307 | test_tick && | |
308 | git commit --author "claus <me@company.xx>" -m sixth && | |
309 | ||
310 | echo seven >>one && | |
311 | git add one && | |
312 | test_tick && | |
313 | git commit --author "CTO <cto@coompany.xx>" -m seventh && | |
314 | ||
d8d2eb7d | 315 | mkdir -p internal_mailmap && |
d20d654f MSO |
316 | echo "Committed <committer@example.com>" > internal_mailmap/.mailmap && |
317 | echo "<cto@company.xx> <cto@coompany.xx>" >> internal_mailmap/.mailmap && | |
318 | echo "Some Dude <some@dude.xx> nick1 <bugs@company.xx>" >> internal_mailmap/.mailmap && | |
319 | echo "Other Author <other@author.xx> nick2 <bugs@company.xx>" >> internal_mailmap/.mailmap && | |
320 | echo "Other Author <other@author.xx> <nick2@company.xx>" >> internal_mailmap/.mailmap && | |
321 | echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap && | |
322 | echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap && | |
323 | ||
324 | git shortlog -e HEAD >actual && | |
325 | test_cmp expect actual | |
326 | ||
327 | ' | |
328 | ||
329 | # git log with --pretty format which uses the name and email mailmap placemarkers | |
330 | cat >expect <<\EOF | |
331 | Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx> | |
332 | Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com> | |
333 | ||
334 | Author claus <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx> | |
335 | Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com> | |
336 | ||
337 | Author santa <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx> | |
338 | Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com> | |
339 | ||
340 | Author nick2 <nick2@company.xx> maps to Other Author <other@author.xx> | |
341 | Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com> | |
342 | ||
343 | Author nick2 <bugs@company.xx> maps to Other Author <other@author.xx> | |
344 | Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com> | |
345 | ||
346 | Author nick1 <bugs@company.xx> maps to Some Dude <some@dude.xx> | |
347 | Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com> | |
348 | ||
349 | Author A U Thor <author@example.com> maps to A U Thor <author@example.com> | |
350 | Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com> | |
351 | EOF | |
352 | ||
353 | test_expect_success 'Log output (complex mapping)' ' | |
354 | git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual && | |
355 | test_cmp expect actual | |
356 | ' | |
357 | ||
d2074343 AP |
358 | cat >expect <<\EOF |
359 | Author: CTO <cto@company.xx> | |
360 | Author: Santa Claus <santa.claus@northpole.xx> | |
361 | Author: Santa Claus <santa.claus@northpole.xx> | |
362 | Author: Other Author <other@author.xx> | |
363 | Author: Other Author <other@author.xx> | |
364 | Author: Some Dude <some@dude.xx> | |
365 | Author: A U Thor <author@example.com> | |
366 | EOF | |
d72fbe81 | 367 | |
d2074343 AP |
368 | test_expect_success 'Log output with --use-mailmap' ' |
369 | git log --use-mailmap | grep Author >actual && | |
370 | test_cmp expect actual | |
371 | ' | |
372 | ||
e6bb5f78 AP |
373 | cat >expect <<\EOF |
374 | Author: CTO <cto@company.xx> | |
375 | Author: Santa Claus <santa.claus@northpole.xx> | |
376 | Author: Santa Claus <santa.claus@northpole.xx> | |
377 | Author: Other Author <other@author.xx> | |
378 | Author: Other Author <other@author.xx> | |
379 | Author: Some Dude <some@dude.xx> | |
380 | Author: A U Thor <author@example.com> | |
381 | EOF | |
382 | ||
383 | test_expect_success 'Log output with log.mailmap' ' | |
384 | git -c log.mailmap=True log | grep Author >actual && | |
385 | test_cmp expect actual | |
386 | ' | |
387 | ||
d72fbe81 AP |
388 | cat >expect <<\EOF |
389 | Author: Santa Claus <santa.claus@northpole.xx> | |
390 | Author: Santa Claus <santa.claus@northpole.xx> | |
391 | EOF | |
392 | ||
393 | test_expect_success 'Grep author with --use-mailmap' ' | |
394 | git log --use-mailmap --author Santa | grep Author >actual && | |
395 | test_cmp expect actual | |
396 | ' | |
e6bb5f78 AP |
397 | cat >expect <<\EOF |
398 | Author: Santa Claus <santa.claus@northpole.xx> | |
399 | Author: Santa Claus <santa.claus@northpole.xx> | |
400 | EOF | |
401 | ||
402 | test_expect_success 'Grep author with log.mailmap' ' | |
403 | git -c log.mailmap=True log --author Santa | grep Author >actual && | |
404 | test_cmp expect actual | |
405 | ' | |
d72fbe81 AP |
406 | |
407 | >expect | |
408 | ||
409 | test_expect_success 'Only grep replaced author with --use-mailmap' ' | |
410 | git log --use-mailmap --author "<cto@coompany.xx>" >actual && | |
411 | test_cmp expect actual | |
412 | ' | |
413 | ||
d20d654f MSO |
414 | # git blame |
415 | cat >expect <<\EOF | |
bfdfa3d4 JN |
416 | ^OBJI (A U Thor DATE 1) one |
417 | OBJID (Some Dude DATE 2) two | |
418 | OBJID (Other Author DATE 3) three | |
419 | OBJID (Other Author DATE 4) four | |
420 | OBJID (Santa Claus DATE 5) five | |
421 | OBJID (Santa Claus DATE 6) six | |
422 | OBJID (CTO DATE 7) seven | |
d20d654f | 423 | EOF |
d20d654f MSO |
424 | test_expect_success 'Blame output (complex mapping)' ' |
425 | git blame one >actual && | |
bfdfa3d4 JN |
426 | fuzz_blame actual >actual.fuzz && |
427 | test_cmp expect actual.fuzz | |
d20d654f MSO |
428 | ' |
429 | ||
d551a488 | 430 | test_done |