]>
Commit | Line | Data |
---|---|---|
d551a488 MSO |
1 | #!/bin/sh |
2 | ||
3 | test_description='.mailmap configurations' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
bfdfa3d4 JN |
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 | " "$@" | |
13 | } | |
14 | ||
d551a488 | 15 | test_expect_success setup ' |
cb5c9521 ES |
16 | cat >contacts <<-\EOF && |
17 | A U Thor <author@example.com> | |
18 | nick1 <bugs@company.xx> | |
19 | EOF | |
20 | ||
d551a488 MSO |
21 | echo one >one && |
22 | git add one && | |
23 | test_tick && | |
24 | git commit -m initial && | |
25 | echo two >>one && | |
26 | git add one && | |
d8d2eb7d | 27 | test_tick && |
d551a488 MSO |
28 | git commit --author "nick1 <bugs@company.xx>" -m second |
29 | ' | |
30 | ||
cb5c9521 ES |
31 | test_expect_success 'check-mailmap no arguments' ' |
32 | test_must_fail git check-mailmap | |
33 | ' | |
34 | ||
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 | |
44 | ' | |
45 | ||
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 | |
53 | ' | |
54 | ||
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 | |
63 | ' | |
64 | ||
65 | test_expect_success 'check-mailmap bogus contact' ' | |
66 | test_must_fail git check-mailmap bogus | |
67 | ' | |
68 | ||
d551a488 MSO |
69 | cat >expect <<\EOF |
70 | A U Thor (1): | |
71 | initial | |
72 | ||
73 | nick1 (1): | |
74 | second | |
75 | ||
76 | EOF | |
77 | ||
78 | test_expect_success 'No mailmap' ' | |
79 | git shortlog HEAD >actual && | |
80 | test_cmp expect actual | |
81 | ' | |
82 | ||
83 | cat >expect <<\EOF | |
84 | Repo Guy (1): | |
85 | initial | |
86 | ||
87 | nick1 (1): | |
88 | second | |
89 | ||
90 | EOF | |
91 | ||
92 | test_expect_success 'default .mailmap' ' | |
93 | echo "Repo Guy <author@example.com>" > .mailmap && | |
94 | git shortlog HEAD >actual && | |
95 | test_cmp expect actual | |
96 | ' | |
97 | ||
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 | |
103 | ||
104 | Repo Guy (1): | |
105 | initial | |
106 | ||
107 | EOF | |
108 | test_expect_success 'mailmap.file set' ' | |
d8d2eb7d | 109 | mkdir -p internal_mailmap && |
d551a488 MSO |
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 | |
114 | ' | |
115 | ||
116 | cat >expect <<\EOF | |
117 | External Guy (1): | |
118 | initial | |
119 | ||
120 | Internal Guy (1): | |
121 | second | |
122 | ||
123 | EOF | |
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 | |
129 | ' | |
130 | ||
131 | cat >expect <<\EOF | |
132 | Repo Guy (1): | |
133 | initial | |
134 | ||
135 | nick1 (1): | |
136 | second | |
137 | ||
138 | EOF | |
139 | ||
7be8b3ba | 140 | test_expect_success 'mailmap.file non-existent' ' |
d551a488 MSO |
141 | rm internal_mailmap/.mailmap && |
142 | rmdir internal_mailmap && | |
143 | git shortlog HEAD >actual && | |
144 | test_cmp expect actual | |
145 | ' | |
146 | ||
d8d2eb7d JM |
147 | cat >expect <<\EOF |
148 | Internal Guy (1): | |
149 | second | |
150 | ||
151 | Repo Guy (1): | |
152 | initial | |
153 | ||
154 | EOF | |
155 | ||
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 && | |
3e3e1ef5 | 160 | git shortlog HEAD >actual && |
d8d2eb7d JM |
161 | test_cmp expect actual |
162 | ' | |
163 | ||
164 | cat >expect <<\EOF | |
165 | Internal Guy (1): | |
166 | second | |
167 | ||
168 | Repo Guy (1): | |
169 | initial | |
170 | ||
171 | EOF | |
172 | ||
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 && | |
3e3e1ef5 | 177 | git shortlog HEAD >actual && |
d8d2eb7d JM |
178 | test_cmp expect actual |
179 | ' | |
180 | ||
d551a488 MSO |
181 | cat >expect <<\EOF |
182 | A U Thor (1): | |
183 | initial | |
184 | ||
185 | nick1 (1): | |
186 | second | |
187 | ||
188 | EOF | |
189 | test_expect_success 'No mailmap files, but configured' ' | |
d8d2eb7d | 190 | rm -f .mailmap internal_mailmap/.mailmap && |
d551a488 MSO |
191 | git shortlog HEAD >actual && |
192 | test_cmp expect actual | |
193 | ' | |
194 | ||
08610900 JK |
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> | |
200 | EOF | |
201 | cat >both <<-\EOF && | |
202 | Blob Guy <author@example.com> | |
203 | Blob Guy <bugs@company.xx> | |
204 | EOF | |
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 | |
209 | ' | |
210 | ||
211 | test_expect_success 'mailmap.blob set' ' | |
212 | cat >expect <<-\EOF && | |
213 | Blob Guy (1): | |
214 | second | |
215 | ||
216 | Repo Guy (1): | |
217 | initial | |
218 | ||
219 | EOF | |
220 | git -c mailmap.blob=map:just-bugs shortlog HEAD >actual && | |
221 | test_cmp expect actual | |
222 | ' | |
223 | ||
224 | test_expect_success 'mailmap.blob overrides .mailmap' ' | |
225 | cat >expect <<-\EOF && | |
226 | Blob Guy (2): | |
227 | initial | |
228 | second | |
229 | ||
230 | EOF | |
231 | git -c mailmap.blob=map:both shortlog HEAD >actual && | |
232 | test_cmp expect actual | |
233 | ' | |
234 | ||
235 | test_expect_success 'mailmap.file overrides mailmap.blob' ' | |
236 | cat >expect <<-\EOF && | |
237 | Blob Guy (1): | |
238 | second | |
239 | ||
240 | Internal Guy (1): | |
241 | initial | |
242 | ||
243 | EOF | |
244 | git \ | |
245 | -c mailmap.blob=map:both \ | |
246 | -c mailmap.file=internal.map \ | |
247 | shortlog HEAD >actual && | |
248 | test_cmp expect actual | |
249 | ' | |
250 | ||
251 | test_expect_success 'mailmap.blob can be missing' ' | |
252 | cat >expect <<-\EOF && | |
253 | Repo Guy (1): | |
254 | initial | |
255 | ||
256 | nick1 (1): | |
257 | second | |
258 | ||
259 | EOF | |
260 | git -c mailmap.blob=map:nonexistent shortlog HEAD >actual && | |
261 | test_cmp expect actual | |
262 | ' | |
263 | ||
8c473cec JK |
264 | test_expect_success 'mailmap.blob defaults to off in non-bare repo' ' |
265 | git init non-bare && | |
266 | ( | |
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 | |
276 | ) | |
277 | ' | |
278 | ||
279 | test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' ' | |
280 | git clone --bare non-bare bare && | |
281 | ( | |
282 | cd bare && | |
283 | echo " 1 Fake Name" >expect && | |
284 | git shortlog -ns HEAD >actual && | |
285 | test_cmp expect actual | |
286 | ) | |
287 | ' | |
288 | ||
08610900 JK |
289 | test_expect_success 'cleanup after mailmap.blob tests' ' |
290 | rm -f .mailmap | |
291 | ' | |
292 | ||
8c381151 | 293 | test_expect_success 'single-character name' ' |
109025b4 ES |
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 | |
3aff56dd ES |
300 | ' |
301 | ||
97e751be | 302 | test_expect_success 'preserve canonical email case' ' |
3aff56dd ES |
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 | |
109025b4 ES |
309 | ' |
310 | ||
d20d654f MSO |
311 | # Extended mailmap configurations should give us the following output for shortlog |
312 | cat >expect <<\EOF | |
313 | A U Thor <author@example.com> (1): | |
314 | initial | |
315 | ||
316 | CTO <cto@company.xx> (1): | |
317 | seventh | |
318 | ||
319 | Other Author <other@author.xx> (2): | |
320 | third | |
321 | fourth | |
322 | ||
323 | Santa Claus <santa.claus@northpole.xx> (2): | |
324 | fifth | |
325 | sixth | |
326 | ||
327 | Some Dude <some@dude.xx> (1): | |
328 | second | |
329 | ||
330 | EOF | |
331 | ||
332 | test_expect_success 'Shortlog output (complex mapping)' ' | |
333 | echo three >>one && | |
334 | git add one && | |
335 | test_tick && | |
336 | git commit --author "nick2 <bugs@company.xx>" -m third && | |
337 | ||
338 | echo four >>one && | |
339 | git add one && | |
340 | test_tick && | |
341 | git commit --author "nick2 <nick2@company.xx>" -m fourth && | |
342 | ||
343 | echo five >>one && | |
344 | git add one && | |
345 | test_tick && | |
346 | git commit --author "santa <me@company.xx>" -m fifth && | |
347 | ||
348 | echo six >>one && | |
349 | git add one && | |
350 | test_tick && | |
351 | git commit --author "claus <me@company.xx>" -m sixth && | |
352 | ||
353 | echo seven >>one && | |
354 | git add one && | |
355 | test_tick && | |
356 | git commit --author "CTO <cto@coompany.xx>" -m seventh && | |
357 | ||
d8d2eb7d | 358 | mkdir -p internal_mailmap && |
d20d654f MSO |
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 && | |
366 | ||
367 | git shortlog -e HEAD >actual && | |
368 | test_cmp expect actual | |
369 | ||
370 | ' | |
371 | ||
372 | # git log with --pretty format which uses the name and email mailmap placemarkers | |
373 | cat >expect <<\EOF | |
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> | |
376 | ||
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> | |
379 | ||
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> | |
382 | ||
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> | |
385 | ||
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> | |
388 | ||
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> | |
391 | ||
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> | |
394 | EOF | |
395 | ||
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 | |
399 | ' | |
400 | ||
d2074343 AP |
401 | cat >expect <<\EOF |
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> | |
409 | EOF | |
d72fbe81 | 410 | |
d2074343 AP |
411 | test_expect_success 'Log output with --use-mailmap' ' |
412 | git log --use-mailmap | grep Author >actual && | |
413 | test_cmp expect actual | |
414 | ' | |
415 | ||
e6bb5f78 AP |
416 | cat >expect <<\EOF |
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> | |
424 | EOF | |
425 | ||
426 | test_expect_success 'Log output with log.mailmap' ' | |
427 | git -c log.mailmap=True log | grep Author >actual && | |
428 | test_cmp expect actual | |
429 | ' | |
430 | ||
d72fbe81 AP |
431 | cat >expect <<\EOF |
432 | Author: Santa Claus <santa.claus@northpole.xx> | |
433 | Author: Santa Claus <santa.claus@northpole.xx> | |
434 | EOF | |
435 | ||
436 | test_expect_success 'Grep author with --use-mailmap' ' | |
437 | git log --use-mailmap --author Santa | grep Author >actual && | |
438 | test_cmp expect actual | |
439 | ' | |
e6bb5f78 AP |
440 | cat >expect <<\EOF |
441 | Author: Santa Claus <santa.claus@northpole.xx> | |
442 | Author: Santa Claus <santa.claus@northpole.xx> | |
443 | EOF | |
444 | ||
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 | |
448 | ' | |
d72fbe81 AP |
449 | |
450 | >expect | |
451 | ||
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 | |
455 | ' | |
456 | ||
d20d654f MSO |
457 | # git blame |
458 | cat >expect <<\EOF | |
bfdfa3d4 JN |
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 | |
d20d654f | 466 | EOF |
d20d654f MSO |
467 | test_expect_success 'Blame output (complex mapping)' ' |
468 | git blame one >actual && | |
bfdfa3d4 JN |
469 | fuzz_blame actual >actual.fuzz && |
470 | test_cmp expect actual.fuzz | |
d20d654f MSO |
471 | ' |
472 | ||
d551a488 | 473 | test_done |