3 test_description
='.mailmap configurations'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=master
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12 s/$_x05[0-9a-f][0-9a-f][0-9a-f]/OBJID/g
13 s/$_x05[0-9a-f][0-9a-f]/OBJI/g
14 s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
18 test_expect_success setup
'
19 cat >contacts <<- EOF &&
20 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
21 nick1 <bugs@company.xx>
27 git commit -m initial &&
31 git commit --author "nick1 <bugs@company.xx>" -m second
34 test_expect_success
'check-mailmap no arguments' '
35 test_must_fail git check-mailmap
38 test_expect_success
'check-mailmap arguments' '
39 cat >expect <<- EOF &&
40 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
41 nick1 <bugs@company.xx>
44 "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" \
45 "nick1 <bugs@company.xx>" >actual &&
46 test_cmp expect actual
49 test_expect_success
'check-mailmap --stdin' '
50 cat >expect <<- EOF &&
51 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
52 nick1 <bugs@company.xx>
54 git check-mailmap --stdin <contacts >actual &&
55 test_cmp expect actual
58 test_expect_success
'check-mailmap --stdin arguments' '
59 cat >expect <<-\EOF &&
60 Internal Guy <bugs@company.xy>
62 cat <contacts >>expect &&
63 git check-mailmap --stdin "Internal Guy <bugs@company.xy>" \
65 test_cmp expect actual
68 test_expect_success
'check-mailmap bogus contact' '
69 test_must_fail git check-mailmap bogus
81 test_expect_success
'No mailmap' '
82 git shortlog HEAD >actual &&
83 test_cmp expect actual
95 test_expect_success
'default .mailmap' '
96 echo "Repo Guy <$GIT_AUTHOR_EMAIL>" > .mailmap &&
97 git shortlog HEAD >actual &&
98 test_cmp expect actual
101 # Using a mailmap file in a subdirectory of the repo here, but
102 # could just as well have been a file outside of the repository
111 test_expect_success
'mailmap.file set' '
112 mkdir -p internal_mailmap &&
113 echo "Internal Guy <bugs@company.xx>" > internal_mailmap/.mailmap &&
114 git config mailmap.file internal_mailmap/.mailmap &&
115 git shortlog HEAD >actual &&
116 test_cmp expect actual
127 test_expect_success
'mailmap.file override' '
128 echo "External Guy <$GIT_AUTHOR_EMAIL>" >> internal_mailmap/.mailmap &&
129 git config mailmap.file internal_mailmap/.mailmap &&
130 git shortlog HEAD >actual &&
131 test_cmp expect actual
143 test_expect_success
'mailmap.file non-existent' '
144 rm internal_mailmap/.mailmap &&
145 rmdir internal_mailmap &&
146 git shortlog HEAD >actual &&
147 test_cmp expect actual
159 test_expect_success
'name entry after email entry' '
160 mkdir -p internal_mailmap &&
161 echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap &&
162 echo "Internal Guy <bugs@company.xx>" >>internal_mailmap/.mailmap &&
163 git shortlog HEAD >actual &&
164 test_cmp expect actual
176 test_expect_success
'name entry after email entry, case-insensitive' '
177 mkdir -p internal_mailmap &&
178 echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap &&
179 echo "Internal Guy <BUGS@Company.xx>" >>internal_mailmap/.mailmap &&
180 git shortlog HEAD >actual &&
181 test_cmp expect actual
185 $GIT_AUTHOR_NAME (1):
192 test_expect_success
'No mailmap files, but configured' '
193 rm -f .mailmap internal_mailmap/.mailmap &&
194 git shortlog HEAD >actual &&
195 test_cmp expect actual
198 test_expect_success
'setup mailmap blob tests' '
199 git checkout -b map &&
200 test_when_finished "git checkout master" &&
201 cat >just-bugs <<- EOF &&
202 Blob Guy <bugs@company.xx>
205 Blob Guy <$GIT_AUTHOR_EMAIL>
206 Blob Guy <bugs@company.xx>
208 printf "Tricky Guy <$GIT_AUTHOR_EMAIL>" >no-newline &&
209 git add just-bugs both no-newline &&
210 git commit -m "my mailmaps" &&
211 echo "Repo Guy <$GIT_AUTHOR_EMAIL>" >.mailmap &&
212 echo "Internal Guy <$GIT_AUTHOR_EMAIL>" >internal.map
215 test_expect_success
'mailmap.blob set' '
216 cat >expect <<-\EOF &&
224 git -c mailmap.blob=map:just-bugs shortlog HEAD >actual &&
225 test_cmp expect actual
228 test_expect_success
'mailmap.blob overrides .mailmap' '
229 cat >expect <<-\EOF &&
235 git -c mailmap.blob=map:both shortlog HEAD >actual &&
236 test_cmp expect actual
239 test_expect_success
'mailmap.file overrides mailmap.blob' '
240 cat >expect <<-\EOF &&
249 -c mailmap.blob=map:both \
250 -c mailmap.file=internal.map \
251 shortlog HEAD >actual &&
252 test_cmp expect actual
255 test_expect_success
'mailmap.blob can be missing' '
256 cat >expect <<-\EOF &&
264 git -c mailmap.blob=map:nonexistent shortlog HEAD >actual &&
265 test_cmp expect actual
268 test_expect_success
'mailmap.blob defaults to off in non-bare repo' '
272 test_commit one .mailmap "Fake Name <$GIT_AUTHOR_EMAIL>" &&
273 echo " 1 Fake Name" >expect &&
274 git shortlog -ns HEAD >actual &&
275 test_cmp expect actual &&
277 echo " 1 $GIT_AUTHOR_NAME" >expect &&
278 git shortlog -ns HEAD >actual &&
279 test_cmp expect actual
283 test_expect_success
'mailmap.blob defaults to HEAD:.mailmap in bare repo' '
284 git clone --bare non-bare bare &&
287 echo " 1 Fake Name" >expect &&
288 git shortlog -ns HEAD >actual &&
289 test_cmp expect actual
293 test_expect_success
'mailmap.blob can handle blobs without trailing newline' '
294 cat >expect <<-\EOF &&
302 git -c mailmap.blob=map:no-newline shortlog HEAD >actual &&
303 test_cmp expect actual
306 test_expect_success
'cleanup after mailmap.blob tests' '
310 test_expect_success
'single-character name' '
311 echo " 1 A <$GIT_AUTHOR_EMAIL>" >expect &&
312 echo " 1 nick1 <bugs@company.xx>" >>expect &&
313 echo "A <$GIT_AUTHOR_EMAIL>" >.mailmap &&
314 test_when_finished "rm .mailmap" &&
315 git shortlog -es HEAD >actual &&
316 test_cmp expect actual
319 test_expect_success
'preserve canonical email case' '
320 echo " 1 $GIT_AUTHOR_NAME <AUTHOR@example.com>" >expect &&
321 echo " 1 nick1 <bugs@company.xx>" >>expect &&
322 echo "<AUTHOR@example.com> <$GIT_AUTHOR_EMAIL>" >.mailmap &&
323 test_when_finished "rm .mailmap" &&
324 git shortlog -es HEAD >actual &&
325 test_cmp expect actual
328 # Extended mailmap configurations should give us the following output for shortlog
330 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1):
333 CTO <cto@company.xx> (1):
336 Other Author <other@author.xx> (2):
340 Santa Claus <santa.claus@northpole.xx> (2):
344 Some Dude <some@dude.xx> (1):
349 test_expect_success
'Shortlog output (complex mapping)' '
353 git commit --author "nick2 <bugs@company.xx>" -m third &&
358 git commit --author "nick2 <nick2@company.xx>" -m fourth &&
363 git commit --author "santa <me@company.xx>" -m fifth &&
368 git commit --author "claus <me@company.xx>" -m sixth &&
373 git commit --author "CTO <cto@coompany.xx>" -m seventh &&
375 mkdir -p internal_mailmap &&
376 echo "Committed <$GIT_COMMITTER_EMAIL>" > internal_mailmap/.mailmap &&
377 echo "<cto@company.xx> <cto@coompany.xx>" >> internal_mailmap/.mailmap &&
378 echo "Some Dude <some@dude.xx> nick1 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
379 echo "Other Author <other@author.xx> nick2 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
380 echo "Other Author <other@author.xx> <nick2@company.xx>" >> internal_mailmap/.mailmap &&
381 echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
382 echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
384 git shortlog -e HEAD >actual &&
385 test_cmp expect actual
389 # git log with --pretty format which uses the name and email mailmap placemarkers
391 Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx>
392 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
394 Author claus <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
395 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
397 Author santa <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
398 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
400 Author nick2 <nick2@company.xx> maps to Other Author <other@author.xx>
401 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
403 Author nick2 <bugs@company.xx> maps to Other Author <other@author.xx>
404 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
406 Author nick1 <bugs@company.xx> maps to Some Dude <some@dude.xx>
407 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
409 Author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> maps to $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
410 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
413 test_expect_success
'Log output (complex mapping)' '
414 git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
415 test_cmp expect actual
419 Author email cto@coompany.xx has local-part cto
420 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
422 Author email me@company.xx has local-part me
423 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
425 Author email me@company.xx has local-part me
426 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
428 Author email nick2@company.xx has local-part nick2
429 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
431 Author email bugs@company.xx has local-part bugs
432 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
434 Author email bugs@company.xx has local-part bugs
435 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
437 Author email author@example.com has local-part author
438 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
441 test_expect_success
'Log output (local-part email address)' '
442 git log --pretty=format:"Author email %ae has local-part %al%nCommitter email %ce has local-part %cl%n" >actual &&
443 test_cmp expect actual
447 Author: CTO <cto@company.xx>
448 Author: Santa Claus <santa.claus@northpole.xx>
449 Author: Santa Claus <santa.claus@northpole.xx>
450 Author: Other Author <other@author.xx>
451 Author: Other Author <other@author.xx>
452 Author: Some Dude <some@dude.xx>
453 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
456 test_expect_success
'Log output with --use-mailmap' '
457 git log --use-mailmap | grep Author >actual &&
458 test_cmp expect actual
462 Author: CTO <cto@company.xx>
463 Author: Santa Claus <santa.claus@northpole.xx>
464 Author: Santa Claus <santa.claus@northpole.xx>
465 Author: Other Author <other@author.xx>
466 Author: Other Author <other@author.xx>
467 Author: Some Dude <some@dude.xx>
468 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
471 test_expect_success
'Log output with log.mailmap' '
472 git -c log.mailmap=True log | grep Author >actual &&
473 test_cmp expect actual
476 test_expect_success
'log.mailmap=false disables mailmap' '
477 cat >expect <<- EOF &&
478 Author: CTO <cto@coompany.xx>
479 Author: claus <me@company.xx>
480 Author: santa <me@company.xx>
481 Author: nick2 <nick2@company.xx>
482 Author: nick2 <bugs@company.xx>
483 Author: nick1 <bugs@company.xx>
484 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
486 git -c log.mailmap=False log | grep Author > actual &&
487 test_cmp expect actual
490 test_expect_success
'--no-use-mailmap disables mailmap' '
491 cat >expect <<- EOF &&
492 Author: CTO <cto@coompany.xx>
493 Author: claus <me@company.xx>
494 Author: santa <me@company.xx>
495 Author: nick2 <nick2@company.xx>
496 Author: nick2 <bugs@company.xx>
497 Author: nick1 <bugs@company.xx>
498 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
500 git log --no-use-mailmap | grep Author > actual &&
501 test_cmp expect actual
505 Author
: Santa Claus
<santa.claus@northpole.xx
>
506 Author
: Santa Claus
<santa.claus@northpole.xx
>
509 test_expect_success
'Grep author with --use-mailmap' '
510 git log --use-mailmap --author Santa | grep Author >actual &&
511 test_cmp expect actual
514 Author
: Santa Claus
<santa.claus@northpole.xx
>
515 Author
: Santa Claus
<santa.claus@northpole.xx
>
518 test_expect_success
'Grep author with log.mailmap' '
519 git -c log.mailmap=True log --author Santa | grep Author >actual &&
520 test_cmp expect actual
523 test_expect_success
'log.mailmap is true by default these days' '
524 git log --author Santa | grep Author >actual &&
525 test_cmp expect actual
528 test_expect_success
'Only grep replaced author with --use-mailmap' '
529 git log --use-mailmap --author "<cto@coompany.xx>" >actual &&
530 test_must_be_empty actual
535 ^OBJI ($GIT_AUTHOR_NAME DATE 1) one
536 OBJID (Some Dude DATE 2) two
537 OBJID (Other Author DATE 3) three
538 OBJID (Other Author DATE 4) four
539 OBJID (Santa Claus DATE 5) five
540 OBJID (Santa Claus DATE 6) six
541 OBJID (CTO DATE 7) seven
543 test_expect_success
'Blame output (complex mapping)' '
544 git blame one >actual &&
545 fuzz_blame actual >actual.fuzz &&
546 test_cmp expect actual.fuzz
550 Some Dude
<some@dude.xx
>
553 test_expect_success
'commit --author honors mailmap' '
554 test_must_fail git commit --author "nick" --allow-empty -meight &&
555 git commit --author "Some Dude" --allow-empty -meight &&
556 git show --pretty=format:"%an <%ae>%n" >actual &&
557 test_cmp expect actual