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