Git fork
1#!/bin/sh
2#
3# Copyright (c) 2006 Johannes E. Schindelin
4#
5
6test_description='git shortlog
7'
8
9GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
10export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11
12. ./test-lib.sh
13
14test_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
62fuzz() {
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
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
86test_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
93test_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
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
105'
106
107test_expect_success !MINGW,ICONV 'shortlog wrapping' '
108 cat >expect <<\EOF &&
109A 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
120Someone else (1):
121 Commit by someone else
122
123EOF
124 git shortlog -w HEAD >out &&
125 test_cmp expect out
126'
127
128test_expect_success !MINGW,ICONV '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
134test_expect_success !MINGW,ICONV '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
140test_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_grep "too many arguments" out
143'
144
145test_expect_success 'shortlog --author from non-git directory does not segfault' '
146 nongit git shortlog --author=author </dev/null
147'
148
149test_expect_success 'shortlog should add newline when input line matches wraplen' '
150 cat >expect <<\EOF &&
151A U Thor (2):
152 bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
153 aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
154
155EOF
156 git shortlog -w >out <<\EOF &&
157commit 0000000000000000000000000000000000000001
158Author: A U Thor <author@example.com>
159Date: Thu Apr 7 15:14:13 2005 -0700
160
161 aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
162
163commit 0000000000000000000000000000000000000002
164Author: A U Thor <author@example.com>
165Date: Thu Apr 7 15:14:13 2005 -0700
166
167 bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
168
169EOF
170 test_cmp expect out
171'
172
173iconvfromutf8toiso88591() {
174 printf "%s" "$*" | iconv -f UTF-8 -t ISO8859-1
175}
176
177DSCHO="Jöhännës \"Dschö\" Schindëlin"
178DSCHOE="$DSCHO <Johannes.Schindelin@gmx.de>"
179MSG1="set a1 to 2 and some non-ASCII chars: Äßø"
180MSG2="set a1 to 3 and some non-ASCII chars: áæï"
181cat > expect << EOF
182$DSCHO (2):
183 $MSG1
184 $MSG2
185
186EOF
187
188test_expect_success !MINGW,ICONV 'shortlog encoding' '
189 git reset --hard "$commit" &&
190 git config --unset i18n.commitencoding &&
191 echo 2 > a1 &&
192 git commit --quiet -m "$MSG1" --author="$DSCHOE" a1 &&
193 git config i18n.commitencoding "ISO8859-1" &&
194 echo 3 > a1 &&
195 git commit --quiet -m "$(iconvfromutf8toiso88591 "$MSG2")" \
196 --author="$(iconvfromutf8toiso88591 "$DSCHOE")" a1 &&
197 git config --unset i18n.commitencoding &&
198 git shortlog HEAD~2.. > out &&
199test_cmp expect out'
200
201test_expect_success 'shortlog with revision pseudo options' '
202 git shortlog --all &&
203 git shortlog --branches &&
204 git shortlog --exclude=refs/heads/m* --all
205'
206
207test_expect_success 'shortlog with --output=<file>' '
208 git shortlog --output=shortlog -1 main >output &&
209 test_must_be_empty output &&
210 test_line_count = 3 shortlog
211'
212
213test_expect_success 'shortlog --committer (internal)' '
214 git checkout --orphan side &&
215 git commit --allow-empty -m one &&
216 git commit --allow-empty -m two &&
217 GIT_COMMITTER_NAME="Sin Nombre" git commit --allow-empty -m three &&
218
219 cat >expect <<-\EOF &&
220 2 C O Mitter
221 1 Sin Nombre
222 EOF
223 git shortlog -nsc HEAD >actual &&
224 test_cmp expect actual
225'
226
227test_expect_success 'shortlog --committer (external)' '
228 git log --format=full | git shortlog -nsc >actual &&
229 test_cmp expect actual
230'
231
232test_expect_success '--group=committer is the same as --committer' '
233 git shortlog -ns --group=committer HEAD >actual &&
234 test_cmp expect actual
235'
236
237test_expect_success 'shortlog --group=trailer:signed-off-by' '
238 git commit --allow-empty -m foo -s &&
239 GIT_COMMITTER_NAME="SOB One" \
240 GIT_COMMITTER_EMAIL=sob@example.com \
241 git commit --allow-empty -m foo -s &&
242 git commit --allow-empty --amend --no-edit -s &&
243 cat >expect <<-\EOF &&
244 2 C O Mitter <committer@example.com>
245 1 SOB One <sob@example.com>
246 EOF
247 git shortlog -nse --group=trailer:signed-off-by HEAD >actual &&
248 test_cmp expect actual
249'
250
251test_expect_success 'shortlog --group=format' '
252 git shortlog -s --date="format:%Y" --group="format:%cN (%cd)" \
253 HEAD >actual &&
254 cat >expect <<-\EOF &&
255 4 C O Mitter (2005)
256 1 Sin Nombre (2005)
257 EOF
258 test_cmp expect actual
259'
260
261test_expect_success 'shortlog --group=<format> DWIM' '
262 git shortlog -s --date="format:%Y" --group="%cN (%cd)" HEAD >actual &&
263 test_cmp expect actual
264'
265
266test_expect_success 'shortlog bogus --group' '
267 test_must_fail git shortlog --group=bogus HEAD 2>err &&
268 grep "unknown group type" err
269'
270
271test_expect_success 'trailer idents are split' '
272 cat >expect <<-\EOF &&
273 2 C O Mitter
274 1 SOB One
275 EOF
276 git shortlog -ns --group=trailer:signed-off-by HEAD >actual &&
277 test_cmp expect actual
278'
279
280test_expect_success 'trailer idents are mailmapped' '
281 cat >expect <<-\EOF &&
282 2 C O Mitter
283 1 Another Name
284 EOF
285 echo "Another Name <sob@example.com>" >mail.map &&
286 git -c mailmap.file=mail.map shortlog -ns \
287 --group=trailer:signed-off-by HEAD >actual &&
288 test_cmp expect actual
289'
290
291test_expect_success 'shortlog de-duplicates trailers in a single commit' '
292 git commit --allow-empty -F - <<-\EOF &&
293 subject one
294
295 this message has two distinct values, plus a repeat
296
297 Repeated-trailer: Foo
298 Repeated-trailer: Bar
299 Repeated-trailer: Foo
300 EOF
301
302 git commit --allow-empty -F - <<-\EOF &&
303 subject two
304
305 similar to the previous, but without the second distinct value
306
307 Repeated-trailer: Foo
308 Repeated-trailer: Foo
309 EOF
310
311 cat >expect <<-\EOF &&
312 2 Foo
313 1 Bar
314 EOF
315 git shortlog -ns --group=trailer:repeated-trailer -2 HEAD >actual &&
316 test_cmp expect actual
317'
318
319# Trailers that have unfolded (single line) and folded (multiline) values which
320# are otherwise identical are treated as the same trailer for de-duplication.
321test_expect_success 'shortlog de-duplicates trailers in a single commit (folded/unfolded values)' '
322 git commit --allow-empty -F - <<-\EOF &&
323 subject one
324
325 this message has two distinct values, plus a repeat (folded)
326
327 Repeated-trailer: Foo foo foo
328 Repeated-trailer: Bar
329 Repeated-trailer: Foo
330 foo foo
331 EOF
332
333 git commit --allow-empty -F - <<-\EOF &&
334 subject two
335
336 similar to the previous, but without the second distinct value
337
338 Repeated-trailer: Foo foo foo
339 Repeated-trailer: Foo
340 foo foo
341 EOF
342
343 cat >expect <<-\EOF &&
344 2 Foo foo foo
345 1 Bar
346 EOF
347 git shortlog -ns --group=trailer:repeated-trailer -2 HEAD >actual &&
348 test_cmp expect actual
349'
350
351test_expect_success 'shortlog can match multiple groups' '
352 git commit --allow-empty -F - <<-\EOF &&
353 subject one
354
355 this has two trailers that are distinct from the author; it will count
356 3 times in the output
357
358 Some-trailer: User A <a@example.com>
359 Another-trailer: User B <b@example.com>
360 EOF
361
362 git commit --allow-empty -F - <<-\EOF &&
363 subject two
364
365 this one has two trailers, one of which is a duplicate with the author;
366 it will only be counted once for them
367
368 Another-trailer: A U Thor <author@example.com>
369 Some-trailer: User B <b@example.com>
370 EOF
371
372 cat >expect <<-\EOF &&
373 2 A U Thor
374 2 User B
375 1 User A
376 EOF
377 git shortlog -ns \
378 --group=author \
379 --group=trailer:some-trailer \
380 --group=trailer:another-trailer \
381 -2 HEAD >actual &&
382 test_cmp expect actual
383'
384
385test_expect_success 'shortlog can match multiple format groups' '
386 GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" \
387 git commit --allow-empty -m "identical names" &&
388 test_tick &&
389 cat >expect <<-\EOF &&
390 2 A U Thor
391 1 C O Mitter
392 EOF
393 git shortlog -ns --group="%cn" --group="%an" -2 HEAD >actual &&
394 test_cmp expect actual
395'
396
397test_expect_success 'set up option selection tests' '
398 git commit --allow-empty -F - <<-\EOF
399 subject
400
401 body
402
403 Trailer-one: value-one
404 Trailer-two: value-two
405 EOF
406'
407
408test_expect_success '--no-group resets group list to author' '
409 cat >expect <<-\EOF &&
410 1 A U Thor
411 EOF
412 git shortlog -ns \
413 --group=committer \
414 --group=trailer:trailer-one \
415 --no-group \
416 -1 HEAD >actual &&
417 test_cmp expect actual
418'
419
420test_expect_success '--no-group resets trailer list' '
421 cat >expect <<-\EOF &&
422 1 value-two
423 EOF
424 git shortlog -ns \
425 --group=trailer:trailer-one \
426 --no-group \
427 --group=trailer:trailer-two \
428 -1 HEAD >actual &&
429 test_cmp expect actual
430'
431
432test_expect_success 'stdin with multiple groups reports error' '
433 git log >log &&
434 test_must_fail git shortlog --group=author --group=committer <log
435'
436
437test_done