mailmap: plug memory leak in read_mailmap_blob()
[git/gitster.git] / t / t4203-mailmap.sh
blob79e5f42760d9190376442243cebf0273d8cae330
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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
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' '
21 cat >expect <<-EOF &&
22 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
23 nick1 <bugs@company.xx>
24 EOF
25 git check-mailmap \
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' '
32 cat >expect <<-EOF &&
33 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
34 nick1 <bugs@company.xx>
35 EOF
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>
45 EOF
46 cat >expect <<-\EOF &&
47 Internal Guy <bugs@company.xy>
48 EOF
49 cat contacts >>expect &&
51 git check-mailmap --stdin "Internal Guy <bugs@company.xy>" \
52 <contacts >actual &&
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>
60 EOF
61 cat >stdin <<-EOF &&
62 Old Name <$GIT_AUTHOR_EMAIL>
63 EOF
65 cp .mailmap expect &&
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>" \
71 <stdin >actual &&
72 test_cmp expect actual
75 test_expect_success 'check-mailmap bogus contact' '
76 test_must_fail git check-mailmap bogus
79 test_expect_success 'check-mailmap bogus contact --stdin' '
80 test_must_fail git check-mailmap --stdin bogus </dev/null
83 test_expect_success 'No mailmap' '
84 cat >expect <<-EOF &&
85 $GIT_AUTHOR_NAME (1):
86 initial
88 nick1 (1):
89 second
91 EOF
92 git shortlog HEAD >actual &&
93 test_cmp expect actual
96 test_expect_success 'setup default .mailmap' '
97 cat >default.map <<-EOF
98 Repo Guy <$GIT_AUTHOR_EMAIL>
99 EOF
102 test_expect_success 'test default .mailmap' '
103 test_when_finished "rm .mailmap" &&
104 cp default.map .mailmap &&
106 cat >expect <<-\EOF &&
107 Repo Guy (1):
108 initial
110 nick1 (1):
111 second
114 git shortlog HEAD >actual &&
115 test_cmp expect actual
118 test_expect_success 'mailmap.file set' '
119 test_when_finished "rm .mailmap" &&
120 cp default.map .mailmap &&
122 test_config mailmap.file internal.map &&
123 cat >internal.map <<-\EOF &&
124 Internal Guy <bugs@company.xx>
127 cat >expect <<-\EOF &&
128 Internal Guy (1):
129 second
131 Repo Guy (1):
132 initial
135 git shortlog HEAD >actual &&
136 test_cmp expect actual &&
138 # The internal_mailmap/.mailmap file is an a subdirectory, but
139 # as shown here it can also be outside the repository
140 test_when_finished "rm -rf sub-repo" &&
141 git clone . sub-repo &&
143 cd sub-repo &&
144 cp ../.mailmap . &&
145 git config mailmap.file ../internal.map &&
146 git shortlog HEAD >actual &&
147 test_cmp ../expect actual
151 test_expect_success 'mailmap.file override' '
152 test_config mailmap.file internal.map &&
153 cat >internal.map <<-EOF &&
154 Internal Guy <bugs@company.xx>
155 External Guy <$GIT_AUTHOR_EMAIL>
158 cat >expect <<-\EOF &&
159 External Guy (1):
160 initial
162 Internal Guy (1):
163 second
166 git shortlog HEAD >actual &&
167 test_cmp expect actual
170 test_expect_success 'mailmap.file non-existent' '
171 test_when_finished "rm .mailmap" &&
172 cp default.map .mailmap &&
174 cat >expect <<-\EOF &&
175 Repo Guy (1):
176 initial
178 nick1 (1):
179 second
182 git shortlog HEAD >actual &&
183 test_cmp expect actual
186 test_expect_success 'name entry after email entry' '
187 test_when_finished "rm .mailmap" &&
188 cp default.map .mailmap &&
190 test_config mailmap.file internal.map &&
191 cat >internal.map <<-\EOF &&
192 <bugs@company.xy> <bugs@company.xx>
193 Internal Guy <bugs@company.xx>
196 cat >expect <<-\EOF &&
197 Internal Guy (1):
198 second
200 Repo Guy (1):
201 initial
205 git shortlog HEAD >actual &&
206 test_cmp expect actual
209 test_expect_success 'name entry after email entry, case-insensitive' '
210 test_when_finished "rm .mailmap" &&
211 cp default.map .mailmap &&
213 test_config mailmap.file internal.map &&
214 cat >internal.map <<-\EOF &&
215 <bugs@company.xy> <bugs@company.xx>
216 Internal Guy <BUGS@Company.xx>
219 cat >expect <<-\EOF &&
220 Internal Guy (1):
221 second
223 Repo Guy (1):
224 initial
227 git shortlog HEAD >actual &&
228 test_cmp expect actual &&
230 cat >internal.map <<-\EOF &&
231 NiCk <BuGs@CoMpAnY.Xy> NICK1 <BUGS@COMPANY.XX>
234 cat >expect <<-\EOF &&
235 NiCk (1):
236 second
238 Repo Guy (1):
239 initial
242 git shortlog HEAD >actual &&
243 test_cmp expect actual
246 test_expect_success 'No mailmap files, but configured' '
247 cat >expect <<-EOF &&
248 $GIT_AUTHOR_NAME (1):
249 initial
251 nick1 (1):
252 second
255 git shortlog HEAD >actual &&
256 test_cmp expect actual
259 test_expect_success 'setup mailmap blob tests' '
260 git checkout -b map &&
261 test_when_finished "git checkout main" &&
262 cat >just-bugs <<-\EOF &&
263 Blob Guy <bugs@company.xx>
265 cat >both <<-EOF &&
266 Blob Guy <$GIT_AUTHOR_EMAIL>
267 Blob Guy <bugs@company.xx>
269 printf "Tricky Guy <$GIT_AUTHOR_EMAIL>" >no-newline &&
270 git add just-bugs both no-newline &&
271 git commit -m "my mailmaps" &&
273 cat >internal.map <<-EOF
274 Internal Guy <$GIT_AUTHOR_EMAIL>
278 test_expect_success 'mailmap.blob set' '
279 test_when_finished "rm .mailmap" &&
280 cp default.map .mailmap &&
282 cat >expect <<-\EOF &&
283 Blob Guy (1):
284 second
286 Repo Guy (1):
287 initial
290 git -c mailmap.blob=map:just-bugs shortlog HEAD >actual &&
291 test_cmp expect actual
294 test_expect_success 'mailmap.blob overrides .mailmap' '
295 test_when_finished "rm .mailmap" &&
296 cp default.map .mailmap &&
298 cat >expect <<-\EOF &&
299 Blob Guy (2):
300 initial
301 second
304 git -c mailmap.blob=map:both shortlog HEAD >actual &&
305 test_cmp expect actual
308 test_expect_success 'mailmap.file overrides mailmap.blob' '
309 cat >expect <<-\EOF &&
310 Blob Guy (1):
311 second
313 Internal Guy (1):
314 initial
317 git \
318 -c mailmap.blob=map:both \
319 -c mailmap.file=internal.map \
320 shortlog HEAD >actual &&
321 test_cmp expect actual
324 test_expect_success 'mailmap.file can be missing' '
325 test_when_finished "rm .mailmap" &&
326 cp default.map .mailmap &&
328 test_config mailmap.file nonexistent &&
329 cat >expect <<-\EOF &&
330 Repo Guy (1):
331 initial
333 nick1 (1):
334 second
337 git shortlog HEAD >actual 2>err &&
338 test_must_be_empty err &&
339 test_cmp expect actual
342 test_expect_success 'mailmap.blob can be missing' '
343 test_when_finished "rm .mailmap" &&
344 cp default.map .mailmap &&
346 cat >expect <<-\EOF &&
347 Repo Guy (1):
348 initial
350 nick1 (1):
351 second
354 git -c mailmap.blob=map:nonexistent shortlog HEAD >actual 2>err &&
355 test_must_be_empty err &&
356 test_cmp expect actual
359 test_expect_success 'mailmap.blob might be the wrong type' '
360 test_when_finished "rm .mailmap" &&
361 cp default.map .mailmap &&
363 git -c mailmap.blob=HEAD: shortlog HEAD >actual 2>err &&
364 test_grep "mailmap is not a blob" err &&
365 test_cmp expect actual
368 test_expect_success 'mailmap.blob defaults to off in non-bare repo' '
369 git init non-bare &&
371 cd non-bare &&
372 test_commit one .mailmap "Fake Name <$GIT_AUTHOR_EMAIL>" &&
373 cat >expect <<-\EOF &&
374 1 Fake Name
376 git shortlog -ns HEAD >actual &&
377 test_cmp expect actual &&
378 rm .mailmap &&
379 cat >expect <<-EOF &&
380 1 $GIT_AUTHOR_NAME
382 git shortlog -ns HEAD >actual &&
383 test_cmp expect actual
387 test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' '
388 git clone --bare non-bare bare &&
390 cd bare &&
391 cat >expect <<-\EOF &&
392 1 Fake Name
394 git shortlog -ns HEAD >actual &&
395 test_cmp expect actual
399 test_expect_success 'mailmap.blob can handle blobs without trailing newline' '
400 cat >expect <<-\EOF &&
401 Tricky Guy (1):
402 initial
404 nick1 (1):
405 second
408 git -c mailmap.blob=map:no-newline shortlog HEAD >actual &&
409 test_cmp expect actual
412 test_expect_success 'single-character name' '
413 test_when_finished "rm .mailmap" &&
414 cat >.mailmap <<-EOF &&
415 A <$GIT_AUTHOR_EMAIL>
418 cat >expect <<-EOF &&
419 1 A <$GIT_AUTHOR_EMAIL>
420 1 nick1 <bugs@company.xx>
422 git shortlog -es HEAD >actual &&
423 test_cmp expect actual
426 test_expect_success 'preserve canonical email case' '
427 test_when_finished "rm .mailmap" &&
428 cat >.mailmap <<-EOF &&
429 <AUTHOR@example.com> <$GIT_AUTHOR_EMAIL>
432 cat >expect <<-EOF &&
433 1 $GIT_AUTHOR_NAME <AUTHOR@example.com>
434 1 nick1 <bugs@company.xx>
436 git shortlog -es HEAD >actual &&
437 test_cmp expect actual
440 test_expect_success 'gitmailmap(5) example output: setup' '
441 test_create_repo doc &&
442 test_commit -C doc --author "Joe Developer <joe@example.com>" A &&
443 test_commit -C doc --author "Joe R. Developer <joe@example.com>" B &&
444 test_commit -C doc --author "Jane Doe <jane@example.com>" C &&
445 test_commit -C doc --author "Jane Doe <jane@laptop.(none)>" D &&
446 test_commit -C doc --author "Jane D. <jane@desktop.(none)>" E
449 test_expect_success 'gitmailmap(5) example output: example #1' '
450 test_config -C doc mailmap.file ../doc.map &&
451 cat >doc.map <<-\EOF &&
452 Joe R. Developer <joe@example.com>
453 Jane Doe <jane@example.com>
454 Jane Doe <jane@desktop.(none)>
457 cat >expect <<-\EOF &&
458 Author Joe Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
459 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
461 Author Joe R. Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
462 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
464 Author Jane Doe <jane@example.com> maps to Jane Doe <jane@example.com>
465 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
467 Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <jane@laptop.(none)>
468 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
470 Author Jane D. <jane@desktop.(none)> maps to Jane Doe <jane@desktop.(none)>
471 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
473 git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
474 test_cmp expect actual
477 test_expect_success 'gitmailmap(5) example output: example #2' '
478 test_config -C doc mailmap.file ../doc.map &&
479 cat >doc.map <<-\EOF &&
480 Joe R. Developer <joe@example.com>
481 Jane Doe <jane@example.com> <jane@laptop.(none)>
482 Jane Doe <jane@example.com> <jane@desktop.(none)>
485 cat >expect <<-\EOF &&
486 Author Joe Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
487 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
489 Author Joe R. Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
490 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
492 Author Jane Doe <jane@example.com> maps to Jane Doe <jane@example.com>
493 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
495 Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <jane@example.com>
496 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
498 Author Jane D. <jane@desktop.(none)> maps to Jane Doe <jane@example.com>
499 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
501 git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
502 test_cmp expect actual
505 test_expect_success 'gitmailmap(5) example output: example #3' '
506 test_config -C doc mailmap.file ../doc.map &&
507 cat >>doc.map <<-\EOF &&
508 Joe R. Developer <joe@example.com> Joe <bugs@example.com>
509 Jane Doe <jane@example.com> Jane <bugs@example.com>
512 test_commit -C doc --author "Joe <bugs@example.com>" F &&
513 test_commit -C doc --author "Jane <bugs@example.com>" G &&
515 cat >>expect <<-\EOF &&
517 Author Joe <bugs@example.com> maps to Joe R. Developer <joe@example.com>
518 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
520 Author Jane <bugs@example.com> maps to Jane Doe <jane@example.com>
521 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
523 git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
524 test_cmp expect actual
528 test_expect_success 'Shortlog output (complex mapping)' '
529 test_config mailmap.file complex.map &&
530 cat >complex.map <<-EOF &&
531 Committed <$GIT_COMMITTER_EMAIL>
532 <cto@company.xx> <cto@coompany.xx>
533 Some Dude <some@dude.xx> nick1 <bugs@company.xx>
534 Other Author <other@author.xx> nick2 <bugs@company.xx>
535 Other Author <other@author.xx> <nick2@company.xx>
536 Santa Claus <santa.claus@northpole.xx> <me@company.xx>
539 test_commit --author "nick2 <bugs@company.xx>" --append third one three &&
540 test_commit --author "nick2 <nick2@company.xx>" --append fourth one four &&
541 test_commit --author "santa <me@company.xx>" --append fifth one five &&
542 test_commit --author "claus <me@company.xx>" --append sixth one six &&
543 test_commit --author "CTO <cto@coompany.xx>" --append seventh one seven &&
545 cat >expect <<-EOF &&
546 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1):
547 initial
549 CTO <cto@company.xx> (1):
550 seventh
552 Other Author <other@author.xx> (2):
553 third
554 fourth
556 Santa Claus <santa.claus@northpole.xx> (2):
557 fifth
558 sixth
560 Some Dude <some@dude.xx> (1):
561 second
565 git shortlog -e HEAD >actual &&
566 test_cmp expect actual
570 test_expect_success 'Log output (complex mapping)' '
571 test_config mailmap.file complex.map &&
573 cat >expect <<-EOF &&
574 Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx>
575 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
577 Author claus <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
578 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
580 Author santa <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
581 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
583 Author nick2 <nick2@company.xx> maps to Other Author <other@author.xx>
584 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
586 Author nick2 <bugs@company.xx> maps to Other Author <other@author.xx>
587 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
589 Author nick1 <bugs@company.xx> maps to Some Dude <some@dude.xx>
590 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
592 Author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> maps to $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
593 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
596 git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
597 test_cmp expect actual
600 test_expect_success 'Log output (local-part email address)' '
601 cat >expect <<-EOF &&
602 Author email cto@coompany.xx has local-part cto
603 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
605 Author email me@company.xx has local-part me
606 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
608 Author email me@company.xx has local-part me
609 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
611 Author email nick2@company.xx has local-part nick2
612 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
614 Author email bugs@company.xx has local-part bugs
615 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
617 Author email bugs@company.xx has local-part bugs
618 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
620 Author email author@example.com has local-part author
621 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
624 git log --pretty=format:"Author email %ae has local-part %al%nCommitter email %ce has local-part %cl%n" >actual &&
625 test_cmp expect actual
628 test_expect_success 'Log output with --use-mailmap' '
629 test_config mailmap.file complex.map &&
631 cat >expect <<-EOF &&
632 Author: CTO <cto@company.xx>
633 Author: Santa Claus <santa.claus@northpole.xx>
634 Author: Santa Claus <santa.claus@northpole.xx>
635 Author: Other Author <other@author.xx>
636 Author: Other Author <other@author.xx>
637 Author: Some Dude <some@dude.xx>
638 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
641 git log --use-mailmap >log &&
642 grep Author log >actual &&
643 test_cmp expect actual
646 test_expect_success 'Log output with log.mailmap' '
647 test_config mailmap.file complex.map &&
649 cat >expect <<-EOF &&
650 Author: CTO <cto@company.xx>
651 Author: Santa Claus <santa.claus@northpole.xx>
652 Author: Santa Claus <santa.claus@northpole.xx>
653 Author: Other Author <other@author.xx>
654 Author: Other Author <other@author.xx>
655 Author: Some Dude <some@dude.xx>
656 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
659 git -c log.mailmap=True log >log &&
660 grep Author log >actual &&
661 test_cmp expect actual
664 test_expect_success 'log.mailmap=false disables mailmap' '
665 cat >expect <<-EOF &&
666 Author: CTO <cto@coompany.xx>
667 Author: claus <me@company.xx>
668 Author: santa <me@company.xx>
669 Author: nick2 <nick2@company.xx>
670 Author: nick2 <bugs@company.xx>
671 Author: nick1 <bugs@company.xx>
672 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
674 git -c log.mailmap=false log >log &&
675 grep Author log >actual &&
676 test_cmp expect actual
679 test_expect_success '--no-use-mailmap disables mailmap' '
680 cat >expect <<-EOF &&
681 Author: CTO <cto@coompany.xx>
682 Author: claus <me@company.xx>
683 Author: santa <me@company.xx>
684 Author: nick2 <nick2@company.xx>
685 Author: nick2 <bugs@company.xx>
686 Author: nick1 <bugs@company.xx>
687 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
689 git log --no-use-mailmap >log &&
690 grep Author log >actual &&
691 test_cmp expect actual
694 test_expect_success 'Grep author with --use-mailmap' '
695 test_config mailmap.file complex.map &&
697 cat >expect <<-\EOF &&
698 Author: Santa Claus <santa.claus@northpole.xx>
699 Author: Santa Claus <santa.claus@northpole.xx>
701 git log --use-mailmap --author Santa >log &&
702 grep Author log >actual &&
703 test_cmp expect actual
706 test_expect_success 'Grep author with log.mailmap' '
707 test_config mailmap.file complex.map &&
709 cat >expect <<-\EOF &&
710 Author: Santa Claus <santa.claus@northpole.xx>
711 Author: Santa Claus <santa.claus@northpole.xx>
714 git -c log.mailmap=True log --author Santa >log &&
715 grep Author log >actual &&
716 test_cmp expect actual
719 test_expect_success 'log.mailmap is true by default these days' '
720 test_config mailmap.file complex.map &&
721 git log --author Santa >log &&
722 grep Author log >actual &&
723 test_cmp expect actual
726 test_expect_success 'Only grep replaced author with --use-mailmap' '
727 test_config mailmap.file complex.map &&
728 git log --use-mailmap --author "<cto@coompany.xx>" >actual &&
729 test_must_be_empty actual
732 test_expect_success 'Blame --porcelain output (complex mapping)' '
733 test_config mailmap.file complex.map &&
735 cat >expect <<-EOF &&
736 1 1 1
737 A U Thor
738 2 2 1
739 Some Dude
740 3 3 1
741 Other Author
742 4 4 1
743 Other Author
744 5 5 1
745 Santa Claus
746 6 6 1
747 Santa Claus
748 7 7 1
752 git blame --porcelain one >actual.blame &&
754 NUM="[0-9][0-9]*" &&
755 sed -n <actual.blame >actual.fuzz \
756 -e "s/^author //p" \
757 -e "s/^$OID_REGEX \\($NUM $NUM $NUM\\)$/\\1/p" &&
758 test_cmp expect actual.fuzz
761 test_expect_success 'Blame output (complex mapping)' '
762 git -c mailmap.file=complex.map blame one >a &&
763 git blame one >b &&
764 test_file_not_empty a &&
765 ! cmp a b
768 test_expect_success 'commit --author honors mailmap' '
769 test_config mailmap.file complex.map &&
771 cat >expect <<-\EOF &&
772 Some Dude <some@dude.xx>
775 test_must_fail git commit --author "nick" --allow-empty -meight &&
776 git commit --author "Some Dude" --allow-empty -meight &&
777 git show --pretty=format:"%an <%ae>%n" >actual &&
778 test_cmp expect actual
781 test_expect_success 'comment syntax: setup' '
782 test_create_repo comm &&
783 test_commit -C comm --author "A <a@example.com>" A &&
784 test_commit -C comm --author "B <b@example.com>" B &&
785 test_commit -C comm --author "C <#@example.com>" C &&
786 test_commit -C comm --author "D <d@e#ample.com>" D &&
788 test_config -C comm mailmap.file ../doc.map &&
789 cat >>doc.map <<-\EOF &&
790 # Ah <a@example.com>
792 ; Bee <b@example.com>
793 Cee <cee@example.com> <#@example.com>
794 Dee <dee@example.com> <d@e#ample.com>
797 cat >expect <<-\EOF &&
798 Author A <a@example.com> maps to A <a@example.com>
799 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
801 Author B <b@example.com> maps to ; Bee <b@example.com>
802 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
804 Author C <#@example.com> maps to Cee <cee@example.com>
805 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
807 Author D <d@e#ample.com> maps to Dee <dee@example.com>
808 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
810 git -C comm log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
811 test_cmp expect actual
814 test_expect_success 'whitespace syntax: setup' '
815 test_create_repo space &&
816 test_commit -C space --author "A <a@example.com>" A &&
817 test_commit -C space --author "B <b@example.com>" B &&
818 test_commit -C space --author " C <c@example.com>" C &&
819 test_commit -C space --author " D <d@example.com>" D &&
820 test_commit -C space --author "E E <e@example.com>" E &&
821 test_commit -C space --author "F F <f@example.com>" F &&
822 test_commit -C space --author "G G <g@example.com>" G &&
823 test_commit -C space --author "H H <h@example.com>" H &&
825 test_config -C space mailmap.file ../space.map &&
826 cat >>space.map <<-\EOF &&
827 Ah <ah@example.com> < a@example.com >
828 Bee <bee@example.com > < b@example.com >
829 Cee <cee@example.com> C <c@example.com>
830 dee <dee@example.com> D <d@example.com>
831 eee <eee@example.com> E E <e@example.com>
832 eff <eff@example.com> F F <f@example.com>
833 gee <gee@example.com> G G <g@example.com>
834 aitch <aitch@example.com> H H <h@example.com>
837 cat >expect <<-\EOF &&
838 Author A <a@example.com> maps to A <a@example.com>
839 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
841 Author B <b@example.com> maps to B <b@example.com>
842 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
844 Author C <c@example.com> maps to Cee <cee@example.com>
845 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
847 Author D <d@example.com> maps to dee <dee@example.com>
848 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
850 Author E E <e@example.com> maps to eee <eee@example.com>
851 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
853 Author F F <f@example.com> maps to eff <eff@example.com>
854 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
856 Author G G <g@example.com> maps to gee <gee@example.com>
857 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
859 Author H H <h@example.com> maps to H H <h@example.com>
860 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
862 git -C space log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
863 test_cmp expect actual
866 test_expect_success 'empty syntax: setup' '
867 test_create_repo empty &&
868 test_commit -C empty --author "A <>" A &&
869 test_commit -C empty --author "B <b@example.com>" B &&
870 test_commit -C empty --author "C <c@example.com>" C &&
872 test_config -C empty mailmap.file ../empty.map &&
873 cat >>empty.map <<-\EOF &&
874 Ah <ah@example.com> <>
875 Bee <bee@example.com> <>
876 Cee <> <c@example.com>
879 cat >expect <<-\EOF &&
880 Author A <> maps to Bee <bee@example.com>
881 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
883 Author B <b@example.com> maps to B <b@example.com>
884 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
886 Author C <c@example.com> maps to C <c@example.com>
887 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
889 git -C empty log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
890 test_cmp expect actual
893 test_expect_success 'set up mailmap location tests' '
894 git init --bare loc-bare &&
895 git --git-dir=loc-bare --work-tree=. commit \
896 --allow-empty -m foo --author="Orig <orig@example.com>" &&
897 echo "New <new@example.com> <orig@example.com>" >loc-bare/.mailmap
900 test_expect_success 'bare repo with --work-tree finds mailmap at top-level' '
901 git -C loc-bare --work-tree=. log -1 --format=%aE >actual &&
902 echo new@example.com >expect &&
903 test_cmp expect actual
906 test_expect_success 'bare repo does not look in current directory' '
907 git -C loc-bare log -1 --format=%aE >actual &&
908 echo orig@example.com >expect &&
909 test_cmp expect actual
912 test_expect_success 'non-git shortlog respects mailmap in current dir' '
913 git --git-dir=loc-bare log -1 >input &&
914 nongit cp "$TRASH_DIRECTORY/loc-bare/.mailmap" . &&
915 nongit git shortlog -s <input >actual &&
916 echo " 1 New" >expect &&
917 test_cmp expect actual
920 test_expect_success 'shortlog on stdin respects mailmap from repo' '
921 cp loc-bare/.mailmap . &&
922 git shortlog -s <input >actual &&
923 echo " 1 New" >expect &&
924 test_cmp expect actual
927 test_expect_success 'find top-level mailmap from subdir' '
928 git clone loc-bare loc-wt &&
929 cp loc-bare/.mailmap loc-wt &&
930 mkdir loc-wt/subdir &&
931 git -C loc-wt/subdir log -1 --format=%aE >actual &&
932 echo new@example.com >expect &&
933 test_cmp expect actual
936 test_expect_success SYMLINKS 'set up symlink tests' '
937 git commit --allow-empty -m foo --author="Orig <orig@example.com>" &&
938 echo "New <new@example.com> <orig@example.com>" >map &&
939 rm -f .mailmap
942 test_expect_success SYMLINKS 'symlinks respected in mailmap.file' '
943 test_when_finished "rm symlink" &&
944 ln -s map symlink &&
945 git -c mailmap.file="$(pwd)/symlink" log -1 --format=%aE >actual &&
946 echo "new@example.com" >expect &&
947 test_cmp expect actual
950 test_expect_success SYMLINKS 'symlinks respected in non-repo shortlog' '
951 git log -1 >input &&
952 test_when_finished "nongit rm .mailmap" &&
953 nongit ln -sf "$TRASH_DIRECTORY/map" .mailmap &&
954 nongit git shortlog -s <input >actual &&
955 echo " 1 New" >expect &&
956 test_cmp expect actual
959 test_expect_success SYMLINKS 'symlinks not respected in-tree' '
960 test_when_finished "rm .mailmap" &&
961 ln -s map .mailmap &&
962 git log -1 --format=%aE >actual &&
963 echo "orig@example.com" >expect &&
964 test_cmp expect actual
967 test_expect_success 'prepare for cat-file --mailmap' '
968 rm -f .mailmap &&
969 git commit --allow-empty -m foo --author="Orig <orig@example.com>"
972 test_expect_success '--no-use-mailmap disables mailmap in cat-file' '
973 test_when_finished "rm .mailmap" &&
974 cat >.mailmap <<-EOF &&
975 A U Thor <author@example.com> Orig <orig@example.com>
977 cat >expect <<-EOF &&
978 author Orig <orig@example.com>
980 git cat-file --no-use-mailmap commit HEAD >log &&
981 sed -n "/^author /s/\([^>]*>\).*/\1/p" log >actual &&
982 test_cmp expect actual
985 test_expect_success '--use-mailmap enables mailmap in cat-file' '
986 test_when_finished "rm .mailmap" &&
987 cat >.mailmap <<-EOF &&
988 A U Thor <author@example.com> Orig <orig@example.com>
990 cat >expect <<-EOF &&
991 author A U Thor <author@example.com>
993 git cat-file --use-mailmap commit HEAD >log &&
994 sed -n "/^author /s/\([^>]*>\).*/\1/p" log >actual &&
995 test_cmp expect actual
998 test_expect_success '--no-mailmap disables mailmap in cat-file for annotated tag objects' '
999 test_when_finished "rm .mailmap" &&
1000 cat >.mailmap <<-EOF &&
1001 Orig <orig@example.com> C O Mitter <committer@example.com>
1003 cat >expect <<-EOF &&
1004 tagger C O Mitter <committer@example.com>
1006 git tag -a -m "annotated tag" v1 &&
1007 git cat-file --no-mailmap -p v1 >log &&
1008 sed -n "/^tagger /s/\([^>]*>\).*/\1/p" log >actual &&
1009 test_cmp expect actual
1012 test_expect_success '--mailmap enables mailmap in cat-file for annotated tag objects' '
1013 test_when_finished "rm .mailmap" &&
1014 cat >.mailmap <<-EOF &&
1015 Orig <orig@example.com> C O Mitter <committer@example.com>
1017 cat >expect <<-EOF &&
1018 tagger Orig <orig@example.com>
1020 git tag -a -m "annotated tag" v2 &&
1021 git cat-file --mailmap -p v2 >log &&
1022 sed -n "/^tagger /s/\([^>]*>\).*/\1/p" log >actual &&
1023 test_cmp expect actual
1026 test_expect_success 'git cat-file -s returns correct size with --use-mailmap' '
1027 test_when_finished "rm .mailmap" &&
1028 cat >.mailmap <<-\EOF &&
1029 C O Mitter <committer@example.com> Orig <orig@example.com>
1031 git cat-file commit HEAD >commit.out &&
1032 echo $(wc -c <commit.out) >expect &&
1033 git cat-file --use-mailmap commit HEAD >commit.out &&
1034 echo $(wc -c <commit.out) >>expect &&
1035 git cat-file -s HEAD >actual &&
1036 git cat-file --use-mailmap -s HEAD >>actual &&
1037 test_cmp expect actual
1040 test_expect_success 'git cat-file -s returns correct size with --use-mailmap for tag objects' '
1041 test_when_finished "rm .mailmap" &&
1042 cat >.mailmap <<-\EOF &&
1043 Orig <orig@example.com> C O Mitter <committer@example.com>
1045 git tag -a -m "annotated tag" v3 &&
1046 git cat-file tag v3 >tag.out &&
1047 echo $(wc -c <tag.out) >expect &&
1048 git cat-file --use-mailmap tag v3 >tag.out &&
1049 echo $(wc -c <tag.out) >>expect &&
1050 git cat-file -s v3 >actual &&
1051 git cat-file --use-mailmap -s v3 >>actual &&
1052 test_cmp expect actual
1055 test_expect_success 'git cat-file --batch-check returns correct size with --use-mailmap' '
1056 test_when_finished "rm .mailmap" &&
1057 cat >.mailmap <<-\EOF &&
1058 C O Mitter <committer@example.com> Orig <orig@example.com>
1060 git cat-file commit HEAD >commit.out &&
1061 commit_size=$(wc -c <commit.out) &&
1062 commit_sha=$(git rev-parse HEAD) &&
1063 echo $commit_sha commit $commit_size >expect &&
1064 git cat-file --use-mailmap commit HEAD >commit.out &&
1065 commit_size=$(wc -c <commit.out) &&
1066 echo $commit_sha commit $commit_size >>expect &&
1067 echo "HEAD" >in &&
1068 git cat-file --batch-check <in >actual &&
1069 git cat-file --use-mailmap --batch-check <in >>actual &&
1070 test_cmp expect actual
1073 test_expect_success 'git cat-file --batch-command returns correct size with --use-mailmap' '
1074 test_when_finished "rm .mailmap" &&
1075 cat >.mailmap <<-\EOF &&
1076 C O Mitter <committer@example.com> Orig <orig@example.com>
1078 git cat-file commit HEAD >commit.out &&
1079 commit_size=$(wc -c <commit.out) &&
1080 commit_sha=$(git rev-parse HEAD) &&
1081 echo $commit_sha commit $commit_size >expect &&
1082 git cat-file --use-mailmap commit HEAD >commit.out &&
1083 commit_size=$(wc -c <commit.out) &&
1084 echo $commit_sha commit $commit_size >>expect &&
1085 echo "info HEAD" >in &&
1086 git cat-file --batch-command <in >actual &&
1087 git cat-file --use-mailmap --batch-command <in >>actual &&
1088 test_cmp expect actual
1091 test_done