contrib: contacts: add ability to parse from committish
[git/mingw.git] / t / t4203-mailmap.sh
blobb7476f22209133829f334a56b6a83ac5944b8b40
1 #!/bin/sh
3 test_description='.mailmap configurations'
5 . ./test-lib.sh
7 fuzz_blame () {
8 sed "
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
12 " "$@"
15 test_expect_success setup '
16 cat >contacts <<-\EOF &&
17 A U Thor <author@example.com>
18 nick1 <bugs@company.xx>
19 EOF
21 echo one >one &&
22 git add one &&
23 test_tick &&
24 git commit -m initial &&
25 echo two >>one &&
26 git add one &&
27 test_tick &&
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>
39 EOF
40 git check-mailmap \
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>
50 EOF
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>
58 EOF
59 cat <contacts >>expect &&
60 git check-mailmap --stdin "Internal Guy <bugs@company.xy>" \
61 <contacts >actual &&
62 test_cmp expect actual
65 test_expect_success 'check-mailmap bogus contact' '
66 test_must_fail git check-mailmap bogus
69 cat >expect <<\EOF
70 A U Thor (1):
71 initial
73 nick1 (1):
74 second
76 EOF
78 test_expect_success 'No mailmap' '
79 git shortlog HEAD >actual &&
80 test_cmp expect actual
83 cat >expect <<\EOF
84 Repo Guy (1):
85 initial
87 nick1 (1):
88 second
90 EOF
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
100 cat >expect <<\EOF
101 Internal Guy (1):
102 second
104 Repo Guy (1):
105 initial
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
116 cat >expect <<\EOF
117 External Guy (1):
118 initial
120 Internal Guy (1):
121 second
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
131 cat >expect <<\EOF
132 Repo Guy (1):
133 initial
135 nick1 (1):
136 second
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
147 cat >expect <<\EOF
148 Internal Guy (1):
149 second
151 Repo Guy (1):
152 initial
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
164 cat >expect <<\EOF
165 Internal Guy (1):
166 second
168 Repo Guy (1):
169 initial
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
181 cat >expect <<\EOF
182 A U Thor (1):
183 initial
185 nick1 (1):
186 second
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>
201 cat >both <<-\EOF &&
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 &&
213 Blob Guy (1):
214 second
216 Repo Guy (1):
217 initial
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 &&
226 Blob Guy (2):
227 initial
228 second
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 &&
237 Blob Guy (1):
238 second
240 Internal Guy (1):
241 initial
244 git \
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 &&
253 Repo Guy (1):
254 initial
256 nick1 (1):
257 second
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' '
265 git init non-bare &&
267 cd non-bare &&
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 &&
272 rm .mailmap &&
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 &&
282 cd 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' '
290 rm -f .mailmap
293 # Extended mailmap configurations should give us the following output for shortlog
294 cat >expect <<\EOF
295 A U Thor <author@example.com> (1):
296 initial
298 CTO <cto@company.xx> (1):
299 seventh
301 Other Author <other@author.xx> (2):
302 third
303 fourth
305 Santa Claus <santa.claus@northpole.xx> (2):
306 fifth
307 sixth
309 Some Dude <some@dude.xx> (1):
310 second
314 test_expect_success 'Shortlog output (complex mapping)' '
315 echo three >>one &&
316 git add one &&
317 test_tick &&
318 git commit --author "nick2 <bugs@company.xx>" -m third &&
320 echo four >>one &&
321 git add one &&
322 test_tick &&
323 git commit --author "nick2 <nick2@company.xx>" -m fourth &&
325 echo five >>one &&
326 git add one &&
327 test_tick &&
328 git commit --author "santa <me@company.xx>" -m fifth &&
330 echo six >>one &&
331 git add one &&
332 test_tick &&
333 git commit --author "claus <me@company.xx>" -m sixth &&
335 echo seven >>one &&
336 git add one &&
337 test_tick &&
338 git commit --author "CTO <cto@coompany.xx>" -m seventh &&
340 mkdir -p internal_mailmap &&
341 echo "Committed <committer@example.com>" > internal_mailmap/.mailmap &&
342 echo "<cto@company.xx> <cto@coompany.xx>" >> internal_mailmap/.mailmap &&
343 echo "Some Dude <some@dude.xx> nick1 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
344 echo "Other Author <other@author.xx> nick2 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
345 echo "Other Author <other@author.xx> <nick2@company.xx>" >> internal_mailmap/.mailmap &&
346 echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
347 echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
349 git shortlog -e HEAD >actual &&
350 test_cmp expect actual
354 # git log with --pretty format which uses the name and email mailmap placemarkers
355 cat >expect <<\EOF
356 Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx>
357 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
359 Author claus <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
360 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
362 Author santa <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
363 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
365 Author nick2 <nick2@company.xx> maps to Other Author <other@author.xx>
366 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
368 Author nick2 <bugs@company.xx> maps to Other Author <other@author.xx>
369 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
371 Author nick1 <bugs@company.xx> maps to Some Dude <some@dude.xx>
372 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
374 Author A U Thor <author@example.com> maps to A U Thor <author@example.com>
375 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
378 test_expect_success 'Log output (complex mapping)' '
379 git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
380 test_cmp expect actual
383 cat >expect <<\EOF
384 Author: CTO <cto@company.xx>
385 Author: Santa Claus <santa.claus@northpole.xx>
386 Author: Santa Claus <santa.claus@northpole.xx>
387 Author: Other Author <other@author.xx>
388 Author: Other Author <other@author.xx>
389 Author: Some Dude <some@dude.xx>
390 Author: A U Thor <author@example.com>
393 test_expect_success 'Log output with --use-mailmap' '
394 git log --use-mailmap | grep Author >actual &&
395 test_cmp expect actual
398 cat >expect <<\EOF
399 Author: CTO <cto@company.xx>
400 Author: Santa Claus <santa.claus@northpole.xx>
401 Author: Santa Claus <santa.claus@northpole.xx>
402 Author: Other Author <other@author.xx>
403 Author: Other Author <other@author.xx>
404 Author: Some Dude <some@dude.xx>
405 Author: A U Thor <author@example.com>
408 test_expect_success 'Log output with log.mailmap' '
409 git -c log.mailmap=True log | grep Author >actual &&
410 test_cmp expect actual
413 cat >expect <<\EOF
414 Author: Santa Claus <santa.claus@northpole.xx>
415 Author: Santa Claus <santa.claus@northpole.xx>
418 test_expect_success 'Grep author with --use-mailmap' '
419 git log --use-mailmap --author Santa | grep Author >actual &&
420 test_cmp expect actual
422 cat >expect <<\EOF
423 Author: Santa Claus <santa.claus@northpole.xx>
424 Author: Santa Claus <santa.claus@northpole.xx>
427 test_expect_success 'Grep author with log.mailmap' '
428 git -c log.mailmap=True log --author Santa | grep Author >actual &&
429 test_cmp expect actual
432 >expect
434 test_expect_success 'Only grep replaced author with --use-mailmap' '
435 git log --use-mailmap --author "<cto@coompany.xx>" >actual &&
436 test_cmp expect actual
439 # git blame
440 cat >expect <<\EOF
441 ^OBJI (A U Thor DATE 1) one
442 OBJID (Some Dude DATE 2) two
443 OBJID (Other Author DATE 3) three
444 OBJID (Other Author DATE 4) four
445 OBJID (Santa Claus DATE 5) five
446 OBJID (Santa Claus DATE 6) six
447 OBJID (CTO DATE 7) seven
449 test_expect_success 'Blame output (complex mapping)' '
450 git blame one >actual &&
451 fuzz_blame actual >actual.fuzz &&
452 test_cmp expect actual.fuzz
455 test_done