3 test_description
='.mailmap configurations'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success
'setup commits and contacts file' '
12 test_commit initial one one &&
13 test_commit --author "nick1 <bugs@company.xx>" --append second one two
16 test_expect_success
'check-mailmap no arguments' '
17 test_must_fail git check-mailmap
20 test_expect_success
'check-mailmap arguments' '
22 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
23 nick1 <bugs@company.xx>
26 "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" \
27 "nick1 <bugs@company.xx>" >actual &&
28 test_cmp expect actual
31 test_expect_success
'check-mailmap --stdin' '
33 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
34 nick1 <bugs@company.xx>
36 git check-mailmap --stdin <expect >actual &&
37 test_cmp expect actual
40 test_expect_success
'check-mailmap --stdin arguments: no mapping' '
41 test_when_finished "rm contacts" &&
42 cat >contacts <<-EOF &&
43 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
44 nick1 <bugs@company.xx>
46 cat >expect <<-\EOF &&
47 Internal Guy <bugs@company.xy>
49 cat contacts >>expect &&
51 git check-mailmap --stdin "Internal Guy <bugs@company.xy>" \
53 test_cmp expect actual
56 test_expect_success
'check-mailmap --stdin arguments: mapping' '
57 test_when_finished "rm .mailmap" &&
58 cat >.mailmap <<-EOF &&
59 New Name <$GIT_AUTHOR_EMAIL>
62 Old Name <$GIT_AUTHOR_EMAIL>
66 git check-mailmap --stdin <stdin >actual &&
67 test_cmp expect actual &&
69 cat .mailmap >>expect &&
70 git check-mailmap --stdin "Another Old Name <$GIT_AUTHOR_EMAIL>" \
72 test_cmp expect actual
75 test_expect_success
'check-mailmap simple address: mapping' '
76 test_when_finished "rm .mailmap" &&
77 cat >.mailmap <<-EOF &&
78 New Name <$GIT_AUTHOR_EMAIL>
80 cat .mailmap >expect &&
81 git check-mailmap "$GIT_AUTHOR_EMAIL" >actual &&
82 test_cmp expect actual
85 test_expect_success
'check-mailmap --stdin simple address: mapping' '
86 test_when_finished "rm .mailmap" &&
87 cat >.mailmap <<-EOF &&
88 New Name <$GIT_AUTHOR_EMAIL>
93 cat .mailmap >expect &&
94 git check-mailmap --stdin <stdin >actual &&
95 test_cmp expect actual
98 test_expect_success
'check-mailmap simple address: no mapping' '
102 git check-mailmap "bugs@company.xx" >actual &&
103 test_cmp expect actual
106 test_expect_success
'check-mailmap --stdin simple address: no mapping' '
107 cat >expect <<-EOF &&
113 git check-mailmap --stdin <stdin >actual &&
114 test_cmp expect actual
117 test_expect_success
'No mailmap' '
118 cat >expect <<-EOF &&
119 $GIT_AUTHOR_NAME (1):
126 git shortlog HEAD >actual &&
127 test_cmp expect actual
130 test_expect_success
'setup default .mailmap' '
131 cat >default.map <<-EOF
132 Repo Guy <$GIT_AUTHOR_EMAIL>
136 test_expect_success
'test default .mailmap' '
137 test_when_finished "rm .mailmap" &&
138 cp default.map .mailmap &&
140 cat >expect <<-\EOF &&
148 git shortlog HEAD >actual &&
149 test_cmp expect actual
152 test_expect_success
'mailmap.file set' '
153 test_when_finished "rm .mailmap" &&
154 cp default.map .mailmap &&
156 test_config mailmap.file internal.map &&
157 cat >internal.map <<-\EOF &&
158 Internal Guy <bugs@company.xx>
161 cat >expect <<-\EOF &&
169 git shortlog HEAD >actual &&
170 test_cmp expect actual &&
172 # The internal_mailmap/.mailmap file is an a subdirectory, but
173 # as shown here it can also be outside the repository
174 test_when_finished "rm -rf sub-repo" &&
175 git clone . sub-repo &&
179 git config mailmap.file ../internal.map &&
180 git shortlog HEAD >actual &&
181 test_cmp ../expect actual
185 test_expect_success
'mailmap.file override' '
186 test_config mailmap.file internal.map &&
187 cat >internal.map <<-EOF &&
188 Internal Guy <bugs@company.xx>
189 External Guy <$GIT_AUTHOR_EMAIL>
192 cat >expect <<-\EOF &&
200 git shortlog HEAD >actual &&
201 test_cmp expect actual
204 test_expect_success
'mailmap.file non-existent' '
205 test_when_finished "rm .mailmap" &&
206 cp default.map .mailmap &&
208 cat >expect <<-\EOF &&
216 git shortlog HEAD >actual &&
217 test_cmp expect actual
220 test_expect_success
'name entry after email entry' '
221 test_when_finished "rm .mailmap" &&
222 cp default.map .mailmap &&
224 test_config mailmap.file internal.map &&
225 cat >internal.map <<-\EOF &&
226 <bugs@company.xy> <bugs@company.xx>
227 Internal Guy <bugs@company.xx>
230 cat >expect <<-\EOF &&
239 git shortlog HEAD >actual &&
240 test_cmp expect actual
243 test_expect_success
'name entry after email entry, case-insensitive' '
244 test_when_finished "rm .mailmap" &&
245 cp default.map .mailmap &&
247 test_config mailmap.file internal.map &&
248 cat >internal.map <<-\EOF &&
249 <bugs@company.xy> <bugs@company.xx>
250 Internal Guy <BUGS@Company.xx>
253 cat >expect <<-\EOF &&
261 git shortlog HEAD >actual &&
262 test_cmp expect actual &&
264 cat >internal.map <<-\EOF &&
265 NiCk <BuGs@CoMpAnY.Xy> NICK1 <BUGS@COMPANY.XX>
268 cat >expect <<-\EOF &&
276 git shortlog HEAD >actual &&
277 test_cmp expect actual
280 test_expect_success
'No mailmap files, but configured' '
281 cat >expect <<-EOF &&
282 $GIT_AUTHOR_NAME (1):
289 git shortlog HEAD >actual &&
290 test_cmp expect actual
293 test_expect_success
'setup mailmap blob tests' '
294 git checkout -b map &&
295 test_when_finished "git checkout main" &&
296 cat >just-bugs <<-\EOF &&
297 Blob Guy <bugs@company.xx>
300 Blob Guy <$GIT_AUTHOR_EMAIL>
301 Blob Guy <bugs@company.xx>
303 printf "Tricky Guy <$GIT_AUTHOR_EMAIL>" >no-newline &&
304 git add just-bugs both no-newline &&
305 git commit -m "my mailmaps" &&
307 cat >internal.map <<-EOF
308 Internal Guy <$GIT_AUTHOR_EMAIL>
312 test_expect_success
'mailmap.blob set' '
313 test_when_finished "rm .mailmap" &&
314 cp default.map .mailmap &&
316 cat >expect <<-\EOF &&
324 git -c mailmap.blob=map:just-bugs shortlog HEAD >actual &&
325 test_cmp expect actual
328 test_expect_success
'mailmap.blob overrides .mailmap' '
329 test_when_finished "rm .mailmap" &&
330 cp default.map .mailmap &&
332 cat >expect <<-\EOF &&
338 git -c mailmap.blob=map:both shortlog HEAD >actual &&
339 test_cmp expect actual
342 test_expect_success
'mailmap.file overrides mailmap.blob' '
343 cat >expect <<-\EOF &&
352 -c mailmap.blob=map:both \
353 -c mailmap.file=internal.map \
354 shortlog HEAD >actual &&
355 test_cmp expect actual
358 test_expect_success
'mailmap.file can be missing' '
359 test_when_finished "rm .mailmap" &&
360 cp default.map .mailmap &&
362 test_config mailmap.file nonexistent &&
363 cat >expect <<-\EOF &&
371 git shortlog HEAD >actual 2>err &&
372 test_must_be_empty err &&
373 test_cmp expect actual
376 test_expect_success
'mailmap.blob can be missing' '
377 test_when_finished "rm .mailmap" &&
378 cp default.map .mailmap &&
380 cat >expect <<-\EOF &&
388 git -c mailmap.blob=map:nonexistent shortlog HEAD >actual 2>err &&
389 test_must_be_empty err &&
390 test_cmp expect actual
393 test_expect_success
'mailmap.blob might be the wrong type' '
394 test_when_finished "rm .mailmap" &&
395 cp default.map .mailmap &&
397 git -c mailmap.blob=HEAD: shortlog HEAD >actual 2>err &&
398 test_grep "mailmap is not a blob" err &&
399 test_cmp expect actual
402 test_expect_success
'mailmap.blob defaults to off in non-bare repo' '
406 test_commit one .mailmap "Fake Name <$GIT_AUTHOR_EMAIL>" &&
407 cat >expect <<-\EOF &&
410 git shortlog -ns HEAD >actual &&
411 test_cmp expect actual &&
413 cat >expect <<-EOF &&
416 git shortlog -ns HEAD >actual &&
417 test_cmp expect actual
421 test_expect_success
'mailmap.blob defaults to HEAD:.mailmap in bare repo' '
422 git clone --bare non-bare bare &&
425 cat >expect <<-\EOF &&
428 git shortlog -ns HEAD >actual &&
429 test_cmp expect actual
433 test_expect_success
'mailmap.blob can handle blobs without trailing newline' '
434 cat >expect <<-\EOF &&
442 git -c mailmap.blob=map:no-newline shortlog HEAD >actual &&
443 test_cmp expect actual
446 test_expect_success
'single-character name' '
447 test_when_finished "rm .mailmap" &&
448 cat >.mailmap <<-EOF &&
449 A <$GIT_AUTHOR_EMAIL>
452 cat >expect <<-EOF &&
453 1 A <$GIT_AUTHOR_EMAIL>
454 1 nick1 <bugs@company.xx>
456 git shortlog -es HEAD >actual &&
457 test_cmp expect actual
460 test_expect_success
'preserve canonical email case' '
461 test_when_finished "rm .mailmap" &&
462 cat >.mailmap <<-EOF &&
463 <AUTHOR@example.com> <$GIT_AUTHOR_EMAIL>
466 cat >expect <<-EOF &&
467 1 $GIT_AUTHOR_NAME <AUTHOR@example.com>
468 1 nick1 <bugs@company.xx>
470 git shortlog -es HEAD >actual &&
471 test_cmp expect actual
474 test_expect_success
'gitmailmap(5) example output: setup' '
475 test_create_repo doc &&
476 test_commit -C doc --author "Joe Developer <joe@example.com>" A &&
477 test_commit -C doc --author "Joe R. Developer <joe@example.com>" B &&
478 test_commit -C doc --author "Jane Doe <jane@example.com>" C &&
479 test_commit -C doc --author "Jane Doe <jane@laptop.(none)>" D &&
480 test_commit -C doc --author "Jane D. <jane@desktop.(none)>" E
483 test_expect_success
'gitmailmap(5) example output: example #1' '
484 test_config -C doc mailmap.file ../doc.map &&
485 cat >doc.map <<-\EOF &&
486 Joe R. Developer <joe@example.com>
487 Jane Doe <jane@example.com>
488 Jane Doe <jane@desktop.(none)>
491 cat >expect <<-\EOF &&
492 Author Joe Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
493 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
495 Author Joe R. Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
496 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
498 Author Jane Doe <jane@example.com> maps to Jane Doe <jane@example.com>
499 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
501 Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <jane@laptop.(none)>
502 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
504 Author Jane D. <jane@desktop.(none)> maps to Jane Doe <jane@desktop.(none)>
505 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
507 git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
508 test_cmp expect actual
511 test_expect_success
'gitmailmap(5) example output: example #2' '
512 test_config -C doc mailmap.file ../doc.map &&
513 cat >doc.map <<-\EOF &&
514 Joe R. Developer <joe@example.com>
515 Jane Doe <jane@example.com> <jane@laptop.(none)>
516 Jane Doe <jane@example.com> <jane@desktop.(none)>
519 cat >expect <<-\EOF &&
520 Author Joe Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
521 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
523 Author Joe R. Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
524 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
526 Author Jane Doe <jane@example.com> maps to Jane Doe <jane@example.com>
527 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
529 Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <jane@example.com>
530 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
532 Author Jane D. <jane@desktop.(none)> maps to Jane Doe <jane@example.com>
533 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
535 git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
536 test_cmp expect actual
539 test_expect_success
'gitmailmap(5) example output: example #3' '
540 test_config -C doc mailmap.file ../doc.map &&
541 cat >>doc.map <<-\EOF &&
542 Joe R. Developer <joe@example.com> Joe <bugs@example.com>
543 Jane Doe <jane@example.com> Jane <bugs@example.com>
546 test_commit -C doc --author "Joe <bugs@example.com>" F &&
547 test_commit -C doc --author "Jane <bugs@example.com>" G &&
549 cat >>expect <<-\EOF &&
551 Author Joe <bugs@example.com> maps to Joe R. Developer <joe@example.com>
552 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
554 Author Jane <bugs@example.com> maps to Jane Doe <jane@example.com>
555 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
557 git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
558 test_cmp expect actual
562 test_expect_success
'Shortlog output (complex mapping)' '
563 test_config mailmap.file complex.map &&
564 cat >complex.map <<-EOF &&
565 Committed <$GIT_COMMITTER_EMAIL>
566 <cto@company.xx> <cto@coompany.xx>
567 Some Dude <some@dude.xx> nick1 <bugs@company.xx>
568 Other Author <other@author.xx> nick2 <bugs@company.xx>
569 Other Author <other@author.xx> <nick2@company.xx>
570 Santa Claus <santa.claus@northpole.xx> <me@company.xx>
573 test_commit --author "nick2 <bugs@company.xx>" --append third one three &&
574 test_commit --author "nick2 <nick2@company.xx>" --append fourth one four &&
575 test_commit --author "santa <me@company.xx>" --append fifth one five &&
576 test_commit --author "claus <me@company.xx>" --append sixth one six &&
577 test_commit --author "CTO <cto@coompany.xx>" --append seventh one seven &&
579 cat >expect <<-EOF &&
580 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1):
583 CTO <cto@company.xx> (1):
586 Other Author <other@author.xx> (2):
590 Santa Claus <santa.claus@northpole.xx> (2):
594 Some Dude <some@dude.xx> (1):
599 git shortlog -e HEAD >actual &&
600 test_cmp expect actual
604 test_expect_success
'Log output (complex mapping)' '
605 test_config mailmap.file complex.map &&
607 cat >expect <<-EOF &&
608 Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx>
609 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
611 Author claus <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
612 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
614 Author santa <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
615 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
617 Author nick2 <nick2@company.xx> maps to Other Author <other@author.xx>
618 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
620 Author nick2 <bugs@company.xx> maps to Other Author <other@author.xx>
621 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
623 Author nick1 <bugs@company.xx> maps to Some Dude <some@dude.xx>
624 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
626 Author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> maps to $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
627 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
630 git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
631 test_cmp expect actual
634 test_expect_success
'Log output (local-part email address)' '
635 cat >expect <<-EOF &&
636 Author email cto@coompany.xx has local-part cto
637 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
639 Author email me@company.xx has local-part me
640 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
642 Author email me@company.xx has local-part me
643 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
645 Author email nick2@company.xx has local-part nick2
646 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
648 Author email bugs@company.xx has local-part bugs
649 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
651 Author email bugs@company.xx has local-part bugs
652 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
654 Author email author@example.com has local-part author
655 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
658 git log --pretty=format:"Author email %ae has local-part %al%nCommitter email %ce has local-part %cl%n" >actual &&
659 test_cmp expect actual
662 test_expect_success
'Log output with --use-mailmap' '
663 test_config mailmap.file complex.map &&
665 cat >expect <<-EOF &&
666 Author: CTO <cto@company.xx>
667 Author: Santa Claus <santa.claus@northpole.xx>
668 Author: Santa Claus <santa.claus@northpole.xx>
669 Author: Other Author <other@author.xx>
670 Author: Other Author <other@author.xx>
671 Author: Some Dude <some@dude.xx>
672 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
675 git log --use-mailmap >log &&
676 grep Author log >actual &&
677 test_cmp expect actual
680 test_expect_success
'Log output with log.mailmap' '
681 test_config mailmap.file complex.map &&
683 cat >expect <<-EOF &&
684 Author: CTO <cto@company.xx>
685 Author: Santa Claus <santa.claus@northpole.xx>
686 Author: Santa Claus <santa.claus@northpole.xx>
687 Author: Other Author <other@author.xx>
688 Author: Other Author <other@author.xx>
689 Author: Some Dude <some@dude.xx>
690 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
693 git -c log.mailmap=True log >log &&
694 grep Author log >actual &&
695 test_cmp expect actual
698 test_expect_success
'log.mailmap=false disables mailmap' '
699 cat >expect <<-EOF &&
700 Author: CTO <cto@coompany.xx>
701 Author: claus <me@company.xx>
702 Author: santa <me@company.xx>
703 Author: nick2 <nick2@company.xx>
704 Author: nick2 <bugs@company.xx>
705 Author: nick1 <bugs@company.xx>
706 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
708 git -c log.mailmap=false log >log &&
709 grep Author log >actual &&
710 test_cmp expect actual
713 test_expect_success
'--no-use-mailmap disables mailmap' '
714 cat >expect <<-EOF &&
715 Author: CTO <cto@coompany.xx>
716 Author: claus <me@company.xx>
717 Author: santa <me@company.xx>
718 Author: nick2 <nick2@company.xx>
719 Author: nick2 <bugs@company.xx>
720 Author: nick1 <bugs@company.xx>
721 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
723 git log --no-use-mailmap >log &&
724 grep Author log >actual &&
725 test_cmp expect actual
728 test_expect_success
'Grep author with --use-mailmap' '
729 test_config mailmap.file complex.map &&
731 cat >expect <<-\EOF &&
732 Author: Santa Claus <santa.claus@northpole.xx>
733 Author: Santa Claus <santa.claus@northpole.xx>
735 git log --use-mailmap --author Santa >log &&
736 grep Author log >actual &&
737 test_cmp expect actual
740 test_expect_success
'Grep author with log.mailmap' '
741 test_config mailmap.file complex.map &&
743 cat >expect <<-\EOF &&
744 Author: Santa Claus <santa.claus@northpole.xx>
745 Author: Santa Claus <santa.claus@northpole.xx>
748 git -c log.mailmap=True log --author Santa >log &&
749 grep Author log >actual &&
750 test_cmp expect actual
753 test_expect_success
'log.mailmap is true by default these days' '
754 test_config mailmap.file complex.map &&
755 git log --author Santa >log &&
756 grep Author log >actual &&
757 test_cmp expect actual
760 test_expect_success
'Only grep replaced author with --use-mailmap' '
761 test_config mailmap.file complex.map &&
762 git log --use-mailmap --author "<cto@coompany.xx>" >actual &&
763 test_must_be_empty actual
766 test_expect_success
'Blame --porcelain output (complex mapping)' '
767 test_config mailmap.file complex.map &&
769 cat >expect <<-EOF &&
786 git blame --porcelain one >actual.blame &&
789 sed -n <actual.blame >actual.fuzz \
791 -e "s/^$OID_REGEX \\($NUM $NUM $NUM\\)$/\\1/p" &&
792 test_cmp expect actual.fuzz
795 test_expect_success
'Blame output (complex mapping)' '
796 git -c mailmap.file=complex.map blame one >a &&
798 test_file_not_empty a &&
802 test_expect_success
'commit --author honors mailmap' '
803 test_config mailmap.file complex.map &&
805 cat >expect <<-\EOF &&
806 Some Dude <some@dude.xx>
809 test_must_fail git commit --author "nick" --allow-empty -meight &&
810 git commit --author "Some Dude" --allow-empty -meight &&
811 git show --pretty=format:"%an <%ae>%n" >actual &&
812 test_cmp expect actual
815 test_expect_success
'comment syntax: setup' '
816 test_create_repo comm &&
817 test_commit -C comm --author "A <a@example.com>" A &&
818 test_commit -C comm --author "B <b@example.com>" B &&
819 test_commit -C comm --author "C <#@example.com>" C &&
820 test_commit -C comm --author "D <d@e#ample.com>" D &&
822 test_config -C comm mailmap.file ../doc.map &&
823 cat >>doc.map <<-\EOF &&
826 ; Bee <b@example.com>
827 Cee <cee@example.com> <#@example.com>
828 Dee <dee@example.com> <d@e#ample.com>
831 cat >expect <<-\EOF &&
832 Author A <a@example.com> maps to A <a@example.com>
833 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
835 Author B <b@example.com> maps to ; Bee <b@example.com>
836 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
838 Author C <#@example.com> maps to Cee <cee@example.com>
839 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
841 Author D <d@e#ample.com> maps to Dee <dee@example.com>
842 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
844 git -C comm log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
845 test_cmp expect actual
848 test_expect_success
'whitespace syntax: setup' '
849 test_create_repo space &&
850 test_commit -C space --author "A <a@example.com>" A &&
851 test_commit -C space --author "B <b@example.com>" B &&
852 test_commit -C space --author " C <c@example.com>" C &&
853 test_commit -C space --author " D <d@example.com>" D &&
854 test_commit -C space --author "E E <e@example.com>" E &&
855 test_commit -C space --author "F F <f@example.com>" F &&
856 test_commit -C space --author "G G <g@example.com>" G &&
857 test_commit -C space --author "H H <h@example.com>" H &&
859 test_config -C space mailmap.file ../space.map &&
860 cat >>space.map <<-\EOF &&
861 Ah <ah@example.com> < a@example.com >
862 Bee <bee@example.com > < b@example.com >
863 Cee <cee@example.com> C <c@example.com>
864 dee <dee@example.com> D <d@example.com>
865 eee <eee@example.com> E E <e@example.com>
866 eff <eff@example.com> F F <f@example.com>
867 gee <gee@example.com> G G <g@example.com>
868 aitch <aitch@example.com> H H <h@example.com>
871 cat >expect <<-\EOF &&
872 Author A <a@example.com> maps to A <a@example.com>
873 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
875 Author B <b@example.com> maps to B <b@example.com>
876 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
878 Author C <c@example.com> maps to Cee <cee@example.com>
879 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
881 Author D <d@example.com> maps to dee <dee@example.com>
882 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
884 Author E E <e@example.com> maps to eee <eee@example.com>
885 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
887 Author F F <f@example.com> maps to eff <eff@example.com>
888 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
890 Author G G <g@example.com> maps to gee <gee@example.com>
891 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
893 Author H H <h@example.com> maps to H H <h@example.com>
894 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
896 git -C space log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
897 test_cmp expect actual
900 test_expect_success
'empty syntax: setup' '
901 test_create_repo empty &&
902 test_commit -C empty --author "A <>" A &&
903 test_commit -C empty --author "B <b@example.com>" B &&
904 test_commit -C empty --author "C <c@example.com>" C &&
906 test_config -C empty mailmap.file ../empty.map &&
907 cat >>empty.map <<-\EOF &&
908 Ah <ah@example.com> <>
909 Bee <bee@example.com> <>
910 Cee <> <c@example.com>
913 cat >expect <<-\EOF &&
914 Author A <> maps to Bee <bee@example.com>
915 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
917 Author B <b@example.com> maps to B <b@example.com>
918 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
920 Author C <c@example.com> maps to C <c@example.com>
921 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
923 git -C empty log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
924 test_cmp expect actual
927 test_expect_success
'set up mailmap location tests' '
928 git init --bare loc-bare &&
929 git --git-dir=loc-bare --work-tree=. commit \
930 --allow-empty -m foo --author="Orig <orig@example.com>" &&
931 echo "New <new@example.com> <orig@example.com>" >loc-bare/.mailmap
934 test_expect_success
'bare repo with --work-tree finds mailmap at top-level' '
935 git -C loc-bare --work-tree=. log -1 --format=%aE >actual &&
936 echo new@example.com >expect &&
937 test_cmp expect actual
940 test_expect_success
'bare repo does not look in current directory' '
941 git -C loc-bare log -1 --format=%aE >actual &&
942 echo orig@example.com >expect &&
943 test_cmp expect actual
946 test_expect_success
'non-git shortlog respects mailmap in current dir' '
947 git --git-dir=loc-bare log -1 >input &&
948 nongit cp "$TRASH_DIRECTORY/loc-bare/.mailmap" . &&
949 nongit git shortlog -s <input >actual &&
950 echo " 1 New" >expect &&
951 test_cmp expect actual
954 test_expect_success
'shortlog on stdin respects mailmap from repo' '
955 cp loc-bare/.mailmap . &&
956 git shortlog -s <input >actual &&
957 echo " 1 New" >expect &&
958 test_cmp expect actual
961 test_expect_success
'find top-level mailmap from subdir' '
962 git clone loc-bare loc-wt &&
963 cp loc-bare/.mailmap loc-wt &&
964 mkdir loc-wt/subdir &&
965 git -C loc-wt/subdir log -1 --format=%aE >actual &&
966 echo new@example.com >expect &&
967 test_cmp expect actual
970 test_expect_success SYMLINKS
'set up symlink tests' '
971 git commit --allow-empty -m foo --author="Orig <orig@example.com>" &&
972 echo "New <new@example.com> <orig@example.com>" >map &&
976 test_expect_success SYMLINKS
'symlinks respected in mailmap.file' '
977 test_when_finished "rm symlink" &&
979 git -c mailmap.file="$(pwd)/symlink" log -1 --format=%aE >actual &&
980 echo "new@example.com" >expect &&
981 test_cmp expect actual
984 test_expect_success SYMLINKS
'symlinks respected in non-repo shortlog' '
986 test_when_finished "nongit rm .mailmap" &&
987 nongit ln -sf "$TRASH_DIRECTORY/map" .mailmap &&
988 nongit git shortlog -s <input >actual &&
989 echo " 1 New" >expect &&
990 test_cmp expect actual
993 test_expect_success SYMLINKS
'symlinks not respected in-tree' '
994 test_when_finished "rm .mailmap" &&
995 ln -s map .mailmap &&
996 git log -1 --format=%aE >actual &&
997 echo "orig@example.com" >expect &&
998 test_cmp expect actual
1001 test_expect_success
'prepare for cat-file --mailmap' '
1003 git commit --allow-empty -m foo --author="Orig <orig@example.com>"
1006 test_expect_success
'--no-use-mailmap disables mailmap in cat-file' '
1007 test_when_finished "rm .mailmap" &&
1008 cat >.mailmap <<-EOF &&
1009 A U Thor <author@example.com> Orig <orig@example.com>
1011 cat >expect <<-EOF &&
1012 author Orig <orig@example.com>
1014 git cat-file --no-use-mailmap commit HEAD >log &&
1015 sed -n "/^author /s/\([^>]*>\).*/\1/p" log >actual &&
1016 test_cmp expect actual
1019 test_expect_success
'--use-mailmap enables mailmap in cat-file' '
1020 test_when_finished "rm .mailmap" &&
1021 cat >.mailmap <<-EOF &&
1022 A U Thor <author@example.com> Orig <orig@example.com>
1024 cat >expect <<-EOF &&
1025 author A U Thor <author@example.com>
1027 git cat-file --use-mailmap commit HEAD >log &&
1028 sed -n "/^author /s/\([^>]*>\).*/\1/p" log >actual &&
1029 test_cmp expect actual
1032 test_expect_success
'--no-mailmap disables mailmap in cat-file for annotated tag objects' '
1033 test_when_finished "rm .mailmap" &&
1034 cat >.mailmap <<-EOF &&
1035 Orig <orig@example.com> C O Mitter <committer@example.com>
1037 cat >expect <<-EOF &&
1038 tagger C O Mitter <committer@example.com>
1040 git tag -a -m "annotated tag" v1 &&
1041 git cat-file --no-mailmap -p v1 >log &&
1042 sed -n "/^tagger /s/\([^>]*>\).*/\1/p" log >actual &&
1043 test_cmp expect actual
1046 test_expect_success
'--mailmap enables mailmap in cat-file for annotated tag objects' '
1047 test_when_finished "rm .mailmap" &&
1048 cat >.mailmap <<-EOF &&
1049 Orig <orig@example.com> C O Mitter <committer@example.com>
1051 cat >expect <<-EOF &&
1052 tagger Orig <orig@example.com>
1054 git tag -a -m "annotated tag" v2 &&
1055 git cat-file --mailmap -p v2 >log &&
1056 sed -n "/^tagger /s/\([^>]*>\).*/\1/p" log >actual &&
1057 test_cmp expect actual
1060 test_expect_success
'git cat-file -s returns correct size with --use-mailmap' '
1061 test_when_finished "rm .mailmap" &&
1062 cat >.mailmap <<-\EOF &&
1063 C O Mitter <committer@example.com> Orig <orig@example.com>
1065 git cat-file commit HEAD >commit.out &&
1066 echo $(wc -c <commit.out) >expect &&
1067 git cat-file --use-mailmap commit HEAD >commit.out &&
1068 echo $(wc -c <commit.out) >>expect &&
1069 git cat-file -s HEAD >actual &&
1070 git cat-file --use-mailmap -s HEAD >>actual &&
1071 test_cmp expect actual
1074 test_expect_success
'git cat-file -s returns correct size with --use-mailmap for tag objects' '
1075 test_when_finished "rm .mailmap" &&
1076 cat >.mailmap <<-\EOF &&
1077 Orig <orig@example.com> C O Mitter <committer@example.com>
1079 git tag -a -m "annotated tag" v3 &&
1080 git cat-file tag v3 >tag.out &&
1081 echo $(wc -c <tag.out) >expect &&
1082 git cat-file --use-mailmap tag v3 >tag.out &&
1083 echo $(wc -c <tag.out) >>expect &&
1084 git cat-file -s v3 >actual &&
1085 git cat-file --use-mailmap -s v3 >>actual &&
1086 test_cmp expect actual
1089 test_expect_success
'git cat-file --batch-check returns correct size with --use-mailmap' '
1090 test_when_finished "rm .mailmap" &&
1091 cat >.mailmap <<-\EOF &&
1092 C O Mitter <committer@example.com> Orig <orig@example.com>
1094 git cat-file commit HEAD >commit.out &&
1095 commit_size=$(wc -c <commit.out) &&
1096 commit_sha=$(git rev-parse HEAD) &&
1097 echo $commit_sha commit $commit_size >expect &&
1098 git cat-file --use-mailmap commit HEAD >commit.out &&
1099 commit_size=$(wc -c <commit.out) &&
1100 echo $commit_sha commit $commit_size >>expect &&
1102 git cat-file --batch-check <in >actual &&
1103 git cat-file --use-mailmap --batch-check <in >>actual &&
1104 test_cmp expect actual
1107 test_expect_success
'git cat-file --batch-command returns correct size with --use-mailmap' '
1108 test_when_finished "rm .mailmap" &&
1109 cat >.mailmap <<-\EOF &&
1110 C O Mitter <committer@example.com> Orig <orig@example.com>
1112 git cat-file commit HEAD >commit.out &&
1113 commit_size=$(wc -c <commit.out) &&
1114 commit_sha=$(git rev-parse HEAD) &&
1115 echo $commit_sha commit $commit_size >expect &&
1116 git cat-file --use-mailmap commit HEAD >commit.out &&
1117 commit_size=$(wc -c <commit.out) &&
1118 echo $commit_sha commit $commit_size >>expect &&
1119 echo "info HEAD" >in &&
1120 git cat-file --batch-command <in >actual &&
1121 git cat-file --use-mailmap --batch-command <in >>actual &&
1122 test_cmp expect actual