3 test_description='.mailmap configurations'
9 s/$_x05[0-9a-f][0-9a-f][0-9a-f]/OBJID/g
10 s/$_x05[0-9a-f][0-9a-f]/OBJI/g
11 s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g
15 test_expect_success setup '
16 cat >contacts <<- EOF &&
17 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
18 nick1 <bugs@company.xx>
24 git commit -m initial &&
28 git commit --author "nick1 <bugs@company.xx>" -m second
31 test_expect_success 'check-mailmap no arguments' '
32 test_must_fail git check-mailmap
35 test_expect_success 'check-mailmap arguments' '
36 cat >expect <<- EOF &&
37 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
38 nick1 <bugs@company.xx>
41 "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" \
42 "nick1 <bugs@company.xx>" >actual &&
43 test_cmp expect actual
46 test_expect_success 'check-mailmap --stdin' '
47 cat >expect <<- EOF &&
48 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
49 nick1 <bugs@company.xx>
51 git check-mailmap --stdin <contacts >actual &&
52 test_cmp expect actual
55 test_expect_success 'check-mailmap --stdin arguments' '
56 cat >expect <<-\EOF &&
57 Internal Guy <bugs@company.xy>
59 cat <contacts >>expect &&
60 git check-mailmap --stdin "Internal Guy <bugs@company.xy>" \
62 test_cmp expect actual
65 test_expect_success 'check-mailmap bogus contact' '
66 test_must_fail git check-mailmap bogus
78 test_expect_success 'No mailmap' '
79 git shortlog HEAD >actual &&
80 test_cmp expect actual
92 test_expect_success 'default .mailmap' '
93 echo "Repo Guy <$GIT_AUTHOR_EMAIL>" > .mailmap &&
94 git shortlog HEAD >actual &&
95 test_cmp expect actual
98 # Using a mailmap file in a subdirectory of the repo here, but
99 # could just as well have been a file outside of the repository
108 test_expect_success 'mailmap.file set' '
109 mkdir -p internal_mailmap &&
110 echo "Internal Guy <bugs@company.xx>" > internal_mailmap/.mailmap &&
111 git config mailmap.file internal_mailmap/.mailmap &&
112 git shortlog HEAD >actual &&
113 test_cmp expect actual
124 test_expect_success 'mailmap.file override' '
125 echo "External Guy <$GIT_AUTHOR_EMAIL>" >> internal_mailmap/.mailmap &&
126 git config mailmap.file internal_mailmap/.mailmap &&
127 git shortlog HEAD >actual &&
128 test_cmp expect actual
140 test_expect_success 'mailmap.file non-existent' '
141 rm internal_mailmap/.mailmap &&
142 rmdir internal_mailmap &&
143 git shortlog HEAD >actual &&
144 test_cmp expect actual
156 test_expect_success 'name entry after email entry' '
157 mkdir -p internal_mailmap &&
158 echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap &&
159 echo "Internal Guy <bugs@company.xx>" >>internal_mailmap/.mailmap &&
160 git shortlog HEAD >actual &&
161 test_cmp expect actual
173 test_expect_success 'name entry after email entry, case-insensitive' '
174 mkdir -p internal_mailmap &&
175 echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap &&
176 echo "Internal Guy <BUGS@Company.xx>" >>internal_mailmap/.mailmap &&
177 git shortlog HEAD >actual &&
178 test_cmp expect actual
182 $GIT_AUTHOR_NAME (1):
189 test_expect_success 'No mailmap files, but configured' '
190 rm -f .mailmap internal_mailmap/.mailmap &&
191 git shortlog HEAD >actual &&
192 test_cmp expect actual
195 test_expect_success 'setup mailmap blob tests' '
196 git checkout -b map &&
197 test_when_finished "git checkout master" &&
198 cat >just-bugs <<- EOF &&
199 Blob Guy <bugs@company.xx>
202 Blob Guy <$GIT_AUTHOR_EMAIL>
203 Blob Guy <bugs@company.xx>
205 printf "Tricky Guy <$GIT_AUTHOR_EMAIL>" >no-newline &&
206 git add just-bugs both no-newline &&
207 git commit -m "my mailmaps" &&
208 echo "Repo Guy <$GIT_AUTHOR_EMAIL>" >.mailmap &&
209 echo "Internal Guy <$GIT_AUTHOR_EMAIL>" >internal.map
212 test_expect_success 'mailmap.blob set' '
213 cat >expect <<-\EOF &&
221 git -c mailmap.blob=map:just-bugs shortlog HEAD >actual &&
222 test_cmp expect actual
225 test_expect_success 'mailmap.blob overrides .mailmap' '
226 cat >expect <<-\EOF &&
232 git -c mailmap.blob=map:both shortlog HEAD >actual &&
233 test_cmp expect actual
236 test_expect_success 'mailmap.file overrides mailmap.blob' '
237 cat >expect <<-\EOF &&
246 -c mailmap.blob=map:both \
247 -c mailmap.file=internal.map \
248 shortlog HEAD >actual &&
249 test_cmp expect actual
252 test_expect_success 'mailmap.blob can be missing' '
253 cat >expect <<-\EOF &&
261 git -c mailmap.blob=map:nonexistent shortlog HEAD >actual &&
262 test_cmp expect actual
265 test_expect_success 'mailmap.blob defaults to off in non-bare repo' '
269 test_commit one .mailmap "Fake Name <$GIT_AUTHOR_EMAIL>" &&
270 echo " 1 Fake Name" >expect &&
271 git shortlog -ns HEAD >actual &&
272 test_cmp expect actual &&
274 echo " 1 $GIT_AUTHOR_NAME" >expect &&
275 git shortlog -ns HEAD >actual &&
276 test_cmp expect actual
280 test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' '
281 git clone --bare non-bare bare &&
284 echo " 1 Fake Name" >expect &&
285 git shortlog -ns HEAD >actual &&
286 test_cmp expect actual
290 test_expect_success 'mailmap.blob can handle blobs without trailing newline' '
291 cat >expect <<-\EOF &&
299 git -c mailmap.blob=map:no-newline shortlog HEAD >actual &&
300 test_cmp expect actual
303 test_expect_success 'cleanup after mailmap.blob tests' '
307 test_expect_success 'single-character name' '
308 echo " 1 A <$GIT_AUTHOR_EMAIL>" >expect &&
309 echo " 1 nick1 <bugs@company.xx>" >>expect &&
310 echo "A <$GIT_AUTHOR_EMAIL>" >.mailmap &&
311 test_when_finished "rm .mailmap" &&
312 git shortlog -es HEAD >actual &&
313 test_cmp expect actual
316 test_expect_success 'preserve canonical email case' '
317 echo " 1 $GIT_AUTHOR_NAME <AUTHOR@example.com>" >expect &&
318 echo " 1 nick1 <bugs@company.xx>" >>expect &&
319 echo "<AUTHOR@example.com> <$GIT_AUTHOR_EMAIL>" >.mailmap &&
320 test_when_finished "rm .mailmap" &&
321 git shortlog -es HEAD >actual &&
322 test_cmp expect actual
325 # Extended mailmap configurations should give us the following output for shortlog
327 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1):
330 CTO <cto@company.xx> (1):
333 Other Author <other@author.xx> (2):
337 Santa Claus <santa.claus@northpole.xx> (2):
341 Some Dude <some@dude.xx> (1):
346 test_expect_success 'Shortlog output (complex mapping)' '
350 git commit --author "nick2 <bugs@company.xx>" -m third &&
355 git commit --author "nick2 <nick2@company.xx>" -m fourth &&
360 git commit --author "santa <me@company.xx>" -m fifth &&
365 git commit --author "claus <me@company.xx>" -m sixth &&
370 git commit --author "CTO <cto@coompany.xx>" -m seventh &&
372 mkdir -p internal_mailmap &&
373 echo "Committed <$GIT_COMMITTER_EMAIL>" > internal_mailmap/.mailmap &&
374 echo "<cto@company.xx> <cto@coompany.xx>" >> internal_mailmap/.mailmap &&
375 echo "Some Dude <some@dude.xx> nick1 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
376 echo "Other Author <other@author.xx> nick2 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
377 echo "Other Author <other@author.xx> <nick2@company.xx>" >> internal_mailmap/.mailmap &&
378 echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
379 echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
381 git shortlog -e HEAD >actual &&
382 test_cmp expect actual
386 # git log with --pretty format which uses the name and email mailmap placemarkers
388 Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx>
389 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
391 Author claus <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
392 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
394 Author santa <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 nick2 <nick2@company.xx> maps to Other Author <other@author.xx>
398 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
400 Author nick2 <bugs@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 nick1 <bugs@company.xx> maps to Some Dude <some@dude.xx>
404 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
406 Author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> maps to $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
407 Committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> maps to Committed <$GIT_COMMITTER_EMAIL>
410 test_expect_success 'Log output (complex mapping)' '
411 git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
412 test_cmp expect actual
416 Author email cto@coompany.xx has local-part cto
417 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
419 Author email me@company.xx has local-part me
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 nick2@company.xx has local-part nick2
426 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
428 Author email bugs@company.xx has local-part bugs
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 author@example.com has local-part author
435 Committer email $GIT_COMMITTER_EMAIL has local-part $TEST_COMMITTER_LOCALNAME
438 test_expect_success 'Log output (local-part email address)' '
439 git log --pretty=format:"Author email %ae has local-part %al%nCommitter email %ce has local-part %cl%n" >actual &&
440 test_cmp expect actual
444 Author: CTO <cto@company.xx>
445 Author: Santa Claus <santa.claus@northpole.xx>
446 Author: Santa Claus <santa.claus@northpole.xx>
447 Author: Other Author <other@author.xx>
448 Author: Other Author <other@author.xx>
449 Author: Some Dude <some@dude.xx>
450 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
453 test_expect_success 'Log output with --use-mailmap' '
454 git log --use-mailmap | grep Author >actual &&
455 test_cmp expect actual
459 Author: CTO <cto@company.xx>
460 Author: Santa Claus <santa.claus@northpole.xx>
461 Author: Santa Claus <santa.claus@northpole.xx>
462 Author: Other Author <other@author.xx>
463 Author: Other Author <other@author.xx>
464 Author: Some Dude <some@dude.xx>
465 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
468 test_expect_success 'Log output with log.mailmap' '
469 git -c log.mailmap=True log | grep Author >actual &&
470 test_cmp expect actual
473 test_expect_success 'log.mailmap=false disables mailmap' '
474 cat >expect <<- EOF &&
475 Author: CTO <cto@coompany.xx>
476 Author: claus <me@company.xx>
477 Author: santa <me@company.xx>
478 Author: nick2 <nick2@company.xx>
479 Author: nick2 <bugs@company.xx>
480 Author: nick1 <bugs@company.xx>
481 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
483 git -c log.mailmap=False log | grep Author > actual &&
484 test_cmp expect actual
487 test_expect_success '--no-use-mailmap disables mailmap' '
488 cat >expect <<- EOF &&
489 Author: CTO <cto@coompany.xx>
490 Author: claus <me@company.xx>
491 Author: santa <me@company.xx>
492 Author: nick2 <nick2@company.xx>
493 Author: nick2 <bugs@company.xx>
494 Author: nick1 <bugs@company.xx>
495 Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
497 git log --no-use-mailmap | grep Author > actual &&
498 test_cmp expect actual
502 Author: Santa Claus <santa.claus@northpole.xx>
503 Author: Santa Claus <santa.claus@northpole.xx>
506 test_expect_success 'Grep author with --use-mailmap' '
507 git log --use-mailmap --author Santa | grep Author >actual &&
508 test_cmp expect actual
511 Author: Santa Claus <santa.claus@northpole.xx>
512 Author: Santa Claus <santa.claus@northpole.xx>
515 test_expect_success 'Grep author with log.mailmap' '
516 git -c log.mailmap=True log --author Santa | grep Author >actual &&
517 test_cmp expect actual
520 test_expect_success 'log.mailmap is true by default these days' '
521 git log --author Santa | grep Author >actual &&
522 test_cmp expect actual
525 test_expect_success 'Only grep replaced author with --use-mailmap' '
526 git log --use-mailmap --author "<cto@coompany.xx>" >actual &&
527 test_must_be_empty actual
532 ^OBJI ($GIT_AUTHOR_NAME DATE 1) one
533 OBJID (Some Dude DATE 2) two
534 OBJID (Other Author DATE 3) three
535 OBJID (Other Author DATE 4) four
536 OBJID (Santa Claus DATE 5) five
537 OBJID (Santa Claus DATE 6) six
538 OBJID (CTO DATE 7) seven
540 test_expect_success 'Blame output (complex mapping)' '
541 git blame one >actual &&
542 fuzz_blame actual >actual.fuzz &&
543 test_cmp expect actual.fuzz
547 Some Dude <some@dude.xx>
550 test_expect_success 'commit --author honors mailmap' '
551 test_must_fail git commit --author "nick" --allow-empty -meight &&
552 git commit --author "Some Dude" --allow-empty -meight &&
553 git show --pretty=format:"%an <%ae>%n" >actual &&
554 test_cmp expect actual