]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4201-shortlog.sh
doc: make the gitfile syntax easier to discover
[thirdparty/git.git] / t / t4201-shortlog.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Johannes E. Schindelin
4 #
5
6 test_description='git shortlog
7 '
8
9 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
10 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11
12 . ./test-lib.sh
13
14 test_expect_success 'setup' '
15 test_tick &&
16 echo 1 >a1 &&
17 git add a1 &&
18 tree=$(git write-tree) &&
19 commit=$(printf "%s\n" "Test" "" | git commit-tree "$tree") &&
20 git update-ref HEAD "$commit" &&
21
22 echo 2 >a1 &&
23 git commit --quiet -m "This is a very, very long first line for the commit message to see if it is wrapped correctly" a1 &&
24
25 # test if the wrapping is still valid
26 # when replacing all is by treble clefs.
27 echo 3 >a1 &&
28 git commit --quiet -m "$(
29 echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" |
30 sed "s/i/1234/g" |
31 tr 1234 "\360\235\204\236")" a1 &&
32
33 # now fsck up the utf8
34 git config i18n.commitencoding non-utf-8 &&
35 echo 4 >a1 &&
36 git commit --quiet -m "$(
37 echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" |
38 sed "s/i/1234/g" |
39 tr 1234 "\370\235\204\236")" a1 &&
40
41 echo 5 >a1 &&
42 git commit --quiet -m "a 12 34 56 78" a1 &&
43
44 echo 6 >a1 &&
45 git commit --quiet -m "Commit by someone else" \
46 --author="Someone else <not!me>" a1 &&
47
48 cat >expect.template <<-\EOF
49 A U Thor (5):
50 SUBJECT
51 SUBJECT
52 SUBJECT
53 SUBJECT
54 SUBJECT
55
56 Someone else (1):
57 SUBJECT
58
59 EOF
60 '
61
62 fuzz() {
63 file=$1 &&
64 sed "
65 s/$OID_REGEX/OBJECT_NAME/g
66 s/$_x35/OBJID/g
67 s/^ \{6\}[CTa].*/ SUBJECT/g
68 s/^ \{8\}[^ ].*/ CONTINUATION/g
69 " <"$file" >"$file.fuzzy" &&
70 sed "/CONTINUATION/ d" <"$file.fuzzy"
71 }
72
73 test_expect_success 'default output format' '
74 git shortlog HEAD >log &&
75 fuzz log >log.predictable &&
76 test_cmp expect.template log.predictable
77 '
78
79 test_expect_success 'pretty format' '
80 sed s/SUBJECT/OBJECT_NAME/ expect.template >expect &&
81 git shortlog --format="%H" HEAD >log &&
82 fuzz log >log.predictable &&
83 test_cmp expect log.predictable
84 '
85
86 test_expect_success 'pretty format (with --date)' '
87 sed "s/SUBJECT/2005-04-07 OBJECT_NAME/" expect.template >expect &&
88 git shortlog --format="%ad %H" --date=short HEAD >log &&
89 fuzz log >log.predictable &&
90 test_cmp expect log.predictable
91 '
92
93 test_expect_success '--abbrev' '
94 sed s/SUBJECT/OBJID/ expect.template >expect &&
95 git shortlog --format="%h" --abbrev=35 HEAD >log &&
96 fuzz log >log.predictable &&
97 test_cmp expect log.predictable
98 '
99
100 test_expect_success 'output from user-defined format is re-wrapped' '
101 sed "s/SUBJECT/two lines/" expect.template >expect &&
102 git shortlog --format="two%nlines" HEAD >log &&
103 fuzz log >log.predictable &&
104 test_cmp expect log.predictable
105 '
106
107 test_expect_success !MINGW 'shortlog wrapping' '
108 cat >expect <<\EOF &&
109 A U Thor (5):
110 Test
111 This is a very, very long first line for the commit message to see if
112 it is wrapped correctly
113 Th𝄞s 𝄞s a very, very long f𝄞rst l𝄞ne for the comm𝄞t message to see 𝄞f
114 𝄞t 𝄞s wrapped correctly
115 Thø\9d\84\9es ø\9d\84\9es a very, very long fø\9d\84\9erst lø\9d\84\9ene for the commø\9d\84\9et
116 message to see ø\9d\84\9ef ø\9d\84\9et ø\9d\84\9es wrapped correctly
117 a 12 34
118 56 78
119
120 Someone else (1):
121 Commit by someone else
122
123 EOF
124 git shortlog -w HEAD >out &&
125 test_cmp expect out
126 '
127
128 test_expect_success !MINGW 'shortlog from non-git directory' '
129 git log --no-expand-tabs HEAD >log &&
130 GIT_DIR=non-existing git shortlog -w <log >out &&
131 test_cmp expect out
132 '
133
134 test_expect_success !MINGW 'shortlog can read --format=raw output' '
135 git log --format=raw HEAD >log &&
136 GIT_DIR=non-existing git shortlog -w <log >out &&
137 test_cmp expect out
138 '
139
140 test_expect_success 'shortlog from non-git directory refuses extra arguments' '
141 test_must_fail env GIT_DIR=non-existing git shortlog foo 2>out &&
142 test_i18ngrep "too many arguments" out
143 '
144
145 test_expect_success 'shortlog should add newline when input line matches wraplen' '
146 cat >expect <<\EOF &&
147 A U Thor (2):
148 bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
149 aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
150
151 EOF
152 git shortlog -w >out <<\EOF &&
153 commit 0000000000000000000000000000000000000001
154 Author: A U Thor <author@example.com>
155 Date: Thu Apr 7 15:14:13 2005 -0700
156
157 aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
158
159 commit 0000000000000000000000000000000000000002
160 Author: A U Thor <author@example.com>
161 Date: Thu Apr 7 15:14:13 2005 -0700
162
163 bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
164
165 EOF
166 test_cmp expect out
167 '
168
169 iconvfromutf8toiso88591() {
170 printf "%s" "$*" | iconv -f UTF-8 -t ISO8859-1
171 }
172
173 DSCHO="Jöhännës \"Dschö\" Schindëlin"
174 DSCHOE="$DSCHO <Johannes.Schindelin@gmx.de>"
175 MSG1="set a1 to 2 and some non-ASCII chars: Äßø"
176 MSG2="set a1 to 3 and some non-ASCII chars: áæï"
177 cat > expect << EOF
178 $DSCHO (2):
179 $MSG1
180 $MSG2
181
182 EOF
183
184 test_expect_success !MINGW 'shortlog encoding' '
185 git reset --hard "$commit" &&
186 git config --unset i18n.commitencoding &&
187 echo 2 > a1 &&
188 git commit --quiet -m "$MSG1" --author="$DSCHOE" a1 &&
189 git config i18n.commitencoding "ISO8859-1" &&
190 echo 3 > a1 &&
191 git commit --quiet -m "$(iconvfromutf8toiso88591 "$MSG2")" \
192 --author="$(iconvfromutf8toiso88591 "$DSCHOE")" a1 &&
193 git config --unset i18n.commitencoding &&
194 git shortlog HEAD~2.. > out &&
195 test_cmp expect out'
196
197 test_expect_success 'shortlog with revision pseudo options' '
198 git shortlog --all &&
199 git shortlog --branches &&
200 git shortlog --exclude=refs/heads/m* --all
201 '
202
203 test_expect_success 'shortlog with --output=<file>' '
204 git shortlog --output=shortlog -1 main >output &&
205 test_must_be_empty output &&
206 test_line_count = 3 shortlog
207 '
208
209 test_expect_success 'shortlog --committer (internal)' '
210 git checkout --orphan side &&
211 git commit --allow-empty -m one &&
212 git commit --allow-empty -m two &&
213 GIT_COMMITTER_NAME="Sin Nombre" git commit --allow-empty -m three &&
214
215 cat >expect <<-\EOF &&
216 2 C O Mitter
217 1 Sin Nombre
218 EOF
219 git shortlog -nsc HEAD >actual &&
220 test_cmp expect actual
221 '
222
223 test_expect_success 'shortlog --committer (external)' '
224 git log --format=full | git shortlog -nsc >actual &&
225 test_cmp expect actual
226 '
227
228 test_expect_success '--group=committer is the same as --committer' '
229 git shortlog -ns --group=committer HEAD >actual &&
230 test_cmp expect actual
231 '
232
233 test_expect_success 'shortlog --group=trailer:signed-off-by' '
234 git commit --allow-empty -m foo -s &&
235 GIT_COMMITTER_NAME="SOB One" \
236 GIT_COMMITTER_EMAIL=sob@example.com \
237 git commit --allow-empty -m foo -s &&
238 git commit --allow-empty --amend --no-edit -s &&
239 cat >expect <<-\EOF &&
240 2 C O Mitter <committer@example.com>
241 1 SOB One <sob@example.com>
242 EOF
243 git shortlog -nse --group=trailer:signed-off-by HEAD >actual &&
244 test_cmp expect actual
245 '
246
247 test_expect_success 'shortlog --group=format' '
248 git shortlog -s --date="format:%Y" --group="format:%cN (%cd)" \
249 HEAD >actual &&
250 cat >expect <<-\EOF &&
251 4 C O Mitter (2005)
252 1 Sin Nombre (2005)
253 EOF
254 test_cmp expect actual
255 '
256
257 test_expect_success 'shortlog --group=<format> DWIM' '
258 git shortlog -s --date="format:%Y" --group="%cN (%cd)" HEAD >actual &&
259 test_cmp expect actual
260 '
261
262 test_expect_success 'shortlog bogus --group' '
263 test_must_fail git shortlog --group=bogus HEAD 2>err &&
264 grep "unknown group type" err
265 '
266
267 test_expect_success 'trailer idents are split' '
268 cat >expect <<-\EOF &&
269 2 C O Mitter
270 1 SOB One
271 EOF
272 git shortlog -ns --group=trailer:signed-off-by HEAD >actual &&
273 test_cmp expect actual
274 '
275
276 test_expect_success 'trailer idents are mailmapped' '
277 cat >expect <<-\EOF &&
278 2 C O Mitter
279 1 Another Name
280 EOF
281 echo "Another Name <sob@example.com>" >mail.map &&
282 git -c mailmap.file=mail.map shortlog -ns \
283 --group=trailer:signed-off-by HEAD >actual &&
284 test_cmp expect actual
285 '
286
287 test_expect_success 'shortlog de-duplicates trailers in a single commit' '
288 git commit --allow-empty -F - <<-\EOF &&
289 subject one
290
291 this message has two distinct values, plus a repeat
292
293 Repeated-trailer: Foo
294 Repeated-trailer: Bar
295 Repeated-trailer: Foo
296 EOF
297
298 git commit --allow-empty -F - <<-\EOF &&
299 subject two
300
301 similar to the previous, but without the second distinct value
302
303 Repeated-trailer: Foo
304 Repeated-trailer: Foo
305 EOF
306
307 cat >expect <<-\EOF &&
308 2 Foo
309 1 Bar
310 EOF
311 git shortlog -ns --group=trailer:repeated-trailer -2 HEAD >actual &&
312 test_cmp expect actual
313 '
314
315 test_expect_success 'shortlog can match multiple groups' '
316 git commit --allow-empty -F - <<-\EOF &&
317 subject one
318
319 this has two trailers that are distinct from the author; it will count
320 3 times in the output
321
322 Some-trailer: User A <a@example.com>
323 Another-trailer: User B <b@example.com>
324 EOF
325
326 git commit --allow-empty -F - <<-\EOF &&
327 subject two
328
329 this one has two trailers, one of which is a duplicate with the author;
330 it will only be counted once for them
331
332 Another-trailer: A U Thor <author@example.com>
333 Some-trailer: User B <b@example.com>
334 EOF
335
336 cat >expect <<-\EOF &&
337 2 A U Thor
338 2 User B
339 1 User A
340 EOF
341 git shortlog -ns \
342 --group=author \
343 --group=trailer:some-trailer \
344 --group=trailer:another-trailer \
345 -2 HEAD >actual &&
346 test_cmp expect actual
347 '
348
349 test_expect_success 'shortlog can match multiple format groups' '
350 GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" \
351 git commit --allow-empty -m "identical names" &&
352 test_tick &&
353 cat >expect <<-\EOF &&
354 2 A U Thor
355 1 C O Mitter
356 EOF
357 git shortlog -ns --group="%cn" --group="%an" -2 HEAD >actual &&
358 test_cmp expect actual
359 '
360
361 test_expect_success 'set up option selection tests' '
362 git commit --allow-empty -F - <<-\EOF
363 subject
364
365 body
366
367 Trailer-one: value-one
368 Trailer-two: value-two
369 EOF
370 '
371
372 test_expect_success '--no-group resets group list to author' '
373 cat >expect <<-\EOF &&
374 1 A U Thor
375 EOF
376 git shortlog -ns \
377 --group=committer \
378 --group=trailer:trailer-one \
379 --no-group \
380 -1 HEAD >actual &&
381 test_cmp expect actual
382 '
383
384 test_expect_success '--no-group resets trailer list' '
385 cat >expect <<-\EOF &&
386 1 value-two
387 EOF
388 git shortlog -ns \
389 --group=trailer:trailer-one \
390 --no-group \
391 --group=trailer:trailer-two \
392 -1 HEAD >actual &&
393 test_cmp expect actual
394 '
395
396 test_expect_success 'stdin with multiple groups reports error' '
397 git log >log &&
398 test_must_fail git shortlog --group=author --group=committer <log
399 '
400
401 test_done