tests: mark tests relying on the current default for `init.defaultBranch`
[alt-git.git] / t / t4203-mailmap.sh
blob8a2f8984f6225dfe7c6ef7764e4f29ec8b195fb6
1 #!/bin/sh
3 test_description='.mailmap configurations'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
10 fuzz_blame () {
11 sed "
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
15 " "$@"
18 test_expect_success setup '
19 cat >contacts <<- EOF &&
20 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
21 nick1 <bugs@company.xx>
22 EOF
24 echo one >one &&
25 git add one &&
26 test_tick &&
27 git commit -m initial &&
28 echo two >>one &&
29 git add one &&
30 test_tick &&
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>
42 EOF
43 git check-mailmap \
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>
53 EOF
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>
61 EOF
62 cat <contacts >>expect &&
63 git check-mailmap --stdin "Internal Guy <bugs@company.xy>" \
64 <contacts >actual &&
65 test_cmp expect actual
68 test_expect_success 'check-mailmap bogus contact' '
69 test_must_fail git check-mailmap bogus
72 cat >expect << EOF
73 $GIT_AUTHOR_NAME (1):
74 initial
76 nick1 (1):
77 second
79 EOF
81 test_expect_success 'No mailmap' '
82 git shortlog HEAD >actual &&
83 test_cmp expect actual
86 cat >expect <<\EOF
87 Repo Guy (1):
88 initial
90 nick1 (1):
91 second
93 EOF
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
103 cat >expect <<\EOF
104 Internal Guy (1):
105 second
107 Repo Guy (1):
108 initial
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
119 cat >expect <<\EOF
120 External Guy (1):
121 initial
123 Internal Guy (1):
124 second
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
134 cat >expect <<\EOF
135 Repo Guy (1):
136 initial
138 nick1 (1):
139 second
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
150 cat >expect <<\EOF
151 Internal Guy (1):
152 second
154 Repo Guy (1):
155 initial
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
167 cat >expect <<\EOF
168 Internal Guy (1):
169 second
171 Repo Guy (1):
172 initial
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
184 cat >expect << EOF
185 $GIT_AUTHOR_NAME (1):
186 initial
188 nick1 (1):
189 second
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>
204 cat >both <<- EOF &&
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 &&
217 Blob Guy (1):
218 second
220 Repo Guy (1):
221 initial
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 &&
230 Blob Guy (2):
231 initial
232 second
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 &&
241 Blob Guy (1):
242 second
244 Internal Guy (1):
245 initial
248 git \
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 &&
257 Repo Guy (1):
258 initial
260 nick1 (1):
261 second
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' '
269 git init non-bare &&
271 cd non-bare &&
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 &&
276 rm .mailmap &&
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 &&
286 cd 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 &&
295 Tricky Guy (1):
296 initial
298 nick1 (1):
299 second
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' '
307 rm -f .mailmap
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
329 cat >expect << EOF
330 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1):
331 initial
333 CTO <cto@company.xx> (1):
334 seventh
336 Other Author <other@author.xx> (2):
337 third
338 fourth
340 Santa Claus <santa.claus@northpole.xx> (2):
341 fifth
342 sixth
344 Some Dude <some@dude.xx> (1):
345 second
349 test_expect_success 'Shortlog output (complex mapping)' '
350 echo three >>one &&
351 git add one &&
352 test_tick &&
353 git commit --author "nick2 <bugs@company.xx>" -m third &&
355 echo four >>one &&
356 git add one &&
357 test_tick &&
358 git commit --author "nick2 <nick2@company.xx>" -m fourth &&
360 echo five >>one &&
361 git add one &&
362 test_tick &&
363 git commit --author "santa <me@company.xx>" -m fifth &&
365 echo six >>one &&
366 git add one &&
367 test_tick &&
368 git commit --author "claus <me@company.xx>" -m sixth &&
370 echo seven >>one &&
371 git add one &&
372 test_tick &&
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
390 cat >expect << EOF
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
418 cat >expect << EOF
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
446 cat >expect << EOF
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
461 cat >expect << EOF
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
504 cat >expect <<\EOF
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
513 cat >expect <<\EOF
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
533 # git blame
534 cat >expect <<EOF
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
549 cat >expect <<\EOF
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
560 test_done