blob: f698d0c9ad274137a9aa254c8e89bcece8f4cddd [file] [log] [blame]
Johannes Schindelin3714e7c2006-12-22 22:15:59 +01001#!/bin/sh
2#
3# Copyright (c) 2006 Johannes E. Schindelin
4#
5
Junio C Hamano5be60072007-07-02 22:52:14 -07006test_description='git shortlog
Johannes Schindelin3714e7c2006-12-22 22:15:59 +01007'
8
Johannes Schindelin8f378542020-11-18 23:44:27 +00009GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +000010export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11
Johannes Schindelin3714e7c2006-12-22 22:15:59 +010012. ./test-lib.sh
13
Jonathan Niederae00dc12010-05-03 21:57:36 -050014test_expect_success 'setup' '
Charles Bailey5555a2a2017-11-12 15:25:23 +000015 test_tick &&
Jonathan Niederae00dc12010-05-03 21:57:36 -050016 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" &&
Johannes Schindelin3714e7c2006-12-22 22:15:59 +010021
Jonathan Niederae00dc12010-05-03 21:57:36 -050022 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 &&
Johannes Schindelin3714e7c2006-12-22 22:15:59 +010024
Jonathan Niederae00dc12010-05-03 21:57:36 -050025 # 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 &&
Johannes Schindelin3714e7c2006-12-22 22:15:59 +010032
Jonathan Niederae00dc12010-05-03 21:57:36 -050033 # 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 &&
Johannes Schindelin3714e7c2006-12-22 22:15:59 +010040
Jonathan Niederae00dc12010-05-03 21:57:36 -050041 echo 5 >a1 &&
Jonathan Niedera48fcd82010-10-30 20:46:54 -050042 git commit --quiet -m "a 12 34 56 78" a1 &&
Jonathan Niedered715b52010-05-03 21:58:04 -050043
44 echo 6 >a1 &&
45 git commit --quiet -m "Commit by someone else" \
Jonathan Nieder60037242010-05-03 21:59:55 -050046 --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
62fuzz() {
63 file=$1 &&
64 sed "
brian m. carlson2ece6ad2018-05-13 02:24:15 +000065 s/$OID_REGEX/OBJECT_NAME/g
Charles Bailey5555a2a2017-11-12 15:25:23 +000066 s/$_x35/OBJID/g
Jonathan Nieder60037242010-05-03 21:59:55 -050067 s/^ \{6\}[CTa].*/ SUBJECT/g
68 s/^ \{8\}[^ ].*/ CONTINUATION/g
69 " <"$file" >"$file.fuzzy" &&
70 sed "/CONTINUATION/ d" <"$file.fuzzy"
71}
72
73test_expect_success 'default output format' '
74 git shortlog HEAD >log &&
75 fuzz log >log.predictable &&
76 test_cmp expect.template log.predictable
77'
78
79test_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
Jeff King251554c2022-10-24 14:55:30 -040086test_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
Will Palmerc1977022010-05-03 22:18:57 -050093test_expect_success '--abbrev' '
Jonathan Nieder60037242010-05-03 21:59:55 -050094 sed s/SUBJECT/OBJID/ expect.template >expect &&
Charles Bailey5555a2a2017-11-12 15:25:23 +000095 git shortlog --format="%h" --abbrev=35 HEAD >log &&
Jonathan Nieder60037242010-05-03 21:59:55 -050096 fuzz log >log.predictable &&
97 test_cmp expect log.predictable
98'
99
100test_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
Jonathan Niederae00dc12010-05-03 21:57:36 -0500105'
Johannes Schindelin3714e7c2006-12-22 22:15:59 +0100106
Junio C Hamanof57a8712014-07-21 15:09:27 -0700107test_expect_success !MINGW 'shortlog wrapping' '
Jonathan Niederae00dc12010-05-03 21:57:36 -0500108 cat >expect <<\EOF &&
Johannes Schindelin3714e7c2006-12-22 22:15:59 +0100109A 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ø„žs ø„žs a very, very long fø„žrst lø„žne for the commø„žt
116 message to see ø„žf ø„žt ø„žs wrapped correctly
117 a 12 34
118 56 78
119
Jonathan Niedered715b52010-05-03 21:58:04 -0500120Someone else (1):
121 Commit by someone else
122
Johannes Schindelin3714e7c2006-12-22 22:15:59 +0100123EOF
Jonathan Niederae00dc12010-05-03 21:57:36 -0500124 git shortlog -w HEAD >out &&
125 test_cmp expect out
126'
Johannes Schindelin3714e7c2006-12-22 22:15:59 +0100127
Junio C Hamanof57a8712014-07-21 15:09:27 -0700128test_expect_success !MINGW 'shortlog from non-git directory' '
Junio C Hamano0893eec2016-03-29 15:49:24 -0700129 git log --no-expand-tabs HEAD >log &&
Jonathan Niederae00dc12010-05-03 21:57:36 -0500130 GIT_DIR=non-existing git shortlog -w <log >out &&
131 test_cmp expect out
132'
Jonas Fonsecaabe549e2008-03-14 22:35:24 +0100133
Jeff King5c3894c2016-01-18 15:02:40 -0500134test_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
Martin Ågren4aa01612018-03-14 22:34:19 +0100140test_expect_success 'shortlog from non-git directory refuses extra arguments' '
141 test_must_fail env GIT_DIR=non-existing git shortlog foo 2>out &&
Junio C Hamano67892752023-10-31 14:23:30 +0900142 test_grep "too many arguments" out
Martin Ågren4aa01612018-03-14 22:34:19 +0100143'
144
Steffen Prohaska5b597082012-12-11 06:59:21 +0100145test_expect_success 'shortlog should add newline when input line matches wraplen' '
146 cat >expect <<\EOF &&
147A 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
151EOF
152 git shortlog -w >out <<\EOF &&
153commit 0000000000000000000000000000000000000001
154Author: A U Thor <author@example.com>
155Date: Thu Apr 7 15:14:13 2005 -0700
156
157 aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
158
159commit 0000000000000000000000000000000000000002
160Author: A U Thor <author@example.com>
161Date: Thu Apr 7 15:14:13 2005 -0700
162
163 bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
164
165EOF
166 test_cmp expect out
167'
168
Uwe Kleine-König79f7ca02009-11-25 20:33:28 +0100169iconvfromutf8toiso88591() {
Brandon Casey3994e8a2009-12-03 11:52:45 -0600170 printf "%s" "$*" | iconv -f UTF-8 -t ISO8859-1
Uwe Kleine-König79f7ca02009-11-25 20:33:28 +0100171}
172
173DSCHO="Jöhännës \"Dschö\" Schindëlin"
174DSCHOE="$DSCHO <Johannes.Schindelin@gmx.de>"
175MSG1="set a1 to 2 and some non-ASCII chars: Äßø"
176MSG2="set a1 to 3 and some non-ASCII chars: áæï"
177cat > expect << EOF
178$DSCHO (2):
179 $MSG1
180 $MSG2
181
182EOF
183
Junio C Hamanof57a8712014-07-21 15:09:27 -0700184test_expect_success !MINGW 'shortlog encoding' '
Uwe Kleine-König79f7ca02009-11-25 20:33:28 +0100185 git reset --hard "$commit" &&
186 git config --unset i18n.commitencoding &&
187 echo 2 > a1 &&
188 git commit --quiet -m "$MSG1" --author="$DSCHOE" a1 &&
Brandon Casey3994e8a2009-12-03 11:52:45 -0600189 git config i18n.commitencoding "ISO8859-1" &&
Uwe Kleine-König79f7ca02009-11-25 20:33:28 +0100190 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 &&
195test_cmp expect out'
196
Junio C Hamanoeb077742014-05-30 12:57:25 -0700197test_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
Johannes Schindelin7f7d7122016-06-22 17:02:07 +0200203test_expect_success 'shortlog with --output=<file>' '
Johannes Schindelin8f378542020-11-18 23:44:27 +0000204 git shortlog --output=shortlog -1 main >output &&
SZEDER Gáborf0dc5932018-08-19 23:57:23 +0200205 test_must_be_empty output &&
Johannes Schindelinbac233f2016-07-11 15:11:37 +0200206 test_line_count = 3 shortlog
Johannes Schindelin7f7d7122016-06-22 17:02:07 +0200207'
208
Jeff King03f40822016-12-16 08:51:41 -0500209test_expect_success 'shortlog --committer (internal)' '
Junio C Hamanobc44f932016-12-20 10:35:54 -0800210 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
Jeff King03f40822016-12-16 08:51:41 -0500215 cat >expect <<-\EOF &&
Junio C Hamanobc44f932016-12-20 10:35:54 -0800216 2 C O Mitter
217 1 Sin Nombre
Jeff King03f40822016-12-16 08:51:41 -0500218 EOF
219 git shortlog -nsc HEAD >actual &&
220 test_cmp expect actual
221'
222
223test_expect_success 'shortlog --committer (external)' '
224 git log --format=full | git shortlog -nsc >actual &&
225 test_cmp expect actual
226'
227
Jeff King92338c42020-09-27 04:39:59 -0400228test_expect_success '--group=committer is the same as --committer' '
229 git shortlog -ns --group=committer HEAD >actual &&
230 test_cmp expect actual
231'
232
Jeff King47beb372020-09-27 04:40:04 -0400233test_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
Jeff King56d5dde2020-09-27 04:40:11 -0400243 git shortlog -nse --group=trailer:signed-off-by HEAD >actual &&
244 test_cmp expect actual
245'
246
Taylor Blau3dc95e02022-10-24 14:55:39 -0400247test_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
257test_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
262test_expect_success 'shortlog bogus --group' '
263 test_must_fail git shortlog --group=bogus HEAD 2>err &&
264 grep "unknown group type" err
265'
266
Jeff King56d5dde2020-09-27 04:40:11 -0400267test_expect_success 'trailer idents are split' '
268 cat >expect <<-\EOF &&
269 2 C O Mitter
270 1 SOB One
271 EOF
Jeff King47beb372020-09-27 04:40:04 -0400272 git shortlog -ns --group=trailer:signed-off-by HEAD >actual &&
273 test_cmp expect actual
274'
275
Jeff King56d5dde2020-09-27 04:40:11 -0400276test_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
Jeff Kingf17b0b92020-09-27 04:40:07 -0400287test_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
Linus Arvera082e282024-03-01 00:14:39 +0000315# Trailers that have unfolded (single line) and folded (multiline) values which
316# are otherwise identical are treated as the same trailer for de-duplication.
317test_expect_success 'shortlog de-duplicates trailers in a single commit (folded/unfolded values)' '
318 git commit --allow-empty -F - <<-\EOF &&
319 subject one
320
321 this message has two distinct values, plus a repeat (folded)
322
323 Repeated-trailer: Foo foo foo
324 Repeated-trailer: Bar
325 Repeated-trailer: Foo
326 foo foo
327 EOF
328
329 git commit --allow-empty -F - <<-\EOF &&
330 subject two
331
332 similar to the previous, but without the second distinct value
333
334 Repeated-trailer: Foo foo foo
335 Repeated-trailer: Foo
336 foo foo
337 EOF
338
339 cat >expect <<-\EOF &&
340 2 Foo foo foo
341 1 Bar
342 EOF
343 git shortlog -ns --group=trailer:repeated-trailer -2 HEAD >actual &&
344 test_cmp expect actual
345'
346
Jeff King63d24fa2020-09-27 04:40:15 -0400347test_expect_success 'shortlog can match multiple groups' '
348 git commit --allow-empty -F - <<-\EOF &&
349 subject one
350
351 this has two trailers that are distinct from the author; it will count
352 3 times in the output
353
354 Some-trailer: User A <a@example.com>
355 Another-trailer: User B <b@example.com>
356 EOF
357
358 git commit --allow-empty -F - <<-\EOF &&
359 subject two
360
361 this one has two trailers, one of which is a duplicate with the author;
362 it will only be counted once for them
363
364 Another-trailer: A U Thor <author@example.com>
365 Some-trailer: User B <b@example.com>
366 EOF
367
368 cat >expect <<-\EOF &&
369 2 A U Thor
370 2 User B
371 1 User A
372 EOF
373 git shortlog -ns \
374 --group=author \
375 --group=trailer:some-trailer \
376 --group=trailer:another-trailer \
377 -2 HEAD >actual &&
378 test_cmp expect actual
379'
380
Taylor Blau3dc95e02022-10-24 14:55:39 -0400381test_expect_success 'shortlog can match multiple format groups' '
382 GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" \
383 git commit --allow-empty -m "identical names" &&
384 test_tick &&
385 cat >expect <<-\EOF &&
386 2 A U Thor
387 1 C O Mitter
388 EOF
389 git shortlog -ns --group="%cn" --group="%an" -2 HEAD >actual &&
390 test_cmp expect actual
391'
392
Jeff King63d24fa2020-09-27 04:40:15 -0400393test_expect_success 'set up option selection tests' '
394 git commit --allow-empty -F - <<-\EOF
395 subject
396
397 body
398
399 Trailer-one: value-one
400 Trailer-two: value-two
401 EOF
402'
403
404test_expect_success '--no-group resets group list to author' '
405 cat >expect <<-\EOF &&
406 1 A U Thor
407 EOF
408 git shortlog -ns \
409 --group=committer \
410 --group=trailer:trailer-one \
411 --no-group \
412 -1 HEAD >actual &&
413 test_cmp expect actual
414'
415
416test_expect_success '--no-group resets trailer list' '
417 cat >expect <<-\EOF &&
418 1 value-two
419 EOF
420 git shortlog -ns \
421 --group=trailer:trailer-one \
422 --no-group \
423 --group=trailer:trailer-two \
424 -1 HEAD >actual &&
425 test_cmp expect actual
426'
427
428test_expect_success 'stdin with multiple groups reports error' '
429 git log >log &&
430 test_must_fail git shortlog --group=author --group=committer <log
431'
432
Johannes Schindelin3714e7c2006-12-22 22:15:59 +0100433test_done