Raw
1 #!/bin/sh
2
3 test_description='.mailmap configurations'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 test_expect_success 'setup commits and contacts file' '
11 test_commit initial one one &&
12 test_commit --author "nick1 <bugs@company.xx>" --append second one two
13 '
14
15 test_expect_success 'check-mailmap no arguments' '
16 test_must_fail git check-mailmap
17 '
18
19 test_expect_success 'check-mailmap arguments' '
20 cat >expect <<-EOF &&
21 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
22 nick1 <bugs@company.xx>
23 EOF
24 git check-mailmap \
25 "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" \
26 "nick1 <bugs@company.xx>" >actual &&
27 test_cmp expect actual
28 '
29
30 test_expect_success 'check-mailmap --stdin' '
31 cat >expect <<-EOF &&
32 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
33 nick1 <bugs@company.xx>
34 EOF
35 git check-mailmap --stdin <expect >actual &&
36 test_cmp expect actual
37 '
38
39 test_expect_success 'check-mailmap --stdin arguments: no mapping' '
40 test_when_finished "rm contacts" &&
41 cat >contacts <<-EOF &&
42 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
43 nick1 <bugs@company.xx>
44 EOF
45 cat >expect <<-\EOF &&
46 Internal Guy <bugs@company.xy>
47 EOF
48 cat contacts >>expect &&
49
50 git check-mailmap --stdin "Internal Guy <bugs@company.xy>" \
51 <contacts >actual &&
52 test_cmp expect actual
53 '
54
55 test_expect_success 'check-mailmap --stdin arguments: mapping' '
56 test_when_finished "rm .mailmap" &&
57 cat >.mailmap <<-EOF &&
58 New Name <$GIT_AUTHOR_EMAIL>
59 EOF
60 cat >stdin <<-EOF &&
61 Old Name <$GIT_AUTHOR_EMAIL>
62 EOF
63
64 cp .mailmap expect &&
65 git check-mailmap --stdin <stdin >actual &&
66 test_cmp expect actual &&
67
68 cat .mailmap >>expect &&
69 git check-mailmap --stdin "Another Old Name <$GIT_AUTHOR_EMAIL>" \
70 <stdin >actual &&
71 test_cmp expect actual
72 '
73
74 test_expect_success 'check-mailmap simple address: mapping' '
75 test_when_finished "rm .mailmap" &&
76 cat >.mailmap <<-EOF &&
77 New Name <$GIT_AUTHOR_EMAIL>
78 EOF
79 cat .mailmap >expect &&
80 git check-mailmap "$GIT_AUTHOR_EMAIL" >actual &&
81 test_cmp expect actual
82 '
83
84 test_expect_success 'check-mailmap --stdin simple address: mapping' '
85 test_when_finished "rm .mailmap" &&
86 cat >.mailmap <<-EOF &&
87 New Name <$GIT_AUTHOR_EMAIL>
88 EOF
89 cat >stdin <<-EOF &&
90 $GIT_AUTHOR_EMAIL
91 EOF
92 cat .mailmap >expect &&
93 git check-mailmap --stdin <stdin >actual &&
94 test_cmp expect actual
95 '
96
97 test_expect_success 'check-mailmap simple address: no mapping' '
98 cat >expect <<-EOF &&
99 <bugs@company.xx>
100 EOF
101 git check-mailmap "bugs@company.xx" >actual &&
102 test_cmp expect actual
103 '
104
105 test_expect_success 'check-mailmap --stdin simple address: no mapping' '
106 cat >expect <<-EOF &&
107 <bugs@company.xx>
108 EOF
109 cat >stdin <<-EOF &&
110 bugs@company.xx
111 EOF
112 git check-mailmap --stdin <stdin >actual &&
113 test_cmp expect actual
114 '
115
116 test_expect_success 'check-mailmap name and address: mapping' '
117 test_when_finished "rm .mailmap" &&
118 cat >.mailmap <<-EOF &&
119 Bug Reports <bugs-new@company.xx> Bugs <bugs@company.xx>
120 EOF
121 cat >expect <<-EOF &&
122 <bugs@company.xx>
123 EOF
124 git check-mailmap "bugs@company.xx" >actual &&
125 test_cmp expect actual
126 '
127
128 test_expect_success 'No mailmap' '
129 cat >expect <<-EOF &&
130 $GIT_AUTHOR_NAME (1):
131 initial
132
133 nick1 (1):
134 second
135
136 EOF
137 git shortlog HEAD >actual &&
138 test_cmp expect actual
139 '
140
141 test_expect_success 'setup default .mailmap' '
142 cat >default.map <<-EOF
143 Repo Guy <$GIT_AUTHOR_EMAIL>
144 EOF
145 '
146
147 test_expect_success 'test default .mailmap' '
148 test_when_finished "rm .mailmap" &&
149 cp default.map .mailmap &&
150
151 cat >expect <<-\EOF &&
152 Repo Guy (1):
153 initial
154
155 nick1 (1):
156 second
157
158 EOF
159 git shortlog HEAD >actual &&
160 test_cmp expect actual
161 '
162
163 test_expect_success 'mailmap.file set' '
164 test_when_finished "rm .mailmap" &&
165 cp default.map .mailmap &&
166
167 test_config mailmap.file internal.map &&
168 cat >internal.map <<-\EOF &&
169 Internal Guy <bugs@company.xx>
170 EOF
171
172 cat >expect <<-\EOF &&
173 Internal Guy (1):
174 second
175
176 Repo Guy (1):
177 initial
178
179 EOF
180 git shortlog HEAD >actual &&
181 test_cmp expect actual &&
182
183 # The internal_mailmap/.mailmap file is in a subdirectory, but
184 # as shown here it can also be outside the repository
185 test_when_finished "rm -rf sub-repo" &&
186 git clone . sub-repo &&
187 (
188 cd sub-repo &&
189 cp ../.mailmap . &&
190 git config mailmap.file ../internal.map &&
191 git shortlog HEAD >actual &&
192 test_cmp ../expect actual
193 )
194 '
195
196 test_expect_success 'mailmap.file override' '
197 test_config mailmap.file internal.map &&
198 cat >internal.map <<-EOF &&
199 Internal Guy <bugs@company.xx>
200 External Guy <$GIT_AUTHOR_EMAIL>
201 EOF
202
203 cat >expect <<-\EOF &&
204 External Guy (1):
205 initial
206
207 Internal Guy (1):
208 second
209
210 EOF
211 git shortlog HEAD >actual &&
212 test_cmp expect actual
213 '
214
215 test_expect_success 'mailmap.file non-existent' '
216 test_when_finished "rm .mailmap" &&
217 cp default.map .mailmap &&
218
219 cat >expect <<-\EOF &&
220 Repo Guy (1):
221 initial
222
223 nick1 (1):
224 second
225
226 EOF
227 git shortlog HEAD >actual &&
228 test_cmp expect actual
229 '
230
231 test_expect_success 'name entry after email entry' '
232 test_when_finished "rm .mailmap" &&
233 cp default.map .mailmap &&
234
235 test_config mailmap.file internal.map &&
236 cat >internal.map <<-\EOF &&
237 <bugs@company.xy> <bugs@company.xx>
238 Internal Guy <bugs@company.xx>
239 EOF
240
241 cat >expect <<-\EOF &&
242 Internal Guy (1):
243 second
244
245 Repo Guy (1):
246 initial
247
248 EOF
249
250 git shortlog HEAD >actual &&
251 test_cmp expect actual
252 '
253
254 test_expect_success 'name entry after email entry, case-insensitive' '
255 test_when_finished "rm .mailmap" &&
256 cp default.map .mailmap &&
257
258 test_config mailmap.file internal.map &&
259 cat >internal.map <<-\EOF &&
260 <bugs@company.xy> <bugs@company.xx>
261 Internal Guy <BUGS@Company.xx>
262 EOF
263
264 cat >expect <<-\EOF &&
265 Internal Guy (1):
266 second
267
268 Repo Guy (1):
269 initial
270
271 EOF
272 git shortlog HEAD >actual &&
273 test_cmp expect actual &&
274
275 cat >internal.map <<-\EOF &&
276 NiCk <BuGs@CoMpAnY.Xy> NICK1 <BUGS@COMPANY.XX>
277 EOF
278
279 cat >expect <<-\EOF &&
280 NiCk (1):
281 second
282
283 Repo Guy (1):
284 initial
285
286 EOF
287 git shortlog HEAD >actual &&
288 test_cmp expect actual
289 '
290
291 test_expect_success 'No mailmap files, but configured' '
292 cat >expect <<-EOF &&
293 $GIT_AUTHOR_NAME (1):
294 initial
295
296 nick1 (1):
297 second
298
299 EOF
300 git shortlog HEAD >actual &&
301 test_cmp expect actual
302 '
303
304 test_expect_success 'setup mailmap blob tests' '
305 git checkout -b map &&
306 test_when_finished "git checkout main" &&
307 cat >just-bugs <<-\EOF &&
308 Blob Guy <bugs@company.xx>
309 EOF
310 cat >both <<-EOF &&
311 Blob Guy <$GIT_AUTHOR_EMAIL>
312 Blob Guy <bugs@company.xx>
313 EOF
314 printf "Tricky Guy <$GIT_AUTHOR_EMAIL>" >no-newline &&
315 git add just-bugs both no-newline &&
316 git commit -m "my mailmaps" &&
317
318 cat >internal.map <<-EOF
319 Internal Guy <$GIT_AUTHOR_EMAIL>
320 EOF
321 '
322
323 test_expect_success 'mailmap.blob set' '
324 test_when_finished "rm .mailmap" &&
325 cp default.map .mailmap &&
326
327 cat >expect <<-\EOF &&
328 Blob Guy (1):
329 second
330
331 Repo Guy (1):
332 initial
333
334 EOF
335 git -c mailmap.blob=map:just-bugs shortlog HEAD >actual &&
336 test_cmp expect actual
337 '
338
339 test_expect_success 'mailmap.blob overrides .mailmap' '
340 test_when_finished "rm .mailmap" &&
341 cp default.map .mailmap &&
342
343 cat >expect <<-\EOF &&
344 Blob Guy (2):
345 initial
346 second
347
348 EOF
349 git -c mailmap.blob=map:both shortlog HEAD >actual &&
350 test_cmp expect actual
351 '
352
353 test_expect_success 'mailmap.file overrides mailmap.blob' '
354 cat >expect <<-\EOF &&
355 Blob Guy (1):
356 second
357
358 Internal Guy (1):
359 initial
360
361 EOF
362 git \
363 -c mailmap.blob=map:both \
364 -c mailmap.file=internal.map \
365 shortlog HEAD >actual &&
366 test_cmp expect actual
367 '
368
369 test_expect_success 'mailmap.file can be missing' '
370 test_when_finished "rm .mailmap" &&
371 cp default.map .mailmap &&
372
373 test_config mailmap.file nonexistent &&
374 cat >expect <<-\EOF &&
375 Repo Guy (1):
376 initial
377
378 nick1 (1):
379 second
380
381 EOF
382 git shortlog HEAD >actual 2>err &&
383 test_must_be_empty err &&
384 test_cmp expect actual
385 '
386
387 test_expect_success 'mailmap.blob can be missing' '
388 test_when_finished "rm .mailmap" &&
389 cp default.map .mailmap &&
390
391 cat >expect <<-\EOF &&
392 Repo Guy (1):
393 initial
394
395 nick1 (1):
396 second
397
398 EOF
399 git -c mailmap.blob=map:nonexistent shortlog HEAD >actual 2>err &&
400 test_must_be_empty err &&
401 test_cmp expect actual
402 '
403
404 test_expect_success 'mailmap.blob might be the wrong type' '
405 test_when_finished "rm .mailmap" &&
406 cp default.map .mailmap &&
407
408 git -c mailmap.blob=HEAD: shortlog HEAD >actual 2>err &&
409 test_grep "mailmap is not a blob" err &&
410 test_cmp expect actual
411 '
412
413 test_expect_success 'mailmap.blob defaults to off in non-bare repo' '
414 git init non-bare &&
415 (
416 cd non-bare &&
417 test_commit one .mailmap "Fake Name <$GIT_AUTHOR_EMAIL>" &&
418 cat >expect <<-\EOF &&
419 1 Fake Name
420 EOF
421 git shortlog -ns HEAD >actual &&
422 test_cmp expect actual &&
423 rm .mailmap &&
424 cat >expect <<-EOF &&
425 1 $GIT_AUTHOR_NAME
426 EOF
427 git shortlog -ns HEAD >actual &&
428 test_cmp expect actual
429 )
430 '
431
432 test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' '
433 git clone --bare non-bare bare &&
434 (
435 cd bare &&
436 cat >expect <<-\EOF &&
437 1 Fake Name
438 EOF
439 git shortlog -ns HEAD >actual &&
440 test_cmp expect actual
441 )
442 '
443
444 test_expect_success 'mailmap.blob can handle blobs without trailing newline' '
445 cat >expect <<-\EOF &&
446 Tricky Guy (1):
447 initial
448
449 nick1 (1):
450 second
451
452 EOF
453 git -c mailmap.blob=map:no-newline shortlog HEAD >actual &&
454 test_cmp expect actual
455 '
456
457 test_expect_success 'single-character name' '
458 test_when_finished "rm .mailmap" &&
459 cat >.mailmap <<-EOF &&
460 A <$GIT_AUTHOR_EMAIL>
461 EOF
462
463 cat >expect <<-EOF &&
464 1 A <$GIT_AUTHOR_EMAIL>
465 1 nick1 <bugs@company.xx>
466 EOF
467 git shortlog -es HEAD >actual &&
468 test_cmp expect actual
469 '
470
471 test_expect_success 'preserve canonical email case' '
472 test_when_finished "rm .mailmap" &&
473 cat >.mailmap <<-EOF &&
474 <AUTHOR@example.com> <$GIT_AUTHOR_EMAIL>
475 EOF
476
477 cat >expect <<-EOF &&
478 1 $GIT_AUTHOR_NAME <AUTHOR@example.com>
479 1 nick1 <bugs@company.xx>
480 EOF
481 git shortlog -es HEAD >actual &&
482 test_cmp expect actual
483 '
484
485 test_expect_success 'gitmailmap(5) example output: setup' '
486 test_create_repo doc &&
487 test_commit -C doc --author "Joe Developer <joe@example.com>" A &&
488 test_commit -C doc --author "Joe R. Developer <joe@example.com>" B &&
489 test_commit -C doc --author "Jane Doe <jane@example.com>" C &&
490 test_commit -C doc --author "Jane Doe <jane@laptop.(none)>" D &&
491 test_commit -C doc --author "Jane D. <jane@desktop.(none)>" E
492 '
493
494 test_expect_success 'gitmailmap(5) example output: example #1' '
495 test_config -C doc mailmap.file ../doc.map &&
496 cat >doc.map <<-\EOF &&
497 Joe R. Developer <joe@example.com>
498 Jane Doe <jane@example.com>
499 Jane Doe <jane@desktop.(none)>
500 EOF
501
502 cat >expect <<-\EOF &&
503 Author Joe Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
504 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
505
506 Author Joe R. Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
507 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
508
509 Author Jane Doe <jane@example.com> maps to Jane Doe <jane@example.com>
510 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
511
512 Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <jane@laptop.(none)>
513 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
514
515 Author Jane D. <jane@desktop.(none)> maps to Jane Doe <jane@desktop.(none)>
516 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
517 EOF
518 git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
519 test_cmp expect actual
520 '
521
522 test_expect_success 'gitmailmap(5) example output: example #2' '
523 test_config -C doc mailmap.file ../doc.map &&
524 cat >doc.map <<-\EOF &&
525 Joe R. Developer <joe@example.com>
526 Jane Doe <jane@example.com> <jane@laptop.(none)>
527 Jane Doe <jane@example.com> <jane@desktop.(none)>
528 EOF
529
530 cat >expect <<-\EOF &&
531 Author Joe Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
532 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
533
534 Author Joe R. Developer <joe@example.com> maps to Joe R. Developer <joe@example.com>
535 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
536
537 Author Jane Doe <jane@example.com> maps to Jane Doe <jane@example.com>
538 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
539
540 Author Jane Doe <jane@laptop.(none)> maps to Jane Doe <jane@example.com>
541 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
542
543 Author Jane D. <jane@desktop.(none)> maps to Jane Doe <jane@example.com>
544 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
545 EOF
546 git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
547 test_cmp expect actual
548 '
549
550 test_expect_success 'gitmailmap(5) example output: example #3' '
551 test_config -C doc mailmap.file ../doc.map &&
552 cat >>doc.map <<-\EOF &&
553 Joe R. Developer <joe@example.com> Joe <bugs@example.com>
554 Jane Doe <jane@example.com> Jane <bugs@example.com>
555 EOF
556
557 test_commit -C doc --author "Joe <bugs@example.com>" F &&
558 test_commit -C doc --author "Jane <bugs@example.com>" G &&
559
560 cat >>expect <<-\EOF &&
561
562 Author Joe <bugs@example.com> maps to Joe R. Developer <joe@example.com>
563 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
564
565 Author Jane <bugs@example.com> maps to Jane Doe <jane@example.com>
566 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
567 EOF
568 git -C doc log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
569 test_cmp expect actual
570 '
571
572
573 test_expect_success 'Shortlog output (complex mapping)' '
574 test_config mailmap.file complex.map &&
575 cat >complex.map <<-EOF &&
576 Committed <$GIT_COMMITTER_EMAIL>
577 <cto@company.xx> <cto@coompany.xx>
578 Some Dude <some@dude.xx> nick1 <bugs@company.xx>
579 Other Author <other@author.xx> nick2 <bugs@company.xx>
580 Other Author <other@author.xx> <nick2@company.xx>
581 Santa Claus <santa.claus@northpole.xx> <me@company.xx>
582 EOF
583
584 test_commit --author "nick2 <bugs@company.xx>" --append third one three &&
585 test_commit --author "nick2 <nick2@company.xx>" --append fourth one four &&
586 test_commit --author "santa <me@company.xx>" --append fifth one five &&
587 test_commit --author "claus <me@company.xx>" --append sixth one six &&
588 test_commit --author "CTO <cto@coompany.xx>" --append seventh one seven &&
589
590 cat >expect <<-EOF &&
591 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1):
592 initial
593
594 CTO <cto@company.xx> (1):
595 seventh
596
597 Other Author <other@author.xx> (2):
598 third
599 fourth
600
601 Santa Claus <santa.claus@northpole.xx> (2):
602 fifth
603 sixth
604
605 Some Dude <some@dude.xx> (1):
606 second
607
608 EOF
609
610 git shortlog -e HEAD >actual &&
611 test_cmp expect actual
612
613 '
614
615 test_expect_success 'Log output (complex mapping)' '
616 test_config mailmap.file complex.map &&
617
618 cat >expect <<-EOF &&
619 Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx>
620 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
621
622 Author claus <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
623 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
624
625 Author santa <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
626 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
627
628 Author nick2 <nick2@company.xx> maps to Other Author <other@author.xx>
629 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
630
631 Author nick2 <bugs@company.xx> maps to Other Author <other@author.xx>
632 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
633
634 Author nick1 <bugs@company.xx> maps to Some Dude <some@dude.xx>
635 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
636
637 Author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> maps to $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
638 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
639 EOF
640
641 git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
642 test_cmp expect actual
643 '
644
645 test_expect_success 'Log output (local-part email address)' '
646 cat >expect <<-EOF &&
647 Author email cto@coompany.xx has local-part cto
648 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
649
650 Author email me@company.xx has local-part me
651 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
652
653 Author email me@company.xx has local-part me
654 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
655
656 Author email nick2@company.xx has local-part nick2
657 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
658
659 Author email bugs@company.xx has local-part bugs
660 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
661
662 Author email bugs@company.xx has local-part bugs
663 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
664
665 Author email author@example.com has local-part author
666 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
667 EOF
668
669 git log --pretty=format:"Author email %ae has local-part %al%nCommitter email %ce has local-part %cl%n" >actual &&
670 test_cmp expect actual
671 '
672
673 test_expect_success 'Log output with --use-mailmap' '
674 test_config mailmap.file complex.map &&
675
676 cat >expect <<-EOF &&
677 Author: CTO <cto@company.xx>
678 Author: Santa Claus <santa.claus@northpole.xx>
679 Author: Santa Claus <santa.claus@northpole.xx>
680 Author: Other Author <other@author.xx>
681 Author: Other Author <other@author.xx>
682 Author: Some Dude <some@dude.xx>
683 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
684 EOF
685
686 git log --use-mailmap >log &&
687 grep Author log >actual &&
688 test_cmp expect actual
689 '
690
691 test_expect_success 'Log output with log.mailmap' '
692 test_config mailmap.file complex.map &&
693
694 cat >expect <<-EOF &&
695 Author: CTO <cto@company.xx>
696 Author: Santa Claus <santa.claus@northpole.xx>
697 Author: Santa Claus <santa.claus@northpole.xx>
698 Author: Other Author <other@author.xx>
699 Author: Other Author <other@author.xx>
700 Author: Some Dude <some@dude.xx>
701 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
702 EOF
703
704 git -c log.mailmap=True log >log &&
705 grep Author log >actual &&
706 test_cmp expect actual
707 '
708
709 test_expect_success 'log.mailmap=false disables mailmap' '
710 cat >expect <<-EOF &&
711 Author: CTO <cto@coompany.xx>
712 Author: claus <me@company.xx>
713 Author: santa <me@company.xx>
714 Author: nick2 <nick2@company.xx>
715 Author: nick2 <bugs@company.xx>
716 Author: nick1 <bugs@company.xx>
717 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
718 EOF
719 git -c log.mailmap=false log >log &&
720 grep Author log >actual &&
721 test_cmp expect actual
722 '
723
724 test_expect_success '--no-use-mailmap disables mailmap' '
725 cat >expect <<-EOF &&
726 Author: CTO <cto@coompany.xx>
727 Author: claus <me@company.xx>
728 Author: santa <me@company.xx>
729 Author: nick2 <nick2@company.xx>
730 Author: nick2 <bugs@company.xx>
731 Author: nick1 <bugs@company.xx>
732 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
733 EOF
734 git log --no-use-mailmap >log &&
735 grep Author log >actual &&
736 test_cmp expect actual
737 '
738
739 test_expect_success 'Grep author with --use-mailmap' '
740 test_config mailmap.file complex.map &&
741
742 cat >expect <<-\EOF &&
743 Author: Santa Claus <santa.claus@northpole.xx>
744 Author: Santa Claus <santa.claus@northpole.xx>
745 EOF
746 git log --use-mailmap --author Santa >log &&
747 grep Author log >actual &&
748 test_cmp expect actual
749 '
750
751 test_expect_success 'Grep author with log.mailmap' '
752 test_config mailmap.file complex.map &&
753
754 cat >expect <<-\EOF &&
755 Author: Santa Claus <santa.claus@northpole.xx>
756 Author: Santa Claus <santa.claus@northpole.xx>
757 EOF
758
759 git -c log.mailmap=True log --author Santa >log &&
760 grep Author log >actual &&
761 test_cmp expect actual
762 '
763
764 test_expect_success 'log.mailmap is true by default these days' '
765 test_config mailmap.file complex.map &&
766 git log --author Santa >log &&
767 grep Author log >actual &&
768 test_cmp expect actual
769 '
770
771 test_expect_success 'Only grep replaced author with --use-mailmap' '
772 test_config mailmap.file complex.map &&
773 git log --use-mailmap --author "<cto@coompany.xx>" >actual &&
774 test_must_be_empty actual
775 '
776
777 test_expect_success 'Blame --porcelain output (complex mapping)' '
778 test_config mailmap.file complex.map &&
779
780 cat >expect <<-EOF &&
781 1 1 1
782 A U Thor
783 2 2 1
784 Some Dude
785 3 3 1
786 Other Author
787 4 4 1
788 Other Author
789 5 5 1
790 Santa Claus
791 6 6 1
792 Santa Claus
793 7 7 1
794 CTO
795 EOF
796
797 git blame --porcelain one >actual.blame &&
798
799 NUM="[0-9][0-9]*" &&
800 sed -n <actual.blame >actual.fuzz \
801 -e "s/^author //p" \
802 -e "s/^$OID_REGEX \\($NUM $NUM $NUM\\)$/\\1/p" &&
803 test_cmp expect actual.fuzz
804 '
805
806 test_expect_success 'Blame output (complex mapping)' '
807 git -c mailmap.file=complex.map blame one >a &&
808 git blame one >b &&
809 test_file_not_empty a &&
810 ! cmp a b
811 '
812
813 test_expect_success 'commit --author honors mailmap' '
814 test_config mailmap.file complex.map &&
815
816 cat >expect <<-\EOF &&
817 Some Dude <some@dude.xx>
818 EOF
819
820 test_must_fail git commit --author "nick" --allow-empty -meight &&
821 git commit --author "Some Dude" --allow-empty -meight &&
822 git show --pretty=format:"%an <%ae>%n" >actual &&
823 test_cmp expect actual
824 '
825
826 test_expect_success 'comment syntax: setup' '
827 test_create_repo comm &&
828 test_commit -C comm --author "A <a@example.com>" A &&
829 test_commit -C comm --author "B <b@example.com>" B &&
830 test_commit -C comm --author "C <#@example.com>" C &&
831 test_commit -C comm --author "D <d@e#ample.com>" D &&
832
833 test_config -C comm mailmap.file ../doc.map &&
834 cat >>doc.map <<-\EOF &&
835 # Ah <a@example.com>
836
837 ; Bee <b@example.com>
838 Cee <cee@example.com> <#@example.com>
839 Dee <dee@example.com> <d@e#ample.com>
840 EOF
841
842 cat >expect <<-\EOF &&
843 Author A <a@example.com> maps to A <a@example.com>
844 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
845
846 Author B <b@example.com> maps to ; Bee <b@example.com>
847 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
848
849 Author C <#@example.com> maps to Cee <cee@example.com>
850 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
851
852 Author D <d@e#ample.com> maps to Dee <dee@example.com>
853 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
854 EOF
855 git -C comm log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
856 test_cmp expect actual
857 '
858
859 test_expect_success 'whitespace syntax: setup' '
860 test_create_repo space &&
861 test_commit -C space --author "A <a@example.com>" A &&
862 test_commit -C space --author "B <b@example.com>" B &&
863 test_commit -C space --author " C <c@example.com>" C &&
864 test_commit -C space --author " D <d@example.com>" D &&
865 test_commit -C space --author "E E <e@example.com>" E &&
866 test_commit -C space --author "F F <f@example.com>" F &&
867 test_commit -C space --author "G G <g@example.com>" G &&
868 test_commit -C space --author "H H <h@example.com>" H &&
869
870 test_config -C space mailmap.file ../space.map &&
871 cat >>space.map <<-\EOF &&
872 Ah <ah@example.com> < a@example.com >
873 Bee <bee@example.com > < b@example.com >
874 Cee <cee@example.com> C <c@example.com>
875 dee <dee@example.com> D <d@example.com>
876 eee <eee@example.com> E E <e@example.com>
877 eff <eff@example.com> F F <f@example.com>
878 gee <gee@example.com> G G <g@example.com>
879 aitch <aitch@example.com> H H <h@example.com>
880 EOF
881
882 cat >expect <<-\EOF &&
883 Author A <a@example.com> maps to A <a@example.com>
884 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
885
886 Author B <b@example.com> maps to B <b@example.com>
887 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
888
889 Author C <c@example.com> maps to Cee <cee@example.com>
890 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
891
892 Author D <d@example.com> maps to dee <dee@example.com>
893 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
894
895 Author E E <e@example.com> maps to eee <eee@example.com>
896 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
897
898 Author F F <f@example.com> maps to eff <eff@example.com>
899 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
900
901 Author G G <g@example.com> maps to gee <gee@example.com>
902 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
903
904 Author H H <h@example.com> maps to H H <h@example.com>
905 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
906 EOF
907 git -C space log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
908 test_cmp expect actual
909 '
910
911 test_expect_success 'empty syntax: setup' '
912 test_create_repo empty &&
913 test_commit -C empty --author "A <>" A &&
914 test_commit -C empty --author "B <b@example.com>" B &&
915 test_commit -C empty --author "C <c@example.com>" C &&
916
917 test_config -C empty mailmap.file ../empty.map &&
918 cat >>empty.map <<-\EOF &&
919 Ah <ah@example.com> <>
920 Bee <bee@example.com> <>
921 Cee <> <c@example.com>
922 EOF
923
924 cat >expect <<-\EOF &&
925 Author A <> maps to Bee <bee@example.com>
926 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
927
928 Author B <b@example.com> maps to B <b@example.com>
929 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
930
931 Author C <c@example.com> maps to C <c@example.com>
932 Committer C O Mitter <committer@example.com> maps to C O Mitter <committer@example.com>
933 EOF
934 git -C empty log --reverse --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
935 test_cmp expect actual
936 '
937
938 test_expect_success 'set up mailmap location tests' '
939 git init --bare loc-bare &&
940 git --git-dir=loc-bare --work-tree=. commit \
941 --allow-empty -m foo --author="Orig <orig@example.com>" &&
942 echo "New <new@example.com> <orig@example.com>" >loc-bare/.mailmap
943 '
944
945 test_expect_success 'bare repo with --work-tree finds mailmap at top-level' '
946 git -C loc-bare --work-tree=. log -1 --format=%aE >actual &&
947 echo new@example.com >expect &&
948 test_cmp expect actual
949 '
950
951 test_expect_success 'bare repo does not look in current directory' '
952 git -C loc-bare log -1 --format=%aE >actual &&
953 echo orig@example.com >expect &&
954 test_cmp expect actual
955 '
956
957 test_expect_success 'non-git shortlog respects mailmap in current dir' '
958 git --git-dir=loc-bare log -1 >input &&
959 nongit cp "$TRASH_DIRECTORY/loc-bare/.mailmap" . &&
960 nongit git shortlog -s <input >actual &&
961 echo " 1 New" >expect &&
962 test_cmp expect actual
963 '
964
965 test_expect_success 'shortlog on stdin respects mailmap from repo' '
966 cp loc-bare/.mailmap . &&
967 git shortlog -s <input >actual &&
968 echo " 1 New" >expect &&
969 test_cmp expect actual
970 '
971
972 test_expect_success 'find top-level mailmap from subdir' '
973 git clone loc-bare loc-wt &&
974 cp loc-bare/.mailmap loc-wt &&
975 mkdir loc-wt/subdir &&
976 git -C loc-wt/subdir log -1 --format=%aE >actual &&
977 echo new@example.com >expect &&
978 test_cmp expect actual
979 '
980
981 test_expect_success SYMLINKS 'set up symlink tests' '
982 git commit --allow-empty -m foo --author="Orig <orig@example.com>" &&
983 echo "New <new@example.com> <orig@example.com>" >map &&
984 rm -f .mailmap
985 '
986
987 test_expect_success SYMLINKS 'symlinks respected in mailmap.file' '
988 test_when_finished "rm symlink" &&
989 ln -s map symlink &&
990 git -c mailmap.file="$(pwd)/symlink" log -1 --format=%aE >actual &&
991 echo "new@example.com" >expect &&
992 test_cmp expect actual
993 '
994
995 test_expect_success SYMLINKS 'symlinks respected in non-repo shortlog' '
996 git log -1 >input &&
997 test_when_finished "nongit rm .mailmap" &&
998 nongit ln -sf "$TRASH_DIRECTORY/map" .mailmap &&
999 nongit git shortlog -s <input >actual &&
1000 echo " 1 New" >expect &&
1001 test_cmp expect actual
1002 '
1003
1004 test_expect_success SYMLINKS 'symlinks not respected in-tree' '
1005 test_when_finished "rm .mailmap" &&
1006 ln -s map .mailmap &&
1007 git log -1 --format=%aE >actual &&
1008 echo "orig@example.com" >expect &&
1009 test_cmp expect actual
1010 '
1011
1012 test_expect_success 'prepare for cat-file --mailmap' '
1013 rm -f .mailmap &&
1014 git commit --allow-empty -m foo --author="Orig <orig@example.com>"
1015 '
1016
1017 test_expect_success '--no-use-mailmap disables mailmap in cat-file' '
1018 test_when_finished "rm .mailmap" &&
1019 cat >.mailmap <<-EOF &&
1020 A U Thor <author@example.com> Orig <orig@example.com>
1021 EOF
1022 cat >expect <<-EOF &&
1023 author Orig <orig@example.com>
1024 EOF
1025 git cat-file --no-use-mailmap commit HEAD >log &&
1026 sed -n "/^author /s/\([^>]*>\).*/\1/p" log >actual &&
1027 test_cmp expect actual
1028 '
1029
1030 test_expect_success '--use-mailmap enables mailmap in cat-file' '
1031 test_when_finished "rm .mailmap" &&
1032 cat >.mailmap <<-EOF &&
1033 A U Thor <author@example.com> Orig <orig@example.com>
1034 EOF
1035 cat >expect <<-EOF &&
1036 author A U Thor <author@example.com>
1037 EOF
1038 git cat-file --use-mailmap commit HEAD >log &&
1039 sed -n "/^author /s/\([^>]*>\).*/\1/p" log >actual &&
1040 test_cmp expect actual
1041 '
1042
1043 test_expect_success '--no-mailmap disables mailmap in cat-file for annotated tag objects' '
1044 test_when_finished "rm .mailmap" &&
1045 cat >.mailmap <<-EOF &&
1046 Orig <orig@example.com> C O Mitter <committer@example.com>
1047 EOF
1048 cat >expect <<-EOF &&
1049 tagger C O Mitter <committer@example.com>
1050 EOF
1051 git tag -a -m "annotated tag" v1 &&
1052 git cat-file --no-mailmap -p v1 >log &&
1053 sed -n "/^tagger /s/\([^>]*>\).*/\1/p" log >actual &&
1054 test_cmp expect actual
1055 '
1056
1057 test_expect_success '--mailmap enables mailmap in cat-file for annotated tag objects' '
1058 test_when_finished "rm .mailmap" &&
1059 cat >.mailmap <<-EOF &&
1060 Orig <orig@example.com> C O Mitter <committer@example.com>
1061 EOF
1062 cat >expect <<-EOF &&
1063 tagger Orig <orig@example.com>
1064 EOF
1065 git tag -a -m "annotated tag" v2 &&
1066 git cat-file --mailmap -p v2 >log &&
1067 sed -n "/^tagger /s/\([^>]*>\).*/\1/p" log >actual &&
1068 test_cmp expect actual
1069 '
1070
1071 test_expect_success 'git cat-file -s returns correct size with --use-mailmap' '
1072 test_when_finished "rm .mailmap" &&
1073 cat >.mailmap <<-\EOF &&
1074 C O Mitter <committer@example.com> Orig <orig@example.com>
1075 EOF
1076 git cat-file commit HEAD >commit.out &&
1077 echo $(wc -c <commit.out) >expect &&
1078 git cat-file --use-mailmap commit HEAD >commit.out &&
1079 echo $(wc -c <commit.out) >>expect &&
1080 git cat-file -s HEAD >actual &&
1081 git cat-file --use-mailmap -s HEAD >>actual &&
1082 test_cmp expect actual
1083 '
1084
1085 test_expect_success 'git cat-file -s returns correct size with --use-mailmap for tag objects' '
1086 test_when_finished "rm .mailmap" &&
1087 cat >.mailmap <<-\EOF &&
1088 Orig <orig@example.com> C O Mitter <committer@example.com>
1089 EOF
1090 git tag -a -m "annotated tag" v3 &&
1091 git cat-file tag v3 >tag.out &&
1092 echo $(wc -c <tag.out) >expect &&
1093 git cat-file --use-mailmap tag v3 >tag.out &&
1094 echo $(wc -c <tag.out) >>expect &&
1095 git cat-file -s v3 >actual &&
1096 git cat-file --use-mailmap -s v3 >>actual &&
1097 test_cmp expect actual
1098 '
1099
1100 test_expect_success 'git cat-file --batch-check returns correct size with --use-mailmap' '
1101 test_when_finished "rm .mailmap" &&
1102 cat >.mailmap <<-\EOF &&
1103 C O Mitter <committer@example.com> Orig <orig@example.com>
1104 EOF
1105 git cat-file commit HEAD >commit.out &&
1106 commit_size=$(wc -c <commit.out) &&
1107 commit_sha=$(git rev-parse HEAD) &&
1108 echo $commit_sha commit $commit_size >expect &&
1109 git cat-file --use-mailmap commit HEAD >commit.out &&
1110 commit_size=$(wc -c <commit.out) &&
1111 echo $commit_sha commit $commit_size >>expect &&
1112 echo "HEAD" >in &&
1113 git cat-file --batch-check <in >actual &&
1114 git cat-file --use-mailmap --batch-check <in >>actual &&
1115 test_cmp expect actual
1116 '
1117
1118 test_expect_success 'git cat-file --batch-command returns correct size with --use-mailmap' '
1119 test_when_finished "rm .mailmap" &&
1120 cat >.mailmap <<-\EOF &&
1121 C O Mitter <committer@example.com> Orig <orig@example.com>
1122 EOF
1123 git cat-file commit HEAD >commit.out &&
1124 commit_size=$(wc -c <commit.out) &&
1125 commit_sha=$(git rev-parse HEAD) &&
1126 echo $commit_sha commit $commit_size >expect &&
1127 git cat-file --use-mailmap commit HEAD >commit.out &&
1128 commit_size=$(wc -c <commit.out) &&
1129 echo $commit_sha commit $commit_size >>expect &&
1130 echo "info HEAD" >in &&
1131 git cat-file --batch-command <in >actual &&
1132 git cat-file --use-mailmap --batch-command <in >>actual &&
1133 test_cmp expect actual
1134 '
1135
1136 test_expect_success 'git cat-file --batch-command mailmap yes enables mailmap mid-stream' '
1137 test_when_finished "rm .mailmap" &&
1138 cat >.mailmap <<-\EOF &&
1139 C O Mitter <committer@example.com> Orig <orig@example.com>
1140 EOF
1141 commit_sha=$(git rev-parse HEAD) &&
1142 git cat-file commit HEAD >commit_no_mailmap.out &&
1143 git cat-file --use-mailmap commit HEAD >commit_mailmap.out &&
1144 size_no_mailmap=$(wc -c <commit_no_mailmap.out) &&
1145 size_mailmap=$(wc -c <commit_mailmap.out) &&
1146 printf "info HEAD\nmailmap yes\ninfo HEAD\n" | git cat-file --batch-command >actual &&
1147 echo $commit_sha commit $size_no_mailmap >expect &&
1148 echo $commit_sha commit $size_mailmap >>expect &&
1149 test_cmp expect actual
1150 '
1151
1152 test_expect_success 'git cat-file --batch-command mailmap no disables mailmap mid-stream' '
1153 test_when_finished "rm .mailmap" &&
1154 cat >.mailmap <<-\EOF &&
1155 C O Mitter <committer@example.com> Orig <orig@example.com>
1156 EOF
1157 commit_sha=$(git rev-parse HEAD) &&
1158 git cat-file commit HEAD >commit_no_mailmap.out &&
1159 git cat-file --use-mailmap commit HEAD >commit_mailmap.out &&
1160 size_no_mailmap=$(wc -c <commit_no_mailmap.out) &&
1161 size_mailmap=$(wc -c <commit_mailmap.out) &&
1162 printf "mailmap yes\ninfo HEAD\nmailmap no\ninfo HEAD\n" | git cat-file --batch-command >actual &&
1163 echo $commit_sha commit $size_mailmap >expect &&
1164 echo $commit_sha commit $size_no_mailmap >>expect &&
1165 test_cmp expect actual
1166 '
1167
1168 test_expect_success 'git cat-file --batch-command mailmap works in --buffer mode' '
1169 test_when_finished "rm .mailmap" &&
1170 cat >.mailmap <<-\EOF &&
1171 C O Mitter <committer@example.com> Orig <orig@example.com>
1172 EOF
1173 commit_sha=$(git rev-parse HEAD) &&
1174 git cat-file commit HEAD >commit_no_mailmap.out &&
1175 git cat-file --use-mailmap commit HEAD >commit_mailmap.out &&
1176 size_no_mailmap=$(wc -c <commit_no_mailmap.out) &&
1177 size_mailmap=$(wc -c <commit_mailmap.out) &&
1178 printf "mailmap yes\ninfo HEAD\nmailmap no\ninfo HEAD\nflush\n" | git cat-file --batch-command --buffer >actual &&
1179 echo $commit_sha commit $size_mailmap >expect &&
1180 echo $commit_sha commit $size_no_mailmap >>expect &&
1181 test_cmp expect actual
1182 '
1183
1184 test_expect_success 'git cat-file --batch-command mailmap no overrides startup --mailmap' '
1185 test_when_finished "rm .mailmap" &&
1186 cat >.mailmap <<-\EOF &&
1187 C O Mitter <committer@example.com> Orig <orig@example.com>
1188 EOF
1189 commit_sha=$(git rev-parse HEAD) &&
1190 git cat-file --use-mailmap commit HEAD >commit_mailmap.out &&
1191 size_mailmap=$(wc -c <commit_mailmap.out) &&
1192 git cat-file commit HEAD >commit_no_mailmap.out &&
1193 size_no_mailmap=$(wc -c <commit_no_mailmap.out) &&
1194 printf "info HEAD\nmailmap no\ninfo HEAD\n" | \
1195 git cat-file --mailmap --batch-command >actual &&
1196 echo $commit_sha commit $size_mailmap >expect &&
1197 echo $commit_sha commit $size_no_mailmap >>expect &&
1198 test_cmp expect actual
1199 '
1200
1201 test_expect_success 'git cat-file --batch-command mailmap yes overrides startup --no-mailmap' '
1202 test_when_finished "rm .mailmap" &&
1203 cat >.mailmap <<-\EOF &&
1204 C O Mitter <committer@example.com> Orig <orig@example.com>
1205 EOF
1206 commit_sha=$(git rev-parse HEAD) &&
1207 git cat-file commit HEAD >commit_no_mailmap.out &&
1208 size_no_mailmap=$(wc -c <commit_no_mailmap.out) &&
1209 git cat-file --use-mailmap commit HEAD >commit_mailmap.out &&
1210 size_mailmap=$(wc -c <commit_mailmap.out) &&
1211 printf "info HEAD\nmailmap yes\ninfo HEAD\n" | \
1212 git cat-file --no-mailmap --batch-command >actual &&
1213 echo $commit_sha commit $size_no_mailmap >expect &&
1214 echo $commit_sha commit $size_mailmap >>expect &&
1215 test_cmp expect actual
1216 '
1217
1218 test_expect_success 'git cat-file --batch-command mailmap accepts true/false' '
1219 test_when_finished "rm .mailmap" &&
1220 cat >.mailmap <<-\EOF &&
1221 C O Mitter <committer@example.com> Orig <orig@example.com>
1222 EOF
1223 commit_sha=$(git rev-parse HEAD) &&
1224 git cat-file commit HEAD >commit_no_mailmap.out &&
1225 size_no_mailmap=$(wc -c <commit_no_mailmap.out) &&
1226 git cat-file --use-mailmap commit HEAD >commit_mailmap.out &&
1227 size_mailmap=$(wc -c <commit_mailmap.out) &&
1228 printf "mailmap true\ninfo HEAD\nmailmap false\ninfo HEAD\n" | \
1229 git cat-file --batch-command >actual &&
1230 echo $commit_sha commit $size_mailmap >expect &&
1231 echo $commit_sha commit $size_no_mailmap >>expect &&
1232 test_cmp expect actual
1233 '
1234
1235 test_expect_success 'git cat-file --batch-command mailmap rejects invalid boolean' '
1236 echo "mailmap maybe" >in &&
1237 test_must_fail git cat-file --batch-command <in 2>err &&
1238 test_grep "mailmap: invalid boolean .*maybe" err
1239 '
1240
1241 test_expect_success 'git cat-file --mailmap works with different author and committer' '
1242 test_when_finished "rm .mailmap" &&
1243 cat >.mailmap <<-\EOF &&
1244 Mailmapped User <mailmapped-user@gitlab.com> C O Mitter <committer@example.com>
1245 EOF
1246 git commit --allow-empty -m "different author/committer" \
1247 --author="Different Author <different@example.com>" &&
1248 cat >expect <<-\EOF &&
1249 author Different Author <different@example.com>
1250 committer Mailmapped User <mailmapped-user@gitlab.com>
1251 EOF
1252 git cat-file --mailmap commit HEAD >log &&
1253 sed -n -e "/^author /s/>.*/>/p" -e "/^committer /s/>.*/>/p" log >actual &&
1254 test_cmp expect actual
1255 '
1256
1257 test_expect_success 'git cat-file --mailmap maps both author and committer when both need mapping' '
1258 test_when_finished "rm .mailmap" &&
1259 cat >.mailmap <<-\EOF &&
1260 Mapped Author <mapped-author@example.com> <different@example.com>
1261 Mapped Committer <mapped-committer@example.com> C O Mitter <committer@example.com>
1262 EOF
1263 git commit --allow-empty -m "both author and committer mapped" \
1264 --author="Different Author <different@example.com>" &&
1265 cat >expect <<-\EOF &&
1266 author Mapped Author <mapped-author@example.com>
1267 committer Mapped Committer <mapped-committer@example.com>
1268 EOF
1269 git cat-file --mailmap commit HEAD >log &&
1270 sed -n -e "/^author /s/>.*/>/p" -e "/^committer /s/>.*/>/p" log >actual &&
1271 test_cmp expect actual
1272 '
1273
1274 test_done