mailmap: handle mailmap blobs without trailing newlines
[git/raj.git] / t / t4203-mailmap.sh
blobd5a8ff3f882be670099b382f85cc3bce2eb57fba
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 echo one >one &&
17 git add one &&
18 test_tick &&
19 git commit -m initial &&
20 echo two >>one &&
21 git add one &&
22 test_tick &&
23 git commit --author "nick1 <bugs@company.xx>" -m second
26 cat >expect <<\EOF
27 A U Thor (1):
28 initial
30 nick1 (1):
31 second
33 EOF
35 test_expect_success 'No mailmap' '
36 git shortlog HEAD >actual &&
37 test_cmp expect actual
40 cat >expect <<\EOF
41 Repo Guy (1):
42 initial
44 nick1 (1):
45 second
47 EOF
49 test_expect_success 'default .mailmap' '
50 echo "Repo Guy <author@example.com>" > .mailmap &&
51 git shortlog HEAD >actual &&
52 test_cmp expect actual
55 # Using a mailmap file in a subdirectory of the repo here, but
56 # could just as well have been a file outside of the repository
57 cat >expect <<\EOF
58 Internal Guy (1):
59 second
61 Repo Guy (1):
62 initial
64 EOF
65 test_expect_success 'mailmap.file set' '
66 mkdir -p internal_mailmap &&
67 echo "Internal Guy <bugs@company.xx>" > internal_mailmap/.mailmap &&
68 git config mailmap.file internal_mailmap/.mailmap &&
69 git shortlog HEAD >actual &&
70 test_cmp expect actual
73 cat >expect <<\EOF
74 External Guy (1):
75 initial
77 Internal Guy (1):
78 second
80 EOF
81 test_expect_success 'mailmap.file override' '
82 echo "External Guy <author@example.com>" >> internal_mailmap/.mailmap &&
83 git config mailmap.file internal_mailmap/.mailmap &&
84 git shortlog HEAD >actual &&
85 test_cmp expect actual
88 cat >expect <<\EOF
89 Repo Guy (1):
90 initial
92 nick1 (1):
93 second
95 EOF
97 test_expect_success 'mailmap.file non-existent' '
98 rm internal_mailmap/.mailmap &&
99 rmdir internal_mailmap &&
100 git shortlog HEAD >actual &&
101 test_cmp expect actual
104 cat >expect <<\EOF
105 Internal Guy (1):
106 second
108 Repo Guy (1):
109 initial
113 test_expect_success 'name entry after email entry' '
114 mkdir -p internal_mailmap &&
115 echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap &&
116 echo "Internal Guy <bugs@company.xx>" >>internal_mailmap/.mailmap &&
117 git shortlog HEAD >actual &&
118 test_cmp expect actual
121 cat >expect <<\EOF
122 Internal Guy (1):
123 second
125 Repo Guy (1):
126 initial
130 test_expect_success 'name entry after email entry, case-insensitive' '
131 mkdir -p internal_mailmap &&
132 echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap &&
133 echo "Internal Guy <BUGS@Company.xx>" >>internal_mailmap/.mailmap &&
134 git shortlog HEAD >actual &&
135 test_cmp expect actual
138 cat >expect <<\EOF
139 A U Thor (1):
140 initial
142 nick1 (1):
143 second
146 test_expect_success 'No mailmap files, but configured' '
147 rm -f .mailmap internal_mailmap/.mailmap &&
148 git shortlog HEAD >actual &&
149 test_cmp expect actual
152 test_expect_success 'setup mailmap blob tests' '
153 git checkout -b map &&
154 test_when_finished "git checkout master" &&
155 cat >just-bugs <<-\EOF &&
156 Blob Guy <bugs@company.xx>
158 cat >both <<-\EOF &&
159 Blob Guy <author@example.com>
160 Blob Guy <bugs@company.xx>
162 printf "Tricky Guy <author@example.com>" >no-newline &&
163 git add just-bugs both no-newline &&
164 git commit -m "my mailmaps" &&
165 echo "Repo Guy <author@example.com>" >.mailmap &&
166 echo "Internal Guy <author@example.com>" >internal.map
169 test_expect_success 'mailmap.blob set' '
170 cat >expect <<-\EOF &&
171 Blob Guy (1):
172 second
174 Repo Guy (1):
175 initial
178 git -c mailmap.blob=map:just-bugs shortlog HEAD >actual &&
179 test_cmp expect actual
182 test_expect_success 'mailmap.blob overrides .mailmap' '
183 cat >expect <<-\EOF &&
184 Blob Guy (2):
185 initial
186 second
189 git -c mailmap.blob=map:both shortlog HEAD >actual &&
190 test_cmp expect actual
193 test_expect_success 'mailmap.file overrides mailmap.blob' '
194 cat >expect <<-\EOF &&
195 Blob Guy (1):
196 second
198 Internal Guy (1):
199 initial
202 git \
203 -c mailmap.blob=map:both \
204 -c mailmap.file=internal.map \
205 shortlog HEAD >actual &&
206 test_cmp expect actual
209 test_expect_success 'mailmap.blob can be missing' '
210 cat >expect <<-\EOF &&
211 Repo Guy (1):
212 initial
214 nick1 (1):
215 second
218 git -c mailmap.blob=map:nonexistent shortlog HEAD >actual &&
219 test_cmp expect actual
222 test_expect_success 'mailmap.blob defaults to off in non-bare repo' '
223 git init non-bare &&
225 cd non-bare &&
226 test_commit one .mailmap "Fake Name <author@example.com>" &&
227 echo " 1 Fake Name" >expect &&
228 git shortlog -ns HEAD >actual &&
229 test_cmp expect actual &&
230 rm .mailmap &&
231 echo " 1 A U Thor" >expect &&
232 git shortlog -ns HEAD >actual &&
233 test_cmp expect actual
237 test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' '
238 git clone --bare non-bare bare &&
240 cd bare &&
241 echo " 1 Fake Name" >expect &&
242 git shortlog -ns HEAD >actual &&
243 test_cmp expect actual
247 test_expect_success 'mailmap.blob can handle blobs without trailing newline' '
248 cat >expect <<-\EOF &&
249 Tricky Guy (1):
250 initial
252 nick1 (1):
253 second
256 git -c mailmap.blob=map:no-newline shortlog HEAD >actual &&
257 test_cmp expect actual
260 test_expect_success 'cleanup after mailmap.blob tests' '
261 rm -f .mailmap
264 # Extended mailmap configurations should give us the following output for shortlog
265 cat >expect <<\EOF
266 A U Thor <author@example.com> (1):
267 initial
269 CTO <cto@company.xx> (1):
270 seventh
272 Other Author <other@author.xx> (2):
273 third
274 fourth
276 Santa Claus <santa.claus@northpole.xx> (2):
277 fifth
278 sixth
280 Some Dude <some@dude.xx> (1):
281 second
285 test_expect_success 'Shortlog output (complex mapping)' '
286 echo three >>one &&
287 git add one &&
288 test_tick &&
289 git commit --author "nick2 <bugs@company.xx>" -m third &&
291 echo four >>one &&
292 git add one &&
293 test_tick &&
294 git commit --author "nick2 <nick2@company.xx>" -m fourth &&
296 echo five >>one &&
297 git add one &&
298 test_tick &&
299 git commit --author "santa <me@company.xx>" -m fifth &&
301 echo six >>one &&
302 git add one &&
303 test_tick &&
304 git commit --author "claus <me@company.xx>" -m sixth &&
306 echo seven >>one &&
307 git add one &&
308 test_tick &&
309 git commit --author "CTO <cto@coompany.xx>" -m seventh &&
311 mkdir -p internal_mailmap &&
312 echo "Committed <committer@example.com>" > internal_mailmap/.mailmap &&
313 echo "<cto@company.xx> <cto@coompany.xx>" >> internal_mailmap/.mailmap &&
314 echo "Some Dude <some@dude.xx> nick1 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
315 echo "Other Author <other@author.xx> nick2 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
316 echo "Other Author <other@author.xx> <nick2@company.xx>" >> internal_mailmap/.mailmap &&
317 echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
318 echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
320 git shortlog -e HEAD >actual &&
321 test_cmp expect actual
325 # git log with --pretty format which uses the name and email mailmap placemarkers
326 cat >expect <<\EOF
327 Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx>
328 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
330 Author claus <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
331 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
333 Author santa <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
334 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
336 Author nick2 <nick2@company.xx> maps to Other Author <other@author.xx>
337 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
339 Author nick2 <bugs@company.xx> maps to Other Author <other@author.xx>
340 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
342 Author nick1 <bugs@company.xx> maps to Some Dude <some@dude.xx>
343 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
345 Author A U Thor <author@example.com> maps to A U Thor <author@example.com>
346 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
349 test_expect_success 'Log output (complex mapping)' '
350 git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
351 test_cmp expect actual
354 cat >expect <<\EOF
355 Author: CTO <cto@company.xx>
356 Author: Santa Claus <santa.claus@northpole.xx>
357 Author: Santa Claus <santa.claus@northpole.xx>
358 Author: Other Author <other@author.xx>
359 Author: Other Author <other@author.xx>
360 Author: Some Dude <some@dude.xx>
361 Author: A U Thor <author@example.com>
364 test_expect_success 'Log output with --use-mailmap' '
365 git log --use-mailmap | grep Author >actual &&
366 test_cmp expect actual
369 cat >expect <<\EOF
370 Author: CTO <cto@company.xx>
371 Author: Santa Claus <santa.claus@northpole.xx>
372 Author: Santa Claus <santa.claus@northpole.xx>
373 Author: Other Author <other@author.xx>
374 Author: Other Author <other@author.xx>
375 Author: Some Dude <some@dude.xx>
376 Author: A U Thor <author@example.com>
379 test_expect_success 'Log output with log.mailmap' '
380 git -c log.mailmap=True log | grep Author >actual &&
381 test_cmp expect actual
384 cat >expect <<\EOF
385 Author: Santa Claus <santa.claus@northpole.xx>
386 Author: Santa Claus <santa.claus@northpole.xx>
389 test_expect_success 'Grep author with --use-mailmap' '
390 git log --use-mailmap --author Santa | grep Author >actual &&
391 test_cmp expect actual
393 cat >expect <<\EOF
394 Author: Santa Claus <santa.claus@northpole.xx>
395 Author: Santa Claus <santa.claus@northpole.xx>
398 test_expect_success 'Grep author with log.mailmap' '
399 git -c log.mailmap=True log --author Santa | grep Author >actual &&
400 test_cmp expect actual
403 >expect
405 test_expect_success 'Only grep replaced author with --use-mailmap' '
406 git log --use-mailmap --author "<cto@coompany.xx>" >actual &&
407 test_cmp expect actual
410 # git blame
411 cat >expect <<\EOF
412 ^OBJI (A U Thor DATE 1) one
413 OBJID (Some Dude DATE 2) two
414 OBJID (Other Author DATE 3) three
415 OBJID (Other Author DATE 4) four
416 OBJID (Santa Claus DATE 5) five
417 OBJID (Santa Claus DATE 6) six
418 OBJID (CTO DATE 7) seven
420 test_expect_success 'Blame output (complex mapping)' '
421 git blame one >actual &&
422 fuzz_blame actual >actual.fuzz &&
423 test_cmp expect actual.fuzz
426 test_done