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
15 test_expect_success
'setup' '
19 tree=$(git write-tree) &&
20 commit=$(printf "%s\n" "Test" "" | git commit-tree "$tree") &&
21 git update-ref HEAD "$commit" &&
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.
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" |
32 tr 1234 "\360\235\204\236")" a1 &&
34 # now fsck up the utf8
35 git config i18n.commitencoding non-utf-8 &&
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" |
40 tr 1234 "\370\235\204\236")" a1 &&
43 git commit --quiet -m "a 12 34 56 78" a1 &&
46 git commit --quiet -m "Commit by someone else" \
47 --author="Someone else <not!me>" a1 &&
49 cat >expect.template <<-\EOF
66 s/$OID_REGEX/OBJECT_NAME/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 &&
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
122 Commit by someone else
125 git shortlog -w HEAD >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 &&
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 &&
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 &&
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
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: áæï"
185 test_expect_success
!MINGW
'shortlog encoding' '
186 git reset --hard "$commit" &&
187 git config --unset i18n.commitencoding &&
189 git commit --quiet -m "$MSG1" --author="$DSCHOE" a1 &&
190 git config i18n.commitencoding "ISO8859-1" &&
192 git commit --quiet -m "$(iconvfromutf8toiso88591 "$MSG2")" \
193 --author="$(iconvfromutf8toiso88591 "$DSCHOE")" a1 &&
194 git config --unset i18n.commitencoding &&
195 git shortlog HEAD~2.. > 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 &&
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)" \
251 cat >expect <<-\EOF &&
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 &&
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 &&
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 &&
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 &&
302 similar to the previous, but without the second distinct value
304 Repeated-trailer: Foo
305 Repeated-trailer: Foo
308 cat >expect <<-\EOF &&
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 &&
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
330 git commit --allow-empty -F - <<-\EOF &&
333 similar to the previous, but without the second distinct value
335 Repeated-trailer: Foo foo foo
336 Repeated-trailer: Foo
340 cat >expect <<-\EOF &&
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 &&
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 &&
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 &&
376 --group=trailer:some-trailer \
377 --group=trailer:another-trailer \
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" &&
386 cat >expect <<-\EOF &&
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
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 &&
411 --group=trailer:trailer-one \
414 test_cmp expect actual
417 test_expect_success
'--no-group resets trailer list' '
418 cat >expect <<-\EOF &&
422 --group=trailer:trailer-one \
424 --group=trailer:trailer-two \
426 test_cmp expect actual
429 test_expect_success
'stdin with multiple groups reports error' '
431 test_must_fail git shortlog --group=author --group=committer <log