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 A U Thor <author@example.com>
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 A U Thor <author@example.com>
38 nick1 <bugs@company.xx>
41 "A U Thor <author@example.com>" \
42 "nick1 <bugs@company.xx>" >actual &&
43 test_cmp expect actual
46 test_expect_success 'check-mailmap --stdin' '
47 cat >expect <<-\EOF &&
48 A U Thor <author@example.com>
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 <author@example.com>" > .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 <author@example.com>" >> 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
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 <author@example.com>
203 Blob Guy <bugs@company.xx>
205 git add just-bugs both &&
206 git commit -m "my mailmaps" &&
207 echo "Repo Guy <author@example.com>" >.mailmap &&
208 echo "Internal Guy <author@example.com>" >internal.map
211 test_expect_success 'mailmap.blob set' '
212 cat >expect <<-\EOF &&
220 git -c mailmap.blob=map:just-bugs shortlog HEAD >actual &&
221 test_cmp expect actual
224 test_expect_success 'mailmap.blob overrides .mailmap' '
225 cat >expect <<-\EOF &&
231 git -c mailmap.blob=map:both shortlog HEAD >actual &&
232 test_cmp expect actual
235 test_expect_success 'mailmap.file overrides mailmap.blob' '
236 cat >expect <<-\EOF &&
245 -c mailmap.blob=map:both \
246 -c mailmap.file=internal.map \
247 shortlog HEAD >actual &&
248 test_cmp expect actual
251 test_expect_success 'mailmap.blob can be missing' '
252 cat >expect <<-\EOF &&
260 git -c mailmap.blob=map:nonexistent shortlog HEAD >actual &&
261 test_cmp expect actual
264 test_expect_success 'mailmap.blob defaults to off in non-bare repo' '
268 test_commit one .mailmap "Fake Name <author@example.com>" &&
269 echo " 1 Fake Name" >expect &&
270 git shortlog -ns HEAD >actual &&
271 test_cmp expect actual &&
273 echo " 1 A U Thor" >expect &&
274 git shortlog -ns HEAD >actual &&
275 test_cmp expect actual
279 test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' '
280 git clone --bare non-bare bare &&
283 echo " 1 Fake Name" >expect &&
284 git shortlog -ns HEAD >actual &&
285 test_cmp expect actual
289 test_expect_success 'cleanup after mailmap.blob tests' '
293 test_expect_success 'single-character name' '
294 echo " 1 A <author@example.com>" >expect &&
295 echo " 1 nick1 <bugs@company.xx>" >>expect &&
296 echo "A <author@example.com>" >.mailmap &&
297 test_when_finished "rm .mailmap" &&
298 git shortlog -es HEAD >actual &&
299 test_cmp expect actual
302 test_expect_success 'preserve canonical email case' '
303 echo " 1 A U Thor <AUTHOR@example.com>" >expect &&
304 echo " 1 nick1 <bugs@company.xx>" >>expect &&
305 echo "<AUTHOR@example.com> <author@example.com>" >.mailmap &&
306 test_when_finished "rm .mailmap" &&
307 git shortlog -es HEAD >actual &&
308 test_cmp expect actual
311 # Extended mailmap configurations should give us the following output for shortlog
313 A U Thor <author@example.com> (1):
316 CTO <cto@company.xx> (1):
319 Other Author <other@author.xx> (2):
323 Santa Claus <santa.claus@northpole.xx> (2):
327 Some Dude <some@dude.xx> (1):
332 test_expect_success 'Shortlog output (complex mapping)' '
336 git commit --author "nick2 <bugs@company.xx>" -m third &&
341 git commit --author "nick2 <nick2@company.xx>" -m fourth &&
346 git commit --author "santa <me@company.xx>" -m fifth &&
351 git commit --author "claus <me@company.xx>" -m sixth &&
356 git commit --author "CTO <cto@coompany.xx>" -m seventh &&
358 mkdir -p internal_mailmap &&
359 echo "Committed <committer@example.com>" > internal_mailmap/.mailmap &&
360 echo "<cto@company.xx> <cto@coompany.xx>" >> internal_mailmap/.mailmap &&
361 echo "Some Dude <some@dude.xx> nick1 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
362 echo "Other Author <other@author.xx> nick2 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
363 echo "Other Author <other@author.xx> <nick2@company.xx>" >> internal_mailmap/.mailmap &&
364 echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
365 echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
367 git shortlog -e HEAD >actual &&
368 test_cmp expect actual
372 # git log with --pretty format which uses the name and email mailmap placemarkers
374 Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx>
375 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
377 Author claus <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
378 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
380 Author santa <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
381 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
383 Author nick2 <nick2@company.xx> maps to Other Author <other@author.xx>
384 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
386 Author nick2 <bugs@company.xx> maps to Other Author <other@author.xx>
387 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
389 Author nick1 <bugs@company.xx> maps to Some Dude <some@dude.xx>
390 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
392 Author A U Thor <author@example.com> maps to A U Thor <author@example.com>
393 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
396 test_expect_success 'Log output (complex mapping)' '
397 git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
398 test_cmp expect actual
402 Author: CTO <cto@company.xx>
403 Author: Santa Claus <santa.claus@northpole.xx>
404 Author: Santa Claus <santa.claus@northpole.xx>
405 Author: Other Author <other@author.xx>
406 Author: Other Author <other@author.xx>
407 Author: Some Dude <some@dude.xx>
408 Author: A U Thor <author@example.com>
411 test_expect_success 'Log output with --use-mailmap' '
412 git log --use-mailmap | grep Author >actual &&
413 test_cmp expect actual
417 Author: CTO <cto@company.xx>
418 Author: Santa Claus <santa.claus@northpole.xx>
419 Author: Santa Claus <santa.claus@northpole.xx>
420 Author: Other Author <other@author.xx>
421 Author: Other Author <other@author.xx>
422 Author: Some Dude <some@dude.xx>
423 Author: A U Thor <author@example.com>
426 test_expect_success 'Log output with log.mailmap' '
427 git -c log.mailmap=True log | grep Author >actual &&
428 test_cmp expect actual
432 Author: Santa Claus <santa.claus@northpole.xx>
433 Author: Santa Claus <santa.claus@northpole.xx>
436 test_expect_success 'Grep author with --use-mailmap' '
437 git log --use-mailmap --author Santa | grep Author >actual &&
438 test_cmp expect actual
441 Author: Santa Claus <santa.claus@northpole.xx>
442 Author: Santa Claus <santa.claus@northpole.xx>
445 test_expect_success 'Grep author with log.mailmap' '
446 git -c log.mailmap=True log --author Santa | grep Author >actual &&
447 test_cmp expect actual
452 test_expect_success 'Only grep replaced author with --use-mailmap' '
453 git log --use-mailmap --author "<cto@coompany.xx>" >actual &&
454 test_cmp expect actual
459 ^OBJI (A U Thor DATE 1) one
460 OBJID (Some Dude DATE 2) two
461 OBJID (Other Author DATE 3) three
462 OBJID (Other Author DATE 4) four
463 OBJID (Santa Claus DATE 5) five
464 OBJID (Santa Claus DATE 6) six
465 OBJID (CTO DATE 7) seven
467 test_expect_success 'Blame output (complex mapping)' '
468 git blame one >actual &&
469 fuzz_blame actual >actual.fuzz &&
470 test_cmp expect actual.fuzz