log: add log.mailmap configuration option
[git/jnareb-git.git] / t / t4203-mailmap.sh
blob7d4d31c830cbdf1bb300f563863c61494a783989
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 # Extended mailmap configurations should give us the following output for shortlog
153 cat >expect <<\EOF
154 A U Thor <author@example.com> (1):
155 initial
157 CTO <cto@company.xx> (1):
158 seventh
160 Other Author <other@author.xx> (2):
161 third
162 fourth
164 Santa Claus <santa.claus@northpole.xx> (2):
165 fifth
166 sixth
168 Some Dude <some@dude.xx> (1):
169 second
173 test_expect_success 'Shortlog output (complex mapping)' '
174 echo three >>one &&
175 git add one &&
176 test_tick &&
177 git commit --author "nick2 <bugs@company.xx>" -m third &&
179 echo four >>one &&
180 git add one &&
181 test_tick &&
182 git commit --author "nick2 <nick2@company.xx>" -m fourth &&
184 echo five >>one &&
185 git add one &&
186 test_tick &&
187 git commit --author "santa <me@company.xx>" -m fifth &&
189 echo six >>one &&
190 git add one &&
191 test_tick &&
192 git commit --author "claus <me@company.xx>" -m sixth &&
194 echo seven >>one &&
195 git add one &&
196 test_tick &&
197 git commit --author "CTO <cto@coompany.xx>" -m seventh &&
199 mkdir -p internal_mailmap &&
200 echo "Committed <committer@example.com>" > internal_mailmap/.mailmap &&
201 echo "<cto@company.xx> <cto@coompany.xx>" >> internal_mailmap/.mailmap &&
202 echo "Some Dude <some@dude.xx> nick1 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
203 echo "Other Author <other@author.xx> nick2 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
204 echo "Other Author <other@author.xx> <nick2@company.xx>" >> internal_mailmap/.mailmap &&
205 echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
206 echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
208 git shortlog -e HEAD >actual &&
209 test_cmp expect actual
213 # git log with --pretty format which uses the name and email mailmap placemarkers
214 cat >expect <<\EOF
215 Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx>
216 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
218 Author claus <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
219 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
221 Author santa <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
222 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
224 Author nick2 <nick2@company.xx> maps to Other Author <other@author.xx>
225 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
227 Author nick2 <bugs@company.xx> maps to Other Author <other@author.xx>
228 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
230 Author nick1 <bugs@company.xx> maps to Some Dude <some@dude.xx>
231 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
233 Author A U Thor <author@example.com> maps to A U Thor <author@example.com>
234 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
237 test_expect_success 'Log output (complex mapping)' '
238 git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
239 test_cmp expect actual
242 cat >expect <<\EOF
243 Author: CTO <cto@company.xx>
244 Author: Santa Claus <santa.claus@northpole.xx>
245 Author: Santa Claus <santa.claus@northpole.xx>
246 Author: Other Author <other@author.xx>
247 Author: Other Author <other@author.xx>
248 Author: Some Dude <some@dude.xx>
249 Author: A U Thor <author@example.com>
252 test_expect_success 'Log output with --use-mailmap' '
253 git log --use-mailmap | grep Author >actual &&
254 test_cmp expect actual
257 cat >expect <<\EOF
258 Author: CTO <cto@company.xx>
259 Author: Santa Claus <santa.claus@northpole.xx>
260 Author: Santa Claus <santa.claus@northpole.xx>
261 Author: Other Author <other@author.xx>
262 Author: Other Author <other@author.xx>
263 Author: Some Dude <some@dude.xx>
264 Author: A U Thor <author@example.com>
267 test_expect_success 'Log output with log.mailmap' '
268 git -c log.mailmap=True log | grep Author >actual &&
269 test_cmp expect actual
272 cat >expect <<\EOF
273 Author: Santa Claus <santa.claus@northpole.xx>
274 Author: Santa Claus <santa.claus@northpole.xx>
277 test_expect_success 'Grep author with --use-mailmap' '
278 git log --use-mailmap --author Santa | grep Author >actual &&
279 test_cmp expect actual
281 cat >expect <<\EOF
282 Author: Santa Claus <santa.claus@northpole.xx>
283 Author: Santa Claus <santa.claus@northpole.xx>
286 test_expect_success 'Grep author with log.mailmap' '
287 git -c log.mailmap=True log --author Santa | grep Author >actual &&
288 test_cmp expect actual
291 >expect
293 test_expect_success 'Only grep replaced author with --use-mailmap' '
294 git log --use-mailmap --author "<cto@coompany.xx>" >actual &&
295 test_cmp expect actual
298 # git blame
299 cat >expect <<\EOF
300 ^OBJI (A U Thor DATE 1) one
301 OBJID (Some Dude DATE 2) two
302 OBJID (Other Author DATE 3) three
303 OBJID (Other Author DATE 4) four
304 OBJID (Santa Claus DATE 5) five
305 OBJID (Santa Claus DATE 6) six
306 OBJID (CTO DATE 7) seven
308 test_expect_success 'Blame output (complex mapping)' '
309 git blame one >actual &&
310 fuzz_blame actual >actual.fuzz &&
311 test_cmp expect actual.fuzz
314 test_done