]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4203-mailmap.sh
8a2f8984f6225dfe7c6ef7764e4f29ec8b195fb6
[thirdparty/git.git] / t / t4203-mailmap.sh
1 #!/bin/sh
2
3 test_description='.mailmap configurations'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 fuzz_blame () {
11 sed "
12 s/$_x05[0-9a-f][0-9a-f][0-9a-f]/OBJID/g
13 s/$_x05[0-9a-f][0-9a-f]/OBJI/g
14 s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
15 " "$@"
16 }
17
18 test_expect_success setup '
19 cat >contacts <<- EOF &&
20 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
21 nick1 <bugs@company.xx>
22 EOF
23
24 echo one >one &&
25 git add one &&
26 test_tick &&
27 git commit -m initial &&
28 echo two >>one &&
29 git add one &&
30 test_tick &&
31 git commit --author "nick1 <bugs@company.xx>" -m second
32 '
33
34 test_expect_success 'check-mailmap no arguments' '
35 test_must_fail git check-mailmap
36 '
37
38 test_expect_success 'check-mailmap arguments' '
39 cat >expect <<- EOF &&
40 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
41 nick1 <bugs@company.xx>
42 EOF
43 git check-mailmap \
44 "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" \
45 "nick1 <bugs@company.xx>" >actual &&
46 test_cmp expect actual
47 '
48
49 test_expect_success 'check-mailmap --stdin' '
50 cat >expect <<- EOF &&
51 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
52 nick1 <bugs@company.xx>
53 EOF
54 git check-mailmap --stdin <contacts >actual &&
55 test_cmp expect actual
56 '
57
58 test_expect_success 'check-mailmap --stdin arguments' '
59 cat >expect <<-\EOF &&
60 Internal Guy <bugs@company.xy>
61 EOF
62 cat <contacts >>expect &&
63 git check-mailmap --stdin "Internal Guy <bugs@company.xy>" \
64 <contacts >actual &&
65 test_cmp expect actual
66 '
67
68 test_expect_success 'check-mailmap bogus contact' '
69 test_must_fail git check-mailmap bogus
70 '
71
72 cat >expect << EOF
73 $GIT_AUTHOR_NAME (1):
74 initial
75
76 nick1 (1):
77 second
78
79 EOF
80
81 test_expect_success 'No mailmap' '
82 git shortlog HEAD >actual &&
83 test_cmp expect actual
84 '
85
86 cat >expect <<\EOF
87 Repo Guy (1):
88 initial
89
90 nick1 (1):
91 second
92
93 EOF
94
95 test_expect_success 'default .mailmap' '
96 echo "Repo Guy <$GIT_AUTHOR_EMAIL>" > .mailmap &&
97 git shortlog HEAD >actual &&
98 test_cmp expect actual
99 '
100
101 # Using a mailmap file in a subdirectory of the repo here, but
102 # could just as well have been a file outside of the repository
103 cat >expect <<\EOF
104 Internal Guy (1):
105 second
106
107 Repo Guy (1):
108 initial
109
110 EOF
111 test_expect_success 'mailmap.file set' '
112 mkdir -p internal_mailmap &&
113 echo "Internal Guy <bugs@company.xx>" > internal_mailmap/.mailmap &&
114 git config mailmap.file internal_mailmap/.mailmap &&
115 git shortlog HEAD >actual &&
116 test_cmp expect actual
117 '
118
119 cat >expect <<\EOF
120 External Guy (1):
121 initial
122
123 Internal Guy (1):
124 second
125
126 EOF
127 test_expect_success 'mailmap.file override' '
128 echo "External Guy <$GIT_AUTHOR_EMAIL>" >> internal_mailmap/.mailmap &&
129 git config mailmap.file internal_mailmap/.mailmap &&
130 git shortlog HEAD >actual &&
131 test_cmp expect actual
132 '
133
134 cat >expect <<\EOF
135 Repo Guy (1):
136 initial
137
138 nick1 (1):
139 second
140
141 EOF
142
143 test_expect_success 'mailmap.file non-existent' '
144 rm internal_mailmap/.mailmap &&
145 rmdir internal_mailmap &&
146 git shortlog HEAD >actual &&
147 test_cmp expect actual
148 '
149
150 cat >expect <<\EOF
151 Internal Guy (1):
152 second
153
154 Repo Guy (1):
155 initial
156
157 EOF
158
159 test_expect_success 'name entry after email entry' '
160 mkdir -p internal_mailmap &&
161 echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap &&
162 echo "Internal Guy <bugs@company.xx>" >>internal_mailmap/.mailmap &&
163 git shortlog HEAD >actual &&
164 test_cmp expect actual
165 '
166
167 cat >expect <<\EOF
168 Internal Guy (1):
169 second
170
171 Repo Guy (1):
172 initial
173
174 EOF
175
176 test_expect_success 'name entry after email entry, case-insensitive' '
177 mkdir -p internal_mailmap &&
178 echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap &&
179 echo "Internal Guy <BUGS@Company.xx>" >>internal_mailmap/.mailmap &&
180 git shortlog HEAD >actual &&
181 test_cmp expect actual
182 '
183
184 cat >expect << EOF
185 $GIT_AUTHOR_NAME (1):
186 initial
187
188 nick1 (1):
189 second
190
191 EOF
192 test_expect_success 'No mailmap files, but configured' '
193 rm -f .mailmap internal_mailmap/.mailmap &&
194 git shortlog HEAD >actual &&
195 test_cmp expect actual
196 '
197
198 test_expect_success 'setup mailmap blob tests' '
199 git checkout -b map &&
200 test_when_finished "git checkout master" &&
201 cat >just-bugs <<- EOF &&
202 Blob Guy <bugs@company.xx>
203 EOF
204 cat >both <<- EOF &&
205 Blob Guy <$GIT_AUTHOR_EMAIL>
206 Blob Guy <bugs@company.xx>
207 EOF
208 printf "Tricky Guy <$GIT_AUTHOR_EMAIL>" >no-newline &&
209 git add just-bugs both no-newline &&
210 git commit -m "my mailmaps" &&
211 echo "Repo Guy <$GIT_AUTHOR_EMAIL>" >.mailmap &&
212 echo "Internal Guy <$GIT_AUTHOR_EMAIL>" >internal.map
213 '
214
215 test_expect_success 'mailmap.blob set' '
216 cat >expect <<-\EOF &&
217 Blob Guy (1):
218 second
219
220 Repo Guy (1):
221 initial
222
223 EOF
224 git -c mailmap.blob=map:just-bugs shortlog HEAD >actual &&
225 test_cmp expect actual
226 '
227
228 test_expect_success 'mailmap.blob overrides .mailmap' '
229 cat >expect <<-\EOF &&
230 Blob Guy (2):
231 initial
232 second
233
234 EOF
235 git -c mailmap.blob=map:both shortlog HEAD >actual &&
236 test_cmp expect actual
237 '
238
239 test_expect_success 'mailmap.file overrides mailmap.blob' '
240 cat >expect <<-\EOF &&
241 Blob Guy (1):
242 second
243
244 Internal Guy (1):
245 initial
246
247 EOF
248 git \
249 -c mailmap.blob=map:both \
250 -c mailmap.file=internal.map \
251 shortlog HEAD >actual &&
252 test_cmp expect actual
253 '
254
255 test_expect_success 'mailmap.blob can be missing' '
256 cat >expect <<-\EOF &&
257 Repo Guy (1):
258 initial
259
260 nick1 (1):
261 second
262
263 EOF
264 git -c mailmap.blob=map:nonexistent shortlog HEAD >actual &&
265 test_cmp expect actual
266 '
267
268 test_expect_success 'mailmap.blob defaults to off in non-bare repo' '
269 git init non-bare &&
270 (
271 cd non-bare &&
272 test_commit one .mailmap "Fake Name <$GIT_AUTHOR_EMAIL>" &&
273 echo " 1 Fake Name" >expect &&
274 git shortlog -ns HEAD >actual &&
275 test_cmp expect actual &&
276 rm .mailmap &&
277 echo " 1 $GIT_AUTHOR_NAME" >expect &&
278 git shortlog -ns HEAD >actual &&
279 test_cmp expect actual
280 )
281 '
282
283 test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' '
284 git clone --bare non-bare bare &&
285 (
286 cd bare &&
287 echo " 1 Fake Name" >expect &&
288 git shortlog -ns HEAD >actual &&
289 test_cmp expect actual
290 )
291 '
292
293 test_expect_success 'mailmap.blob can handle blobs without trailing newline' '
294 cat >expect <<-\EOF &&
295 Tricky Guy (1):
296 initial
297
298 nick1 (1):
299 second
300
301 EOF
302 git -c mailmap.blob=map:no-newline shortlog HEAD >actual &&
303 test_cmp expect actual
304 '
305
306 test_expect_success 'cleanup after mailmap.blob tests' '
307 rm -f .mailmap
308 '
309
310 test_expect_success 'single-character name' '
311 echo " 1 A <$GIT_AUTHOR_EMAIL>" >expect &&
312 echo " 1 nick1 <bugs@company.xx>" >>expect &&
313 echo "A <$GIT_AUTHOR_EMAIL>" >.mailmap &&
314 test_when_finished "rm .mailmap" &&
315 git shortlog -es HEAD >actual &&
316 test_cmp expect actual
317 '
318
319 test_expect_success 'preserve canonical email case' '
320 echo " 1 $GIT_AUTHOR_NAME <AUTHOR@example.com>" >expect &&
321 echo " 1 nick1 <bugs@company.xx>" >>expect &&
322 echo "<AUTHOR@example.com> <$GIT_AUTHOR_EMAIL>" >.mailmap &&
323 test_when_finished "rm .mailmap" &&
324 git shortlog -es HEAD >actual &&
325 test_cmp expect actual
326 '
327
328 # Extended mailmap configurations should give us the following output for shortlog
329 cat >expect << EOF
330 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1):
331 initial
332
333 CTO <cto@company.xx> (1):
334 seventh
335
336 Other Author <other@author.xx> (2):
337 third
338 fourth
339
340 Santa Claus <santa.claus@northpole.xx> (2):
341 fifth
342 sixth
343
344 Some Dude <some@dude.xx> (1):
345 second
346
347 EOF
348
349 test_expect_success 'Shortlog output (complex mapping)' '
350 echo three >>one &&
351 git add one &&
352 test_tick &&
353 git commit --author "nick2 <bugs@company.xx>" -m third &&
354
355 echo four >>one &&
356 git add one &&
357 test_tick &&
358 git commit --author "nick2 <nick2@company.xx>" -m fourth &&
359
360 echo five >>one &&
361 git add one &&
362 test_tick &&
363 git commit --author "santa <me@company.xx>" -m fifth &&
364
365 echo six >>one &&
366 git add one &&
367 test_tick &&
368 git commit --author "claus <me@company.xx>" -m sixth &&
369
370 echo seven >>one &&
371 git add one &&
372 test_tick &&
373 git commit --author "CTO <cto@coompany.xx>" -m seventh &&
374
375 mkdir -p internal_mailmap &&
376 echo "Committed <$GIT_COMMITTER_EMAIL>" > internal_mailmap/.mailmap &&
377 echo "<cto@company.xx> <cto@coompany.xx>" >> internal_mailmap/.mailmap &&
378 echo "Some Dude <some@dude.xx> nick1 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
379 echo "Other Author <other@author.xx> nick2 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
380 echo "Other Author <other@author.xx> <nick2@company.xx>" >> internal_mailmap/.mailmap &&
381 echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
382 echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
383
384 git shortlog -e HEAD >actual &&
385 test_cmp expect actual
386
387 '
388
389 # git log with --pretty format which uses the name and email mailmap placemarkers
390 cat >expect << EOF
391 Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx>
392 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
393
394 Author claus <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
395 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
396
397 Author santa <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
398 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
399
400 Author nick2 <nick2@company.xx> maps to Other Author <other@author.xx>
401 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
402
403 Author nick2 <bugs@company.xx> maps to Other Author <other@author.xx>
404 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
405
406 Author nick1 <bugs@company.xx> maps to Some Dude <some@dude.xx>
407 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
408
409 Author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> maps to $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
410 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
411 EOF
412
413 test_expect_success 'Log output (complex mapping)' '
414 git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
415 test_cmp expect actual
416 '
417
418 cat >expect << EOF
419 Author email cto@coompany.xx has local-part cto
420 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
421
422 Author email me@company.xx has local-part me
423 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
424
425 Author email me@company.xx has local-part me
426 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
427
428 Author email nick2@company.xx has local-part nick2
429 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
430
431 Author email bugs@company.xx has local-part bugs
432 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
433
434 Author email bugs@company.xx has local-part bugs
435 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
436
437 Author email author@example.com has local-part author
438 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
439 EOF
440
441 test_expect_success 'Log output (local-part email address)' '
442 git log --pretty=format:"Author email %ae has local-part %al%nCommitter email %ce has local-part %cl%n" >actual &&
443 test_cmp expect actual
444 '
445
446 cat >expect << EOF
447 Author: CTO <cto@company.xx>
448 Author: Santa Claus <santa.claus@northpole.xx>
449 Author: Santa Claus <santa.claus@northpole.xx>
450 Author: Other Author <other@author.xx>
451 Author: Other Author <other@author.xx>
452 Author: Some Dude <some@dude.xx>
453 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
454 EOF
455
456 test_expect_success 'Log output with --use-mailmap' '
457 git log --use-mailmap | grep Author >actual &&
458 test_cmp expect actual
459 '
460
461 cat >expect << EOF
462 Author: CTO <cto@company.xx>
463 Author: Santa Claus <santa.claus@northpole.xx>
464 Author: Santa Claus <santa.claus@northpole.xx>
465 Author: Other Author <other@author.xx>
466 Author: Other Author <other@author.xx>
467 Author: Some Dude <some@dude.xx>
468 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
469 EOF
470
471 test_expect_success 'Log output with log.mailmap' '
472 git -c log.mailmap=True log | grep Author >actual &&
473 test_cmp expect actual
474 '
475
476 test_expect_success 'log.mailmap=false disables mailmap' '
477 cat >expect <<- EOF &&
478 Author: CTO <cto@coompany.xx>
479 Author: claus <me@company.xx>
480 Author: santa <me@company.xx>
481 Author: nick2 <nick2@company.xx>
482 Author: nick2 <bugs@company.xx>
483 Author: nick1 <bugs@company.xx>
484 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
485 EOF
486 git -c log.mailmap=False log | grep Author > actual &&
487 test_cmp expect actual
488 '
489
490 test_expect_success '--no-use-mailmap disables mailmap' '
491 cat >expect <<- EOF &&
492 Author: CTO <cto@coompany.xx>
493 Author: claus <me@company.xx>
494 Author: santa <me@company.xx>
495 Author: nick2 <nick2@company.xx>
496 Author: nick2 <bugs@company.xx>
497 Author: nick1 <bugs@company.xx>
498 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
499 EOF
500 git log --no-use-mailmap | grep Author > actual &&
501 test_cmp expect actual
502 '
503
504 cat >expect <<\EOF
505 Author: Santa Claus <santa.claus@northpole.xx>
506 Author: Santa Claus <santa.claus@northpole.xx>
507 EOF
508
509 test_expect_success 'Grep author with --use-mailmap' '
510 git log --use-mailmap --author Santa | grep Author >actual &&
511 test_cmp expect actual
512 '
513 cat >expect <<\EOF
514 Author: Santa Claus <santa.claus@northpole.xx>
515 Author: Santa Claus <santa.claus@northpole.xx>
516 EOF
517
518 test_expect_success 'Grep author with log.mailmap' '
519 git -c log.mailmap=True log --author Santa | grep Author >actual &&
520 test_cmp expect actual
521 '
522
523 test_expect_success 'log.mailmap is true by default these days' '
524 git log --author Santa | grep Author >actual &&
525 test_cmp expect actual
526 '
527
528 test_expect_success 'Only grep replaced author with --use-mailmap' '
529 git log --use-mailmap --author "<cto@coompany.xx>" >actual &&
530 test_must_be_empty actual
531 '
532
533 # git blame
534 cat >expect <<EOF
535 ^OBJI ($GIT_AUTHOR_NAME DATE 1) one
536 OBJID (Some Dude DATE 2) two
537 OBJID (Other Author DATE 3) three
538 OBJID (Other Author DATE 4) four
539 OBJID (Santa Claus DATE 5) five
540 OBJID (Santa Claus DATE 6) six
541 OBJID (CTO DATE 7) seven
542 EOF
543 test_expect_success 'Blame output (complex mapping)' '
544 git blame one >actual &&
545 fuzz_blame actual >actual.fuzz &&
546 test_cmp expect actual.fuzz
547 '
548
549 cat >expect <<\EOF
550 Some Dude <some@dude.xx>
551 EOF
552
553 test_expect_success 'commit --author honors mailmap' '
554 test_must_fail git commit --author "nick" --allow-empty -meight &&
555 git commit --author "Some Dude" --allow-empty -meight &&
556 git show --pretty=format:"%an <%ae>%n" >actual &&
557 test_cmp expect actual
558 '
559
560 test_done