interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t4201-shortlog.sh

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