Merge branch 'ph/use-delete-refs'
[git] / t / t4203-mailmap.sh
1 #!/bin/sh
2
3 test_description='.mailmap configurations'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 test_expect_success 'setup commits and contacts file' '
11         test_commit initial one one &&
12         test_commit --author "nick1 <bugs@company.xx>" --append second one two
13 '
14
15 test_expect_success 'check-mailmap no arguments' '
16         test_must_fail git check-mailmap
17 '
18
19 test_expect_success 'check-mailmap arguments' '
20         cat >expect <<-EOF &&
21         $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
22         nick1 <bugs@company.xx>
23         EOF
24         git check-mailmap \
25                 "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" \
26                 "nick1 <bugs@company.xx>" >actual &&
27         test_cmp expect actual
28 '
29
30 test_expect_success 'check-mailmap --stdin' '
31         cat >expect <<-EOF &&
32         $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
33         nick1 <bugs@company.xx>
34         EOF
35         git check-mailmap --stdin <expect >actual &&
36         test_cmp expect actual
37 '
38
39 test_expect_success 'check-mailmap --stdin arguments: no mapping' '
40         test_when_finished "rm contacts" &&
41         cat >contacts <<-EOF &&
42         $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
43         nick1 <bugs@company.xx>
44         EOF
45         cat >expect <<-\EOF &&
46         Internal Guy <bugs@company.xy>
47         EOF
48         cat contacts >>expect &&
49
50         git check-mailmap --stdin "Internal Guy <bugs@company.xy>" \
51                 <contacts >actual &&
52         test_cmp expect actual
53 '
54
55 test_expect_success 'check-mailmap --stdin arguments: mapping' '
56         test_when_finished "rm .mailmap" &&
57         cat >.mailmap <<-EOF &&
58         New Name <$GIT_AUTHOR_EMAIL>
59         EOF
60         cat >stdin <<-EOF &&
61         Old Name <$GIT_AUTHOR_EMAIL>
62         EOF
63
64         cp .mailmap expect &&
65         git check-mailmap --stdin <stdin >actual &&
66         test_cmp expect actual &&
67
68         cat .mailmap >>expect &&
69         git check-mailmap --stdin "Another Old Name <$GIT_AUTHOR_EMAIL>" \
70                 <stdin >actual &&
71         test_cmp expect actual
72 '
73
74 test_expect_success 'check-mailmap bogus contact' '
75         test_must_fail git check-mailmap bogus
76 '
77
78 test_expect_success 'check-mailmap bogus contact --stdin' '
79         test_must_fail git check-mailmap --stdin bogus </dev/null
80 '
81
82 test_expect_success 'No mailmap' '
83         cat >expect <<-EOF &&
84         $GIT_AUTHOR_NAME (1):
85               initial
86
87         nick1 (1):
88               second
89
90         EOF
91         git shortlog HEAD >actual &&
92         test_cmp expect actual
93 '
94
95 test_expect_success 'setup default .mailmap' '
96         cat >default.map <<-EOF
97         Repo Guy <$GIT_AUTHOR_EMAIL>
98         EOF
99 '
100
101 test_expect_success 'test default .mailmap' '
102         test_when_finished "rm .mailmap" &&
103         cp default.map .mailmap &&
104
105         cat >expect <<-\EOF &&
106         Repo Guy (1):
107               initial
108
109         nick1 (1):
110               second
111
112         EOF
113         git shortlog HEAD >actual &&
114         test_cmp expect actual
115 '
116
117 test_expect_success 'mailmap.file set' '
118         test_when_finished "rm .mailmap" &&
119         cp default.map .mailmap &&
120
121         test_config mailmap.file internal.map &&
122         cat >internal.map <<-\EOF &&
123         Internal Guy <bugs@company.xx>
124         EOF
125
126         cat >expect <<-\EOF &&
127         Internal Guy (1):
128               second
129
130         Repo Guy (1):
131               initial
132
133         EOF
134         git shortlog HEAD >actual &&
135         test_cmp expect actual &&
136
137         # The internal_mailmap/.mailmap file is an a subdirectory, but
138         # as shown here it can also be outside the repository
139         test_when_finished "rm -rf sub-repo" &&
140         git clone . sub-repo &&
141         (
142                 cd sub-repo &&
143                 cp ../.mailmap . &&
144                 git config mailmap.file ../internal.map &&
145                 git shortlog HEAD >actual &&
146                 test_cmp ../expect actual
147         )
148 '
149
150 test_expect_success 'mailmap.file override' '
151         test_config mailmap.file internal.map &&
152         cat >internal.map <<-EOF &&
153         Internal Guy <bugs@company.xx>
154         External Guy <$GIT_AUTHOR_EMAIL>
155         EOF
156
157         cat >expect <<-\EOF &&
158         External Guy (1):
159               initial
160
161         Internal Guy (1):
162               second
163
164         EOF
165         git shortlog HEAD >actual &&
166         test_cmp expect actual
167 '
168
169 test_expect_success 'mailmap.file non-existent' '
170         test_when_finished "rm .mailmap" &&
171         cp default.map .mailmap &&
172
173         cat >expect <<-\EOF &&
174         Repo Guy (1):
175               initial
176
177         nick1 (1):
178               second
179
180         EOF
181         git shortlog HEAD >actual &&
182         test_cmp expect actual
183 '
184
185 test_expect_success 'name entry after email entry' '
186         test_when_finished "rm .mailmap" &&
187         cp default.map .mailmap &&
188
189         test_config mailmap.file internal.map &&
190         cat >internal.map <<-\EOF &&
191         <bugs@company.xy> <bugs@company.xx>
192         Internal Guy <bugs@company.xx>
193         EOF
194
195         cat >expect <<-\EOF &&
196         Internal Guy (1):
197               second
198
199         Repo Guy (1):
200               initial
201
202         EOF
203
204         git shortlog HEAD >actual &&
205         test_cmp expect actual
206 '
207
208 test_expect_success 'name entry after email entry, case-insensitive' '
209         test_when_finished "rm .mailmap" &&
210         cp default.map .mailmap &&
211
212         test_config mailmap.file internal.map &&
213         cat >internal.map <<-\EOF &&
214         <bugs@company.xy> <bugs@company.xx>
215         Internal Guy <BUGS@Company.xx>
216         EOF
217
218         cat >expect <<-\EOF &&
219         Internal Guy (1):
220               second
221
222         Repo Guy (1):
223               initial
224
225         EOF
226         git shortlog HEAD >actual &&
227         test_cmp expect actual &&
228
229         cat >internal.map <<-\EOF &&
230         NiCk <BuGs@CoMpAnY.Xy> NICK1 <BUGS@COMPANY.XX>
231         EOF
232
233         cat >expect <<-\EOF &&
234         NiCk (1):
235               second
236
237         Repo Guy (1):
238               initial
239
240         EOF
241         git shortlog HEAD >actual &&
242         test_cmp expect actual
243 '
244
245 test_expect_success 'No mailmap files, but configured' '
246         cat >expect <<-EOF &&
247         $GIT_AUTHOR_NAME (1):
248               initial
249
250         nick1 (1):
251               second
252
253         EOF
254         git shortlog HEAD >actual &&
255         test_cmp expect actual
256 '
257
258 test_expect_success 'setup mailmap blob tests' '
259         git checkout -b map &&
260         test_when_finished "git checkout main" &&
261         cat >just-bugs <<-\EOF &&
262         Blob Guy <bugs@company.xx>
263         EOF
264         cat >both <<-EOF &&
265         Blob Guy <$GIT_AUTHOR_EMAIL>
266         Blob Guy <bugs@company.xx>
267         EOF
268         printf "Tricky Guy <$GIT_AUTHOR_EMAIL>" >no-newline &&
269         git add just-bugs both no-newline &&
270         git commit -m "my mailmaps" &&
271
272         cat >internal.map <<-EOF
273         Internal Guy <$GIT_AUTHOR_EMAIL>
274         EOF
275 '
276
277 test_expect_success 'mailmap.blob set' '
278         test_when_finished "rm .mailmap" &&
279         cp default.map .mailmap &&
280
281         cat >expect <<-\EOF &&
282         Blob Guy (1):
283               second
284
285         Repo Guy (1):
286               initial
287
288         EOF
289         git -c mailmap.blob=map:just-bugs shortlog HEAD >actual &&
290         test_cmp expect actual
291 '
292
293 test_expect_success 'mailmap.blob overrides .mailmap' '
294         test_when_finished "rm .mailmap" &&
295         cp default.map .mailmap &&
296
297         cat >expect <<-\EOF &&
298         Blob Guy (2):
299               initial
300               second
301
302         EOF
303         git -c mailmap.blob=map:both shortlog HEAD >actual &&
304         test_cmp expect actual
305 '
306
307 test_expect_success 'mailmap.file overrides mailmap.blob' '
308         cat >expect <<-\EOF &&
309         Blob Guy (1):
310               second
311
312         Internal Guy (1):
313               initial
314
315         EOF
316         git \
317           -c mailmap.blob=map:both \
318           -c mailmap.file=internal.map \
319           shortlog HEAD >actual &&
320         test_cmp expect actual
321 '
322
323 test_expect_success 'mailmap.file can be missing' '
324         test_when_finished "rm .mailmap" &&
325         cp default.map .mailmap &&
326
327         test_config mailmap.file nonexistent &&
328         cat >expect <<-\EOF &&
329         Repo Guy (1):
330               initial
331
332         nick1 (1):
333               second
334
335         EOF
336         git shortlog HEAD >actual 2>err &&
337         test_must_be_empty err &&
338         test_cmp expect actual
339 '
340
341 test_expect_success 'mailmap.blob can be missing' '
342         test_when_finished "rm .mailmap" &&
343         cp default.map .mailmap &&
344
345         cat >expect <<-\EOF &&
346         Repo Guy (1):
347               initial
348
349         nick1 (1):
350               second
351
352         EOF
353         git -c mailmap.blob=map:nonexistent shortlog HEAD >actual 2>err &&
354         test_must_be_empty err &&
355         test_cmp expect actual
356 '
357
358 test_expect_success 'mailmap.blob might be the wrong type' '
359         test_when_finished "rm .mailmap" &&
360         cp default.map .mailmap &&
361
362         git -c mailmap.blob=HEAD: shortlog HEAD >actual 2>err &&
363         test_i18ngrep "mailmap is not a blob" err &&
364         test_cmp expect actual
365 '
366
367 test_expect_success 'mailmap.blob defaults to off in non-bare repo' '
368         git init non-bare &&
369         (
370                 cd non-bare &&
371                 test_commit one .mailmap "Fake Name <$GIT_AUTHOR_EMAIL>" &&
372                 cat >expect <<-\EOF &&
373                      1  Fake Name
374                 EOF
375                 git shortlog -ns HEAD >actual &&
376                 test_cmp expect actual &&
377                 rm .mailmap &&
378                 cat >expect <<-EOF &&
379                      1  $GIT_AUTHOR_NAME
380                 EOF
381                 git shortlog -ns HEAD >actual &&
382                 test_cmp expect actual
383         )
384 '
385
386 test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' '
387         git clone --bare non-bare bare &&
388         (
389                 cd bare &&
390                 cat >expect <<-\EOF &&
391                      1  Fake Name
392                 EOF
393                 git shortlog -ns HEAD >actual &&
394                 test_cmp expect actual
395         )
396 '
397
398 test_expect_success 'mailmap.blob can handle blobs without trailing newline' '
399         cat >expect <<-\EOF &&
400         Tricky Guy (1):
401               initial
402
403         nick1 (1):
404               second
405
406         EOF
407         git -c mailmap.blob=map:no-newline shortlog HEAD >actual &&
408         test_cmp expect actual
409 '
410
411 test_expect_success 'single-character name' '
412         test_when_finished "rm .mailmap" &&
413         cat >.mailmap <<-EOF &&
414         A <$GIT_AUTHOR_EMAIL>
415         EOF
416
417         cat >expect <<-EOF &&
418              1  A <$GIT_AUTHOR_EMAIL>
419              1  nick1 <bugs@company.xx>
420         EOF
421         git shortlog -es HEAD >actual &&
422         test_cmp expect actual
423 '
424
425 test_expect_success 'preserve canonical email case' '
426         test_when_finished "rm .mailmap" &&
427         cat >.mailmap <<-EOF &&
428         <AUTHOR@example.com> <$GIT_AUTHOR_EMAIL>
429         EOF
430
431         cat >expect <<-EOF &&
432              1  $GIT_AUTHOR_NAME <AUTHOR@example.com>
433              1  nick1 <bugs@company.xx>
434         EOF
435         git shortlog -es HEAD >actual &&
436         test_cmp expect actual
437 '
438
439 test_expect_success 'gitmailmap(5) example output: setup' '
440         test_create_repo doc &&
441         test_commit -C doc --author "Joe Developer <joe@example.com>" A &&
442         test_commit -C doc --author "Joe R. Developer <joe@example.com>" B &&
443         test_commit -C doc --author "Jane Doe <jane@example.com>" C &&
444         test_commit -C doc --author "Jane Doe <jane@laptop.(none)>" D &&
445         test_commit -C doc --author "Jane D. <jane@desktop.(none)>" E
446 '
447
448 test_expect_success 'gitmailmap(5) example output: example #1' '
449         test_config -C doc mailmap.file ../doc.map &&
450         cat >doc.map <<-\EOF &&
451         Joe R. Developer <joe@example.com>
452         Jane Doe <jane@example.com>
453         Jane Doe <jane@desktop.(none)>
454         EOF
455
456         cat >expect <<-\EOF &&
457         Author Joe Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
458         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
459
460         Author Joe R. Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
461         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
462
463         Author Jane Doe <jane@example.com> maps to Jane Doe <jane@example.com>
464         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
465
466         Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <jane@laptop.(none)>
467         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
468
469         Author Jane D <jane@desktop.(none)> maps to Jane Doe <jane@desktop.(none)>
470         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
471         EOF
472         git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
473         test_cmp expect actual
474 '
475
476 test_expect_success 'gitmailmap(5) example output: example #2' '
477         test_config -C doc mailmap.file ../doc.map &&
478         cat >doc.map <<-\EOF &&
479         Joe R. Developer <joe@example.com>
480         Jane Doe <jane@example.com> <jane@laptop.(none)>
481         Jane Doe <jane@example.com> <jane@desktop.(none)>
482         EOF
483
484         cat >expect <<-\EOF &&
485         Author Joe Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
486         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
487
488         Author Joe R. Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
489         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
490
491         Author Jane Doe <jane@example.com> maps to Jane Doe <jane@example.com>
492         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
493
494         Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <jane@example.com>
495         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
496
497         Author Jane D <jane@desktop.(none)> maps to Jane Doe <jane@example.com>
498         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
499         EOF
500         git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
501         test_cmp expect actual
502 '
503
504 test_expect_success 'gitmailmap(5) example output: example #3' '
505         test_config -C doc mailmap.file ../doc.map &&
506         cat >>doc.map <<-\EOF &&
507         Joe R. Developer <joe@example.com> Joe <bugs@example.com>
508         Jane Doe <jane@example.com> Jane <bugs@example.com>
509         EOF
510
511         test_commit -C doc --author "Joe <bugs@example.com>" F &&
512         test_commit -C doc --author "Jane <bugs@example.com>" G &&
513
514         cat >>expect <<-\EOF &&
515
516         Author Joe <bugs@example.com> maps to Joe R. Developer <joe@example.com>
517         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
518
519         Author Jane <bugs@example.com> maps to Jane Doe <jane@example.com>
520         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
521         EOF
522         git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
523         test_cmp expect actual
524 '
525
526
527 test_expect_success 'Shortlog output (complex mapping)' '
528         test_config mailmap.file complex.map &&
529         cat >complex.map <<-EOF &&
530         Committed <$GIT_COMMITTER_EMAIL>
531         <cto@company.xx> <cto@coompany.xx>
532         Some Dude <some@dude.xx>         nick1 <bugs@company.xx>
533         Other Author <other@author.xx>   nick2 <bugs@company.xx>
534         Other Author <other@author.xx>         <nick2@company.xx>
535         Santa Claus <santa.claus@northpole.xx> <me@company.xx>
536         EOF
537
538         test_commit --author "nick2 <bugs@company.xx>" --append third one three &&
539         test_commit --author "nick2 <nick2@company.xx>" --append fourth one four &&
540         test_commit --author "santa <me@company.xx>" --append fifth one five &&
541         test_commit --author "claus <me@company.xx>" --append sixth one six &&
542         test_commit --author "CTO <cto@coompany.xx>" --append seventh one seven &&
543
544         cat >expect <<-EOF &&
545         $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1):
546               initial
547
548         CTO <cto@company.xx> (1):
549               seventh
550
551         Other Author <other@author.xx> (2):
552               third
553               fourth
554
555         Santa Claus <santa.claus@northpole.xx> (2):
556               fifth
557               sixth
558
559         Some Dude <some@dude.xx> (1):
560               second
561
562         EOF
563
564         git shortlog -e HEAD >actual &&
565         test_cmp expect actual
566
567 '
568
569 test_expect_success 'Log output (complex mapping)' '
570         test_config mailmap.file complex.map &&
571
572         cat >expect <<-EOF &&
573         Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx>
574         Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
575
576         Author claus <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
577         Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
578
579         Author santa <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
580         Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
581
582         Author nick2 <nick2@company.xx> maps to Other Author <other@author.xx>
583         Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
584
585         Author nick2 <bugs@company.xx> maps to Other Author <other@author.xx>
586         Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
587
588         Author nick1 <bugs@company.xx> maps to Some Dude <some@dude.xx>
589         Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
590
591         Author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> maps to $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
592         Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
593         EOF
594
595         git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
596         test_cmp expect actual
597 '
598
599 test_expect_success 'Log output (local-part email address)' '
600         cat >expect <<-EOF &&
601         Author email cto@coompany.xx has local-part cto
602         Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
603
604         Author email me@company.xx has local-part me
605         Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
606
607         Author email me@company.xx has local-part me
608         Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
609
610         Author email nick2@company.xx has local-part nick2
611         Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
612
613         Author email bugs@company.xx has local-part bugs
614         Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
615
616         Author email bugs@company.xx has local-part bugs
617         Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
618
619         Author email author@example.com has local-part author
620         Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
621         EOF
622
623         git log --pretty=format:"Author email %ae has local-part %al%nCommitter email %ce has local-part %cl%n" >actual &&
624         test_cmp expect actual
625 '
626
627 test_expect_success 'Log output with --use-mailmap' '
628         test_config mailmap.file complex.map &&
629
630         cat >expect <<-EOF &&
631         Author: CTO <cto@company.xx>
632         Author: Santa Claus <santa.claus@northpole.xx>
633         Author: Santa Claus <santa.claus@northpole.xx>
634         Author: Other Author <other@author.xx>
635         Author: Other Author <other@author.xx>
636         Author: Some Dude <some@dude.xx>
637         Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
638         EOF
639
640         git log --use-mailmap >log &&
641         grep Author log >actual &&
642         test_cmp expect actual
643 '
644
645 test_expect_success 'Log output with log.mailmap' '
646         test_config mailmap.file complex.map &&
647
648         cat >expect <<-EOF &&
649         Author: CTO <cto@company.xx>
650         Author: Santa Claus <santa.claus@northpole.xx>
651         Author: Santa Claus <santa.claus@northpole.xx>
652         Author: Other Author <other@author.xx>
653         Author: Other Author <other@author.xx>
654         Author: Some Dude <some@dude.xx>
655         Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
656         EOF
657
658         git -c log.mailmap=True log >log &&
659         grep Author log >actual &&
660         test_cmp expect actual
661 '
662
663 test_expect_success 'log.mailmap=false disables mailmap' '
664         cat >expect <<-EOF &&
665         Author: CTO <cto@coompany.xx>
666         Author: claus <me@company.xx>
667         Author: santa <me@company.xx>
668         Author: nick2 <nick2@company.xx>
669         Author: nick2 <bugs@company.xx>
670         Author: nick1 <bugs@company.xx>
671         Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
672         EOF
673         git -c log.mailmap=false log >log &&
674         grep Author log >actual &&
675         test_cmp expect actual
676 '
677
678 test_expect_success '--no-use-mailmap disables mailmap' '
679         cat >expect <<-EOF &&
680         Author: CTO <cto@coompany.xx>
681         Author: claus <me@company.xx>
682         Author: santa <me@company.xx>
683         Author: nick2 <nick2@company.xx>
684         Author: nick2 <bugs@company.xx>
685         Author: nick1 <bugs@company.xx>
686         Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
687         EOF
688         git log --no-use-mailmap >log &&
689         grep Author log >actual &&
690         test_cmp expect actual
691 '
692
693 test_expect_success 'Grep author with --use-mailmap' '
694         test_config mailmap.file complex.map &&
695
696         cat >expect <<-\EOF &&
697         Author: Santa Claus <santa.claus@northpole.xx>
698         Author: Santa Claus <santa.claus@northpole.xx>
699         EOF
700         git log --use-mailmap --author Santa >log &&
701         grep Author log >actual &&
702         test_cmp expect actual
703 '
704
705 test_expect_success 'Grep author with log.mailmap' '
706         test_config mailmap.file complex.map &&
707
708         cat >expect <<-\EOF &&
709         Author: Santa Claus <santa.claus@northpole.xx>
710         Author: Santa Claus <santa.claus@northpole.xx>
711         EOF
712
713         git -c log.mailmap=True log --author Santa >log &&
714         grep Author log >actual &&
715         test_cmp expect actual
716 '
717
718 test_expect_success 'log.mailmap is true by default these days' '
719         test_config mailmap.file complex.map &&
720         git log --author Santa >log &&
721         grep Author log >actual &&
722         test_cmp expect actual
723 '
724
725 test_expect_success 'Only grep replaced author with --use-mailmap' '
726         test_config mailmap.file complex.map &&
727         git log --use-mailmap --author "<cto@coompany.xx>" >actual &&
728         test_must_be_empty actual
729 '
730
731 test_expect_success 'Blame --porcelain output (complex mapping)' '
732         test_config mailmap.file complex.map &&
733
734         cat >expect <<-EOF &&
735         1 1 1
736         A U Thor
737         2 2 1
738         Some Dude
739         3 3 1
740         Other Author
741         4 4 1
742         Other Author
743         5 5 1
744         Santa Claus
745         6 6 1
746         Santa Claus
747         7 7 1
748         CTO
749         EOF
750
751         git blame --porcelain one >actual.blame &&
752
753         NUM="[0-9][0-9]*" &&
754         sed -n <actual.blame >actual.fuzz \
755                 -e "s/^author //p" \
756                 -e "s/^$OID_REGEX \\($NUM $NUM $NUM\\)$/\\1/p"  &&
757         test_cmp expect actual.fuzz
758 '
759
760 test_expect_success 'Blame output (complex mapping)' '
761         git -c mailmap.file=complex.map blame one >a &&
762         git blame one >b &&
763         test_file_not_empty a &&
764         ! cmp a b
765 '
766
767 test_expect_success 'commit --author honors mailmap' '
768         test_config mailmap.file complex.map &&
769
770         cat >expect <<-\EOF &&
771         Some Dude <some@dude.xx>
772         EOF
773
774         test_must_fail git commit --author "nick" --allow-empty -meight &&
775         git commit --author "Some Dude" --allow-empty -meight &&
776         git show --pretty=format:"%an <%ae>%n" >actual &&
777         test_cmp expect actual
778 '
779
780 test_expect_success 'comment syntax: setup' '
781         test_create_repo comm &&
782         test_commit -C comm --author "A <a@example.com>" A &&
783         test_commit -C comm --author "B <b@example.com>" B &&
784         test_commit -C comm --author "C <#@example.com>" C &&
785         test_commit -C comm --author "D <d@e#ample.com>" D &&
786
787         test_config -C comm mailmap.file ../doc.map &&
788         cat >>doc.map <<-\EOF &&
789         # Ah <a@example.com>
790
791         ; Bee <b@example.com>
792         Cee <cee@example.com> <#@example.com>
793         Dee <dee@example.com> <d@e#ample.com>
794         EOF
795
796         cat >expect <<-\EOF &&
797         Author A <a@example.com> maps to A <a@example.com>
798         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
799
800         Author B <b@example.com> maps to ; Bee <b@example.com>
801         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
802
803         Author C <#@example.com> maps to Cee <cee@example.com>
804         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
805
806         Author D <d@e#ample.com> maps to Dee <dee@example.com>
807         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
808         EOF
809         git -C comm log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
810         test_cmp expect actual
811 '
812
813 test_expect_success 'whitespace syntax: setup' '
814         test_create_repo space &&
815         test_commit -C space --author "A <a@example.com>" A &&
816         test_commit -C space --author "B <b@example.com>" B &&
817         test_commit -C space --author " C <c@example.com>" C &&
818         test_commit -C space --author " D  <d@example.com>" D &&
819         test_commit -C space --author "E E <e@example.com>" E &&
820         test_commit -C space --author "F  F <f@example.com>" F &&
821         test_commit -C space --author "G   G <g@example.com>" G &&
822         test_commit -C space --author "H   H <h@example.com>" H &&
823
824         test_config -C space mailmap.file ../space.map &&
825         cat >>space.map <<-\EOF &&
826         Ah <ah@example.com> < a@example.com >
827         Bee <bee@example.com  > <  b@example.com  >
828         Cee <cee@example.com> C <c@example.com>
829         dee <dee@example.com>  D  <d@example.com>
830         eee <eee@example.com> E E <e@example.com>
831         eff <eff@example.com> F  F <f@example.com>
832         gee <gee@example.com> G   G <g@example.com>
833         aitch <aitch@example.com> H  H <h@example.com>
834         EOF
835
836         cat >expect <<-\EOF &&
837         Author A <a@example.com> maps to A <a@example.com>
838         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
839
840         Author B <b@example.com> maps to B <b@example.com>
841         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
842
843         Author C <c@example.com> maps to Cee <cee@example.com>
844         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
845
846         Author D <d@example.com> maps to dee <dee@example.com>
847         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
848
849         Author E E <e@example.com> maps to eee <eee@example.com>
850         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
851
852         Author F  F <f@example.com> maps to eff <eff@example.com>
853         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
854
855         Author G   G <g@example.com> maps to gee <gee@example.com>
856         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
857
858         Author H   H <h@example.com> maps to H   H <h@example.com>
859         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
860         EOF
861         git -C space log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
862         test_cmp expect actual
863 '
864
865 test_expect_success 'empty syntax: setup' '
866         test_create_repo empty &&
867         test_commit -C empty --author "A <>" A &&
868         test_commit -C empty --author "B <b@example.com>" B &&
869         test_commit -C empty --author "C <c@example.com>" C &&
870
871         test_config -C empty mailmap.file ../empty.map &&
872         cat >>empty.map <<-\EOF &&
873         Ah <ah@example.com> <>
874         Bee <bee@example.com> <>
875         Cee <> <c@example.com>
876         EOF
877
878         cat >expect <<-\EOF &&
879         Author A <> maps to Bee <bee@example.com>
880         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
881
882         Author B <b@example.com> maps to B <b@example.com>
883         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
884
885         Author C <c@example.com> maps to C <c@example.com>
886         Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
887         EOF
888         git -C empty log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
889         test_cmp expect actual
890 '
891
892 test_done