mailmap: fix use of freed memory
[git] / t / t4203-mailmap.sh
1 #!/bin/sh
2
3 test_description='.mailmap configurations'
4
5 . ./test-lib.sh
6
7 test_expect_success setup '
8         echo one >one &&
9         git add one &&
10         test_tick &&
11         git commit -m initial &&
12         echo two >>one &&
13         git add one &&
14         test_tick &&
15         git commit --author "nick1 <bugs@company.xx>" -m second
16 '
17
18 cat >expect <<\EOF
19 A U Thor (1):
20       initial
21
22 nick1 (1):
23       second
24
25 EOF
26
27 test_expect_success 'No mailmap' '
28         git shortlog HEAD >actual &&
29         test_cmp expect actual
30 '
31
32 cat >expect <<\EOF
33 Repo Guy (1):
34       initial
35
36 nick1 (1):
37       second
38
39 EOF
40
41 test_expect_success 'default .mailmap' '
42         echo "Repo Guy <author@example.com>" > .mailmap &&
43         git shortlog HEAD >actual &&
44         test_cmp expect actual
45 '
46
47 # Using a mailmap file in a subdirectory of the repo here, but
48 # could just as well have been a file outside of the repository
49 cat >expect <<\EOF
50 Internal Guy (1):
51       second
52
53 Repo Guy (1):
54       initial
55
56 EOF
57 test_expect_success 'mailmap.file set' '
58         mkdir -p internal_mailmap &&
59         echo "Internal Guy <bugs@company.xx>" > internal_mailmap/.mailmap &&
60         git config mailmap.file internal_mailmap/.mailmap &&
61         git shortlog HEAD >actual &&
62         test_cmp expect actual
63 '
64
65 cat >expect <<\EOF
66 External Guy (1):
67       initial
68
69 Internal Guy (1):
70       second
71
72 EOF
73 test_expect_success 'mailmap.file override' '
74         echo "External Guy <author@example.com>" >> internal_mailmap/.mailmap &&
75         git config mailmap.file internal_mailmap/.mailmap &&
76         git shortlog HEAD >actual &&
77         test_cmp expect actual
78 '
79
80 cat >expect <<\EOF
81 Repo Guy (1):
82       initial
83
84 nick1 (1):
85       second
86
87 EOF
88
89 test_expect_success 'mailmap.file non-existant' '
90         rm internal_mailmap/.mailmap &&
91         rmdir internal_mailmap &&
92         git shortlog HEAD >actual &&
93         test_cmp expect actual
94 '
95
96 cat >expect <<\EOF
97 Internal Guy (1):
98       second
99
100 Repo Guy (1):
101       initial
102
103 EOF
104
105 test_expect_success 'name entry after email entry' '
106         mkdir -p internal_mailmap &&
107         echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap &&
108         echo "Internal Guy <bugs@company.xx>" >>internal_mailmap/.mailmap &&
109         git shortlog >actual &&
110         test_cmp expect actual
111 '
112
113 cat >expect <<\EOF
114 Internal Guy (1):
115       second
116
117 Repo Guy (1):
118       initial
119
120 EOF
121
122 test_expect_success 'name entry after email entry, case-insensitive' '
123         mkdir -p internal_mailmap &&
124         echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap &&
125         echo "Internal Guy <BUGS@Company.xx>" >>internal_mailmap/.mailmap &&
126         git shortlog >actual &&
127         test_cmp expect actual
128 '
129
130 cat >expect <<\EOF
131 A U Thor (1):
132       initial
133
134 nick1 (1):
135       second
136
137 EOF
138 test_expect_success 'No mailmap files, but configured' '
139         rm -f .mailmap internal_mailmap/.mailmap &&
140         git shortlog HEAD >actual &&
141         test_cmp expect actual
142 '
143
144 # Extended mailmap configurations should give us the following output for shortlog
145 cat >expect <<\EOF
146 A U Thor <author@example.com> (1):
147       initial
148
149 CTO <cto@company.xx> (1):
150       seventh
151
152 Other Author <other@author.xx> (2):
153       third
154       fourth
155
156 Santa Claus <santa.claus@northpole.xx> (2):
157       fifth
158       sixth
159
160 Some Dude <some@dude.xx> (1):
161       second
162
163 EOF
164
165 test_expect_success 'Shortlog output (complex mapping)' '
166         echo three >>one &&
167         git add one &&
168         test_tick &&
169         git commit --author "nick2 <bugs@company.xx>" -m third &&
170
171         echo four >>one &&
172         git add one &&
173         test_tick &&
174         git commit --author "nick2 <nick2@company.xx>" -m fourth &&
175
176         echo five >>one &&
177         git add one &&
178         test_tick &&
179         git commit --author "santa <me@company.xx>" -m fifth &&
180
181         echo six >>one &&
182         git add one &&
183         test_tick &&
184         git commit --author "claus <me@company.xx>" -m sixth &&
185
186         echo seven >>one &&
187         git add one &&
188         test_tick &&
189         git commit --author "CTO <cto@coompany.xx>" -m seventh &&
190
191         mkdir -p internal_mailmap &&
192         echo "Committed <committer@example.com>" > internal_mailmap/.mailmap &&
193         echo "<cto@company.xx>                       <cto@coompany.xx>" >> internal_mailmap/.mailmap &&
194         echo "Some Dude <some@dude.xx>         nick1 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
195         echo "Other Author <other@author.xx>   nick2 <bugs@company.xx>" >> internal_mailmap/.mailmap &&
196         echo "Other Author <other@author.xx>         <nick2@company.xx>" >> internal_mailmap/.mailmap &&
197         echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
198         echo "Santa Claus <santa.claus@northpole.xx> <me@company.xx>" >> internal_mailmap/.mailmap &&
199
200         git shortlog -e HEAD >actual &&
201         test_cmp expect actual
202
203 '
204
205 # git log with --pretty format which uses the name and email mailmap placemarkers
206 cat >expect <<\EOF
207 Author CTO <cto@coompany.xx> maps to CTO <cto@company.xx>
208 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
209
210 Author claus <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
211 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
212
213 Author santa <me@company.xx> maps to Santa Claus <santa.claus@northpole.xx>
214 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
215
216 Author nick2 <nick2@company.xx> maps to Other Author <other@author.xx>
217 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
218
219 Author nick2 <bugs@company.xx> maps to Other Author <other@author.xx>
220 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
221
222 Author nick1 <bugs@company.xx> maps to Some Dude <some@dude.xx>
223 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
224
225 Author A U Thor <author@example.com> maps to A U Thor <author@example.com>
226 Committer C O Mitter <committer@example.com> maps to Committed <committer@example.com>
227 EOF
228
229 test_expect_success 'Log output (complex mapping)' '
230         git log --pretty=format:"Author %an <%ae> maps to %aN <%aE>%nCommitter %cn <%ce> maps to %cN <%cE>%n" >actual &&
231         test_cmp expect actual
232 '
233
234 # git blame
235 cat >expect <<\EOF
236 ^3a2fdcb (A U Thor     2005-04-07 15:13:13 -0700 1) one
237 7de6f99b (Some Dude    2005-04-07 15:13:13 -0700 2) two
238 5815879d (Other Author 2005-04-07 15:14:13 -0700 3) three
239 ff859d96 (Other Author 2005-04-07 15:15:13 -0700 4) four
240 5ab6d4fa (Santa Claus  2005-04-07 15:16:13 -0700 5) five
241 38a42d8b (Santa Claus  2005-04-07 15:17:13 -0700 6) six
242 8ddc0386 (CTO          2005-04-07 15:18:13 -0700 7) seven
243 EOF
244
245 test_expect_success 'Blame output (complex mapping)' '
246         git blame one >actual &&
247         test_cmp expect actual
248 '
249
250 test_done