Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t4201-shortlog.sh
blobc20c88572445dcc835218509aa280e66dc5b5cf4
1 #!/bin/sh
3 # Copyright (c) 2006 Johannes E. Schindelin
6 test_description='git shortlog
9 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
10 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12 TEST_PASSES_SANITIZE_LEAK=true
13 . ./test-lib.sh
15 test_expect_success 'setup' '
16 test_tick &&
17 echo 1 >a1 &&
18 git add a1 &&
19 tree=$(git write-tree) &&
20 commit=$(printf "%s\n" "Test" "" | git commit-tree "$tree") &&
21 git update-ref HEAD "$commit" &&
23 echo 2 >a1 &&
24 git commit --quiet -m "This is a very, very long first line for the commit message to see if it is wrapped correctly" a1 &&
26 # test if the wrapping is still valid
27 # when replacing all is by treble clefs.
28 echo 3 >a1 &&
29 git commit --quiet -m "$(
30 echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" |
31 sed "s/i/1234/g" |
32 tr 1234 "\360\235\204\236")" a1 &&
34 # now fsck up the utf8
35 git config i18n.commitencoding non-utf-8 &&
36 echo 4 >a1 &&
37 git commit --quiet -m "$(
38 echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" |
39 sed "s/i/1234/g" |
40 tr 1234 "\370\235\204\236")" a1 &&
42 echo 5 >a1 &&
43 git commit --quiet -m "a 12 34 56 78" a1 &&
45 echo 6 >a1 &&
46 git commit --quiet -m "Commit by someone else" \
47 --author="Someone else <not!me>" a1 &&
49 cat >expect.template <<-\EOF
50 A U Thor (5):
51 SUBJECT
52 SUBJECT
53 SUBJECT
54 SUBJECT
55 SUBJECT
57 Someone else (1):
58 SUBJECT
60 EOF
63 fuzz() {
64 file=$1 &&
65 sed "
66 s/$OID_REGEX/OBJECT_NAME/g
67 s/$_x35/OBJID/g
68 s/^ \{6\}[CTa].*/ SUBJECT/g
69 s/^ \{8\}[^ ].*/ CONTINUATION/g
70 " <"$file" >"$file.fuzzy" &&
71 sed "/CONTINUATION/ d" <"$file.fuzzy"
74 test_expect_success 'default output format' '
75 git shortlog HEAD >log &&
76 fuzz log >log.predictable &&
77 test_cmp expect.template log.predictable
80 test_expect_success 'pretty format' '
81 sed s/SUBJECT/OBJECT_NAME/ expect.template >expect &&
82 git shortlog --format="%H" HEAD >log &&
83 fuzz log >log.predictable &&
84 test_cmp expect log.predictable
87 test_expect_success 'pretty format (with --date)' '
88 sed "s/SUBJECT/2005-04-07 OBJECT_NAME/" expect.template >expect &&
89 git shortlog --format="%ad %H" --date=short HEAD >log &&
90 fuzz log >log.predictable &&
91 test_cmp expect log.predictable
94 test_expect_success '--abbrev' '
95 sed s/SUBJECT/OBJID/ expect.template >expect &&
96 git shortlog --format="%h" --abbrev=35 HEAD >log &&
97 fuzz log >log.predictable &&
98 test_cmp expect log.predictable
101 test_expect_success 'output from user-defined format is re-wrapped' '
102 sed "s/SUBJECT/two lines/" expect.template >expect &&
103 git shortlog --format="two%nlines" HEAD >log &&
104 fuzz log >log.predictable &&
105 test_cmp expect log.predictable
108 test_expect_success !MINGW 'shortlog wrapping' '
109 cat >expect <<\EOF &&
110 A U Thor (5):
111 Test
112 This is a very, very long first line for the commit message to see if
113 it is wrapped correctly
114 Th𝄞s 𝄞s a very, very long f𝄞rst l𝄞ne for the comm𝄞t message to see 𝄞f
115 𝄞t 𝄞s wrapped correctly
116 Thø�„žs ø�„žs a very, very long fø�„žrst lø�„žne for the commø�„žt
117 message to see ø�„žf ø�„žt ø�„žs wrapped correctly
118 a 12 34
119 56 78
121 Someone else (1):
122 Commit by someone else
125 git shortlog -w HEAD >out &&
126 test_cmp expect out
129 test_expect_success !MINGW 'shortlog from non-git directory' '
130 git log --no-expand-tabs HEAD >log &&
131 GIT_DIR=non-existing git shortlog -w <log >out &&
132 test_cmp expect out
135 test_expect_success !MINGW 'shortlog can read --format=raw output' '
136 git log --format=raw HEAD >log &&
137 GIT_DIR=non-existing git shortlog -w <log >out &&
138 test_cmp expect out
141 test_expect_success 'shortlog from non-git directory refuses extra arguments' '
142 test_must_fail env GIT_DIR=non-existing git shortlog foo 2>out &&
143 test_grep "too many arguments" out
146 test_expect_success 'shortlog should add newline when input line matches wraplen' '
147 cat >expect <<\EOF &&
148 A U Thor (2):
149 bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
150 aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
153 git shortlog -w >out <<\EOF &&
154 commit 0000000000000000000000000000000000000001
155 Author: A U Thor <author@example.com>
156 Date: Thu Apr 7 15:14:13 2005 -0700
158 aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
160 commit 0000000000000000000000000000000000000002
161 Author: A U Thor <author@example.com>
162 Date: Thu Apr 7 15:14:13 2005 -0700
164 bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
167 test_cmp expect out
170 iconvfromutf8toiso88591() {
171 printf "%s" "$*" | iconv -f UTF-8 -t ISO8859-1
174 DSCHO="Jöhännës \"Dschö\" Schindëlin"
175 DSCHOE="$DSCHO <Johannes.Schindelin@gmx.de>"
176 MSG1="set a1 to 2 and some non-ASCII chars: Äßø"
177 MSG2="set a1 to 3 and some non-ASCII chars: áæï"
178 cat > expect << EOF
179 $DSCHO (2):
180 $MSG1
181 $MSG2
185 test_expect_success !MINGW 'shortlog encoding' '
186 git reset --hard "$commit" &&
187 git config --unset i18n.commitencoding &&
188 echo 2 > a1 &&
189 git commit --quiet -m "$MSG1" --author="$DSCHOE" a1 &&
190 git config i18n.commitencoding "ISO8859-1" &&
191 echo 3 > a1 &&
192 git commit --quiet -m "$(iconvfromutf8toiso88591 "$MSG2")" \
193 --author="$(iconvfromutf8toiso88591 "$DSCHOE")" a1 &&
194 git config --unset i18n.commitencoding &&
195 git shortlog HEAD~2.. > out &&
196 test_cmp expect out'
198 test_expect_success 'shortlog with revision pseudo options' '
199 git shortlog --all &&
200 git shortlog --branches &&
201 git shortlog --exclude=refs/heads/m* --all
204 test_expect_success 'shortlog with --output=<file>' '
205 git shortlog --output=shortlog -1 main >output &&
206 test_must_be_empty output &&
207 test_line_count = 3 shortlog
210 test_expect_success 'shortlog --committer (internal)' '
211 git checkout --orphan side &&
212 git commit --allow-empty -m one &&
213 git commit --allow-empty -m two &&
214 GIT_COMMITTER_NAME="Sin Nombre" git commit --allow-empty -m three &&
216 cat >expect <<-\EOF &&
217 2 C O Mitter
218 1 Sin Nombre
220 git shortlog -nsc HEAD >actual &&
221 test_cmp expect actual
224 test_expect_success 'shortlog --committer (external)' '
225 git log --format=full | git shortlog -nsc >actual &&
226 test_cmp expect actual
229 test_expect_success '--group=committer is the same as --committer' '
230 git shortlog -ns --group=committer HEAD >actual &&
231 test_cmp expect actual
234 test_expect_success 'shortlog --group=trailer:signed-off-by' '
235 git commit --allow-empty -m foo -s &&
236 GIT_COMMITTER_NAME="SOB One" \
237 GIT_COMMITTER_EMAIL=sob@example.com \
238 git commit --allow-empty -m foo -s &&
239 git commit --allow-empty --amend --no-edit -s &&
240 cat >expect <<-\EOF &&
241 2 C O Mitter <committer@example.com>
242 1 SOB One <sob@example.com>
244 git shortlog -nse --group=trailer:signed-off-by HEAD >actual &&
245 test_cmp expect actual
248 test_expect_success 'shortlog --group=format' '
249 git shortlog -s --date="format:%Y" --group="format:%cN (%cd)" \
250 HEAD >actual &&
251 cat >expect <<-\EOF &&
252 4 C O Mitter (2005)
253 1 Sin Nombre (2005)
255 test_cmp expect actual
258 test_expect_success 'shortlog --group=<format> DWIM' '
259 git shortlog -s --date="format:%Y" --group="%cN (%cd)" HEAD >actual &&
260 test_cmp expect actual
263 test_expect_success 'shortlog bogus --group' '
264 test_must_fail git shortlog --group=bogus HEAD 2>err &&
265 grep "unknown group type" err
268 test_expect_success 'trailer idents are split' '
269 cat >expect <<-\EOF &&
270 2 C O Mitter
271 1 SOB One
273 git shortlog -ns --group=trailer:signed-off-by HEAD >actual &&
274 test_cmp expect actual
277 test_expect_success 'trailer idents are mailmapped' '
278 cat >expect <<-\EOF &&
279 2 C O Mitter
280 1 Another Name
282 echo "Another Name <sob@example.com>" >mail.map &&
283 git -c mailmap.file=mail.map shortlog -ns \
284 --group=trailer:signed-off-by HEAD >actual &&
285 test_cmp expect actual
288 test_expect_success 'shortlog de-duplicates trailers in a single commit' '
289 git commit --allow-empty -F - <<-\EOF &&
290 subject one
292 this message has two distinct values, plus a repeat
294 Repeated-trailer: Foo
295 Repeated-trailer: Bar
296 Repeated-trailer: Foo
299 git commit --allow-empty -F - <<-\EOF &&
300 subject two
302 similar to the previous, but without the second distinct value
304 Repeated-trailer: Foo
305 Repeated-trailer: Foo
308 cat >expect <<-\EOF &&
309 2 Foo
310 1 Bar
312 git shortlog -ns --group=trailer:repeated-trailer -2 HEAD >actual &&
313 test_cmp expect actual
316 # Trailers that have unfolded (single line) and folded (multiline) values which
317 # are otherwise identical are treated as the same trailer for de-duplication.
318 test_expect_success 'shortlog de-duplicates trailers in a single commit (folded/unfolded values)' '
319 git commit --allow-empty -F - <<-\EOF &&
320 subject one
322 this message has two distinct values, plus a repeat (folded)
324 Repeated-trailer: Foo foo foo
325 Repeated-trailer: Bar
326 Repeated-trailer: Foo
327 foo foo
330 git commit --allow-empty -F - <<-\EOF &&
331 subject two
333 similar to the previous, but without the second distinct value
335 Repeated-trailer: Foo foo foo
336 Repeated-trailer: Foo
337 foo foo
340 cat >expect <<-\EOF &&
341 2 Foo foo foo
342 1 Bar
344 git shortlog -ns --group=trailer:repeated-trailer -2 HEAD >actual &&
345 test_cmp expect actual
348 test_expect_success 'shortlog can match multiple groups' '
349 git commit --allow-empty -F - <<-\EOF &&
350 subject one
352 this has two trailers that are distinct from the author; it will count
353 3 times in the output
355 Some-trailer: User A <a@example.com>
356 Another-trailer: User B <b@example.com>
359 git commit --allow-empty -F - <<-\EOF &&
360 subject two
362 this one has two trailers, one of which is a duplicate with the author;
363 it will only be counted once for them
365 Another-trailer: A U Thor <author@example.com>
366 Some-trailer: User B <b@example.com>
369 cat >expect <<-\EOF &&
370 2 A U Thor
371 2 User B
372 1 User A
374 git shortlog -ns \
375 --group=author \
376 --group=trailer:some-trailer \
377 --group=trailer:another-trailer \
378 -2 HEAD >actual &&
379 test_cmp expect actual
382 test_expect_success 'shortlog can match multiple format groups' '
383 GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" \
384 git commit --allow-empty -m "identical names" &&
385 test_tick &&
386 cat >expect <<-\EOF &&
387 2 A U Thor
388 1 C O Mitter
390 git shortlog -ns --group="%cn" --group="%an" -2 HEAD >actual &&
391 test_cmp expect actual
394 test_expect_success 'set up option selection tests' '
395 git commit --allow-empty -F - <<-\EOF
396 subject
398 body
400 Trailer-one: value-one
401 Trailer-two: value-two
405 test_expect_success '--no-group resets group list to author' '
406 cat >expect <<-\EOF &&
407 1 A U Thor
409 git shortlog -ns \
410 --group=committer \
411 --group=trailer:trailer-one \
412 --no-group \
413 -1 HEAD >actual &&
414 test_cmp expect actual
417 test_expect_success '--no-group resets trailer list' '
418 cat >expect <<-\EOF &&
419 1 value-two
421 git shortlog -ns \
422 --group=trailer:trailer-one \
423 --no-group \
424 --group=trailer:trailer-two \
425 -1 HEAD >actual &&
426 test_cmp expect actual
429 test_expect_success 'stdin with multiple groups reports error' '
430 git log >log &&
431 test_must_fail git shortlog --group=author --group=committer <log
434 test_done