Merge branch 'cp/git-flush-is-an-env-bool'
[alt-git.git] / t / t4203-mailmap.sh
blob8a88dd7900ca8a63327bf0853403a38a2c2bc5a9
1 #!/bin/sh
3 test_description='.mailmap configurations'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
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
15 test_expect_success 'check-mailmap no arguments' '
16 test_must_fail git check-mailmap
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
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
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 &&
50 git check-mailmap --stdin "Internal Guy <bugs@company.xy>" \
51 <contacts >actual &&
52 test_cmp expect actual
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
64 cp .mailmap expect &&
65 git check-mailmap --stdin <stdin >actual &&
66 test_cmp expect actual &&
68 cat .mailmap >>expect &&
69 git check-mailmap --stdin "Another Old Name <$GIT_AUTHOR_EMAIL>" \
70 <stdin >actual &&
71 test_cmp expect actual
74 test_expect_success 'check-mailmap bogus contact' '
75 test_must_fail git check-mailmap bogus
78 test_expect_success 'check-mailmap bogus contact --stdin' '
79 test_must_fail git check-mailmap --stdin bogus </dev/null
82 test_expect_success 'No mailmap' '
83 cat >expect <<-EOF &&
84 $GIT_AUTHOR_NAME (1):
85 initial
87 nick1 (1):
88 second
90 EOF
91 git shortlog HEAD >actual &&
92 test_cmp expect actual
95 test_expect_success 'setup default .mailmap' '
96 cat >default.map <<-EOF
97 Repo Guy <$GIT_AUTHOR_EMAIL>
98 EOF
101 test_expect_success 'test default .mailmap' '
102 test_when_finished "rm .mailmap" &&
103 cp default.map .mailmap &&
105 cat >expect <<-\EOF &&
106 Repo Guy (1):
107 initial
109 nick1 (1):
110 second
113 git shortlog HEAD >actual &&
114 test_cmp expect actual
117 test_expect_success 'mailmap.file set' '
118 test_when_finished "rm .mailmap" &&
119 cp default.map .mailmap &&
121 test_config mailmap.file internal.map &&
122 cat >internal.map <<-\EOF &&
123 Internal Guy <bugs@company.xx>
126 cat >expect <<-\EOF &&
127 Internal Guy (1):
128 second
130 Repo Guy (1):
131 initial
134 git shortlog HEAD >actual &&
135 test_cmp expect actual &&
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 &&
142 cd sub-repo &&
143 cp ../.mailmap . &&
144 git config mailmap.file ../internal.map &&
145 git shortlog HEAD >actual &&
146 test_cmp ../expect actual
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>
157 cat >expect <<-\EOF &&
158 External Guy (1):
159 initial
161 Internal Guy (1):
162 second
165 git shortlog HEAD >actual &&
166 test_cmp expect actual
169 test_expect_success 'mailmap.file non-existent' '
170 test_when_finished "rm .mailmap" &&
171 cp default.map .mailmap &&
173 cat >expect <<-\EOF &&
174 Repo Guy (1):
175 initial
177 nick1 (1):
178 second
181 git shortlog HEAD >actual &&
182 test_cmp expect actual
185 test_expect_success 'name entry after email entry' '
186 test_when_finished "rm .mailmap" &&
187 cp default.map .mailmap &&
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>
195 cat >expect <<-\EOF &&
196 Internal Guy (1):
197 second
199 Repo Guy (1):
200 initial
204 git shortlog HEAD >actual &&
205 test_cmp expect actual
208 test_expect_success 'name entry after email entry, case-insensitive' '
209 test_when_finished "rm .mailmap" &&
210 cp default.map .mailmap &&
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>
218 cat >expect <<-\EOF &&
219 Internal Guy (1):
220 second
222 Repo Guy (1):
223 initial
226 git shortlog HEAD >actual &&
227 test_cmp expect actual &&
229 cat >internal.map <<-\EOF &&
230 NiCk <BuGs@CoMpAnY.Xy> NICK1 <BUGS@COMPANY.XX>
233 cat >expect <<-\EOF &&
234 NiCk (1):
235 second
237 Repo Guy (1):
238 initial
241 git shortlog HEAD >actual &&
242 test_cmp expect actual
245 test_expect_success 'No mailmap files, but configured' '
246 cat >expect <<-EOF &&
247 $GIT_AUTHOR_NAME (1):
248 initial
250 nick1 (1):
251 second
254 git shortlog HEAD >actual &&
255 test_cmp expect actual
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>
264 cat >both <<-EOF &&
265 Blob Guy <$GIT_AUTHOR_EMAIL>
266 Blob Guy <bugs@company.xx>
268 printf "Tricky Guy <$GIT_AUTHOR_EMAIL>" >no-newline &&
269 git add just-bugs both no-newline &&
270 git commit -m "my mailmaps" &&
272 cat >internal.map <<-EOF
273 Internal Guy <$GIT_AUTHOR_EMAIL>
277 test_expect_success 'mailmap.blob set' '
278 test_when_finished "rm .mailmap" &&
279 cp default.map .mailmap &&
281 cat >expect <<-\EOF &&
282 Blob Guy (1):
283 second
285 Repo Guy (1):
286 initial
289 git -c mailmap.blob=map:just-bugs shortlog HEAD >actual &&
290 test_cmp expect actual
293 test_expect_success 'mailmap.blob overrides .mailmap' '
294 test_when_finished "rm .mailmap" &&
295 cp default.map .mailmap &&
297 cat >expect <<-\EOF &&
298 Blob Guy (2):
299 initial
300 second
303 git -c mailmap.blob=map:both shortlog HEAD >actual &&
304 test_cmp expect actual
307 test_expect_success 'mailmap.file overrides mailmap.blob' '
308 cat >expect <<-\EOF &&
309 Blob Guy (1):
310 second
312 Internal Guy (1):
313 initial
316 git \
317 -c mailmap.blob=map:both \
318 -c mailmap.file=internal.map \
319 shortlog HEAD >actual &&
320 test_cmp expect actual
323 test_expect_success 'mailmap.file can be missing' '
324 test_when_finished "rm .mailmap" &&
325 cp default.map .mailmap &&
327 test_config mailmap.file nonexistent &&
328 cat >expect <<-\EOF &&
329 Repo Guy (1):
330 initial
332 nick1 (1):
333 second
336 git shortlog HEAD >actual 2>err &&
337 test_must_be_empty err &&
338 test_cmp expect actual
341 test_expect_success 'mailmap.blob can be missing' '
342 test_when_finished "rm .mailmap" &&
343 cp default.map .mailmap &&
345 cat >expect <<-\EOF &&
346 Repo Guy (1):
347 initial
349 nick1 (1):
350 second
353 git -c mailmap.blob=map:nonexistent shortlog HEAD >actual 2>err &&
354 test_must_be_empty err &&
355 test_cmp expect actual
358 test_expect_success 'mailmap.blob might be the wrong type' '
359 test_when_finished "rm .mailmap" &&
360 cp default.map .mailmap &&
362 git -c mailmap.blob=HEAD: shortlog HEAD >actual 2>err &&
363 test_grep "mailmap is not a blob" err &&
364 test_cmp expect actual
367 test_expect_success 'mailmap.blob defaults to off in non-bare repo' '
368 git init non-bare &&
370 cd non-bare &&
371 test_commit one .mailmap "Fake Name <$GIT_AUTHOR_EMAIL>" &&
372 cat >expect <<-\EOF &&
373 1 Fake Name
375 git shortlog -ns HEAD >actual &&
376 test_cmp expect actual &&
377 rm .mailmap &&
378 cat >expect <<-EOF &&
379 1 $GIT_AUTHOR_NAME
381 git shortlog -ns HEAD >actual &&
382 test_cmp expect actual
386 test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' '
387 git clone --bare non-bare bare &&
389 cd bare &&
390 cat >expect <<-\EOF &&
391 1 Fake Name
393 git shortlog -ns HEAD >actual &&
394 test_cmp expect actual
398 test_expect_success 'mailmap.blob can handle blobs without trailing newline' '
399 cat >expect <<-\EOF &&
400 Tricky Guy (1):
401 initial
403 nick1 (1):
404 second
407 git -c mailmap.blob=map:no-newline shortlog HEAD >actual &&
408 test_cmp expect actual
411 test_expect_success 'single-character name' '
412 test_when_finished "rm .mailmap" &&
413 cat >.mailmap <<-EOF &&
414 A <$GIT_AUTHOR_EMAIL>
417 cat >expect <<-EOF &&
418 1 A <$GIT_AUTHOR_EMAIL>
419 1 nick1 <bugs@company.xx>
421 git shortlog -es HEAD >actual &&
422 test_cmp expect actual
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>
431 cat >expect <<-EOF &&
432 1 $GIT_AUTHOR_NAME <AUTHOR@example.com>
433 1 nick1 <bugs@company.xx>
435 git shortlog -es HEAD >actual &&
436 test_cmp expect actual
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
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)>
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>
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>
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>
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>
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>
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
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)>
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>
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>
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>
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>
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>
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
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>
511 test_commit -C doc --author "Joe <bugs@example.com>" F &&
512 test_commit -C doc --author "Jane <bugs@example.com>" G &&
514 cat >>expect <<-\EOF &&
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>
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>
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
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>
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 &&
544 cat >expect <<-EOF &&
545 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1):
546 initial
548 CTO <cto@company.xx> (1):
549 seventh
551 Other Author <other@author.xx> (2):
552 third
553 fourth
555 Santa Claus <santa.claus@northpole.xx> (2):
556 fifth
557 sixth
559 Some Dude <some@dude.xx> (1):
560 second
564 git shortlog -e HEAD >actual &&
565 test_cmp expect actual
569 test_expect_success 'Log output (complex mapping)' '
570 test_config mailmap.file complex.map &&
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>
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>
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>
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>
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>
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>
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>
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
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
604 Author email me@company.xx has local-part me
605 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
607 Author email me@company.xx has local-part me
608 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
610 Author email nick2@company.xx has local-part nick2
611 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
613 Author email bugs@company.xx has local-part bugs
614 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
616 Author email bugs@company.xx has local-part bugs
617 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
619 Author email author@example.com has local-part author
620 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
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
627 test_expect_success 'Log output with --use-mailmap' '
628 test_config mailmap.file complex.map &&
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>
640 git log --use-mailmap >log &&
641 grep Author log >actual &&
642 test_cmp expect actual
645 test_expect_success 'Log output with log.mailmap' '
646 test_config mailmap.file complex.map &&
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>
658 git -c log.mailmap=True log >log &&
659 grep Author log >actual &&
660 test_cmp expect actual
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>
673 git -c log.mailmap=false log >log &&
674 grep Author log >actual &&
675 test_cmp expect actual
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>
688 git log --no-use-mailmap >log &&
689 grep Author log >actual &&
690 test_cmp expect actual
693 test_expect_success 'Grep author with --use-mailmap' '
694 test_config mailmap.file complex.map &&
696 cat >expect <<-\EOF &&
697 Author: Santa Claus <santa.claus@northpole.xx>
698 Author: Santa Claus <santa.claus@northpole.xx>
700 git log --use-mailmap --author Santa >log &&
701 grep Author log >actual &&
702 test_cmp expect actual
705 test_expect_success 'Grep author with log.mailmap' '
706 test_config mailmap.file complex.map &&
708 cat >expect <<-\EOF &&
709 Author: Santa Claus <santa.claus@northpole.xx>
710 Author: Santa Claus <santa.claus@northpole.xx>
713 git -c log.mailmap=True log --author Santa >log &&
714 grep Author log >actual &&
715 test_cmp expect actual
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
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
731 test_expect_success 'Blame --porcelain output (complex mapping)' '
732 test_config mailmap.file complex.map &&
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
751 git blame --porcelain one >actual.blame &&
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
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
767 test_expect_success 'commit --author honors mailmap' '
768 test_config mailmap.file complex.map &&
770 cat >expect <<-\EOF &&
771 Some Dude <some@dude.xx>
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
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 &&
787 test_config -C comm mailmap.file ../doc.map &&
788 cat >>doc.map <<-\EOF &&
789 # Ah <a@example.com>
791 ; Bee <b@example.com>
792 Cee <cee@example.com> <#@example.com>
793 Dee <dee@example.com> <d@e#ample.com>
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>
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>
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>
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>
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
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 &&
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>
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>
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>
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>
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>
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>
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>
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>
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>
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
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 &&
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>
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>
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>
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>
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
892 test_expect_success 'set up mailmap location tests' '
893 git init --bare loc-bare &&
894 git --git-dir=loc-bare --work-tree=. commit \
895 --allow-empty -m foo --author="Orig <orig@example.com>" &&
896 echo "New <new@example.com> <orig@example.com>" >loc-bare/.mailmap
899 test_expect_success 'bare repo with --work-tree finds mailmap at top-level' '
900 git -C loc-bare --work-tree=. log -1 --format=%aE >actual &&
901 echo new@example.com >expect &&
902 test_cmp expect actual
905 test_expect_success 'bare repo does not look in current directory' '
906 git -C loc-bare log -1 --format=%aE >actual &&
907 echo orig@example.com >expect &&
908 test_cmp expect actual
911 test_expect_success 'non-git shortlog respects mailmap in current dir' '
912 git --git-dir=loc-bare log -1 >input &&
913 nongit cp "$TRASH_DIRECTORY/loc-bare/.mailmap" . &&
914 nongit git shortlog -s <input >actual &&
915 echo " 1 New" >expect &&
916 test_cmp expect actual
919 test_expect_success 'shortlog on stdin respects mailmap from repo' '
920 cp loc-bare/.mailmap . &&
921 git shortlog -s <input >actual &&
922 echo " 1 New" >expect &&
923 test_cmp expect actual
926 test_expect_success 'find top-level mailmap from subdir' '
927 git clone loc-bare loc-wt &&
928 cp loc-bare/.mailmap loc-wt &&
929 mkdir loc-wt/subdir &&
930 git -C loc-wt/subdir log -1 --format=%aE >actual &&
931 echo new@example.com >expect &&
932 test_cmp expect actual
935 test_expect_success SYMLINKS 'set up symlink tests' '
936 git commit --allow-empty -m foo --author="Orig <orig@example.com>" &&
937 echo "New <new@example.com> <orig@example.com>" >map &&
938 rm -f .mailmap
941 test_expect_success SYMLINKS 'symlinks respected in mailmap.file' '
942 test_when_finished "rm symlink" &&
943 ln -s map symlink &&
944 git -c mailmap.file="$(pwd)/symlink" log -1 --format=%aE >actual &&
945 echo "new@example.com" >expect &&
946 test_cmp expect actual
949 test_expect_success SYMLINKS 'symlinks respected in non-repo shortlog' '
950 git log -1 >input &&
951 test_when_finished "nongit rm .mailmap" &&
952 nongit ln -sf "$TRASH_DIRECTORY/map" .mailmap &&
953 nongit git shortlog -s <input >actual &&
954 echo " 1 New" >expect &&
955 test_cmp expect actual
958 test_expect_success SYMLINKS 'symlinks not respected in-tree' '
959 test_when_finished "rm .mailmap" &&
960 ln -s map .mailmap &&
961 git log -1 --format=%aE >actual &&
962 echo "orig@example.com" >expect &&
963 test_cmp expect actual
966 test_expect_success 'prepare for cat-file --mailmap' '
967 rm -f .mailmap &&
968 git commit --allow-empty -m foo --author="Orig <orig@example.com>"
971 test_expect_success '--no-use-mailmap disables mailmap in cat-file' '
972 test_when_finished "rm .mailmap" &&
973 cat >.mailmap <<-EOF &&
974 A U Thor <author@example.com> Orig <orig@example.com>
976 cat >expect <<-EOF &&
977 author Orig <orig@example.com>
979 git cat-file --no-use-mailmap commit HEAD >log &&
980 sed -n "/^author /s/\([^>]*>\).*/\1/p" log >actual &&
981 test_cmp expect actual
984 test_expect_success '--use-mailmap enables mailmap in cat-file' '
985 test_when_finished "rm .mailmap" &&
986 cat >.mailmap <<-EOF &&
987 A U Thor <author@example.com> Orig <orig@example.com>
989 cat >expect <<-EOF &&
990 author A U Thor <author@example.com>
992 git cat-file --use-mailmap commit HEAD >log &&
993 sed -n "/^author /s/\([^>]*>\).*/\1/p" log >actual &&
994 test_cmp expect actual
997 test_expect_success '--no-mailmap disables mailmap in cat-file for annotated tag objects' '
998 test_when_finished "rm .mailmap" &&
999 cat >.mailmap <<-EOF &&
1000 Orig <orig@example.com> C O Mitter <committer@example.com>
1002 cat >expect <<-EOF &&
1003 tagger C O Mitter <committer@example.com>
1005 git tag -a -m "annotated tag" v1 &&
1006 git cat-file --no-mailmap -p v1 >log &&
1007 sed -n "/^tagger /s/\([^>]*>\).*/\1/p" log >actual &&
1008 test_cmp expect actual
1011 test_expect_success '--mailmap enables mailmap in cat-file for annotated tag objects' '
1012 test_when_finished "rm .mailmap" &&
1013 cat >.mailmap <<-EOF &&
1014 Orig <orig@example.com> C O Mitter <committer@example.com>
1016 cat >expect <<-EOF &&
1017 tagger Orig <orig@example.com>
1019 git tag -a -m "annotated tag" v2 &&
1020 git cat-file --mailmap -p v2 >log &&
1021 sed -n "/^tagger /s/\([^>]*>\).*/\1/p" log >actual &&
1022 test_cmp expect actual
1025 test_expect_success 'git cat-file -s returns correct size with --use-mailmap' '
1026 test_when_finished "rm .mailmap" &&
1027 cat >.mailmap <<-\EOF &&
1028 C O Mitter <committer@example.com> Orig <orig@example.com>
1030 git cat-file commit HEAD >commit.out &&
1031 echo $(wc -c <commit.out) >expect &&
1032 git cat-file --use-mailmap commit HEAD >commit.out &&
1033 echo $(wc -c <commit.out) >>expect &&
1034 git cat-file -s HEAD >actual &&
1035 git cat-file --use-mailmap -s HEAD >>actual &&
1036 test_cmp expect actual
1039 test_expect_success 'git cat-file -s returns correct size with --use-mailmap for tag objects' '
1040 test_when_finished "rm .mailmap" &&
1041 cat >.mailmap <<-\EOF &&
1042 Orig <orig@example.com> C O Mitter <committer@example.com>
1044 git tag -a -m "annotated tag" v3 &&
1045 git cat-file tag v3 >tag.out &&
1046 echo $(wc -c <tag.out) >expect &&
1047 git cat-file --use-mailmap tag v3 >tag.out &&
1048 echo $(wc -c <tag.out) >>expect &&
1049 git cat-file -s v3 >actual &&
1050 git cat-file --use-mailmap -s v3 >>actual &&
1051 test_cmp expect actual
1054 test_expect_success 'git cat-file --batch-check returns correct size with --use-mailmap' '
1055 test_when_finished "rm .mailmap" &&
1056 cat >.mailmap <<-\EOF &&
1057 C O Mitter <committer@example.com> Orig <orig@example.com>
1059 git cat-file commit HEAD >commit.out &&
1060 commit_size=$(wc -c <commit.out) &&
1061 commit_sha=$(git rev-parse HEAD) &&
1062 echo $commit_sha commit $commit_size >expect &&
1063 git cat-file --use-mailmap commit HEAD >commit.out &&
1064 commit_size=$(wc -c <commit.out) &&
1065 echo $commit_sha commit $commit_size >>expect &&
1066 echo "HEAD" >in &&
1067 git cat-file --batch-check <in >actual &&
1068 git cat-file --use-mailmap --batch-check <in >>actual &&
1069 test_cmp expect actual
1072 test_expect_success 'git cat-file --batch-command returns correct size with --use-mailmap' '
1073 test_when_finished "rm .mailmap" &&
1074 cat >.mailmap <<-\EOF &&
1075 C O Mitter <committer@example.com> Orig <orig@example.com>
1077 git cat-file commit HEAD >commit.out &&
1078 commit_size=$(wc -c <commit.out) &&
1079 commit_sha=$(git rev-parse HEAD) &&
1080 echo $commit_sha commit $commit_size >expect &&
1081 git cat-file --use-mailmap commit HEAD >commit.out &&
1082 commit_size=$(wc -c <commit.out) &&
1083 echo $commit_sha commit $commit_size >>expect &&
1084 echo "info HEAD" >in &&
1085 git cat-file --batch-command <in >actual &&
1086 git cat-file --use-mailmap --batch-command <in >>actual &&
1087 test_cmp expect actual
1090 test_done