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
14 test_expect_success
'setup' '
18 tree=$(git write-tree) &&
19 commit=$(printf "%s\n" "Test" "" | git commit-tree "$tree") &&
20 git update-ref HEAD "$commit" &&
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 &&
25 # test if the wrapping is still valid
26 # when replacing all is by treble clefs.
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" |
31 tr 1234 "\360\235\204\236")" a1 &&
33 # now fsck up the utf8
34 git config i18n.commitencoding non-utf-8 &&
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" |
39 tr 1234 "\370\235\204\236")" a1 &&
42 git commit --quiet -m "a 12 34 56 78" a1 &&
45 git commit --quiet -m "Commit by someone else" \
46 --author="Someone else <not!me>" a1 &&
48 cat >expect.template <<-\EOF
65 s/$OID_REGEX/OBJECT_NAME/g
67 s/^ \{6\}[CTa].*/ SUBJECT/g
68 s/^ \{8\}[^ ].*/ CONTINUATION/g
69 " <"$file" >"$file.fuzzy" &&
70 sed "/CONTINUATION/ d" <"$file.fuzzy"
73 test_expect_success
'default output format' '
74 git shortlog HEAD >log &&
75 fuzz log >log.predictable &&
76 test_cmp expect.template log.predictable
79 test_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
86 test_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
93 test_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
100 test_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
107 test_expect_success
!MINGW
'shortlog wrapping' '
108 cat >expect <<\EOF &&
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
121 Commit by someone else
124 git shortlog -w HEAD >out &&
128 test_expect_success
!MINGW
'shortlog from non-git directory' '
129 git log --no-expand-tabs HEAD >log &&
130 GIT_DIR=non-existing git shortlog -w <log >out &&
134 test_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 &&
140 test_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
145 test_expect_success
'shortlog should add newline when input line matches wraplen' '
146 cat >expect <<\EOF &&
148 bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
149 aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
152 git shortlog -w >out <<\EOF &&
153 commit 0000000000000000000000000000000000000001
154 Author: A U Thor <author@example.com>
155 Date: Thu Apr 7 15:14:13 2005 -0700
157 aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
159 commit 0000000000000000000000000000000000000002
160 Author: A U Thor <author@example.com>
161 Date: Thu Apr 7 15:14:13 2005 -0700
163 bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
169 iconvfromutf8toiso88591
() {
170 printf "%s" "$*" |
iconv -f UTF-8
-t ISO8859-1
173 DSCHO
="Jöhännës \"Dschö\" Schindëlin"
174 DSCHOE
="$DSCHO <Johannes.Schindelin@gmx.de>"
175 MSG1
="set a1 to 2 and some non-ASCII chars: Äßø"
176 MSG2
="set a1 to 3 and some non-ASCII chars: áæï"
184 test_expect_success
!MINGW
'shortlog encoding' '
185 git reset --hard "$commit" &&
186 git config --unset i18n.commitencoding &&
188 git commit --quiet -m "$MSG1" --author="$DSCHOE" a1 &&
189 git config i18n.commitencoding "ISO8859-1" &&
191 git commit --quiet -m "$(iconvfromutf8toiso88591 "$MSG2")" \
192 --author="$(iconvfromutf8toiso88591 "$DSCHOE")" a1 &&
193 git config --unset i18n.commitencoding &&
194 git shortlog HEAD~2.. > out &&
197 test_expect_success
'shortlog with revision pseudo options' '
198 git shortlog --all &&
199 git shortlog --branches &&
200 git shortlog --exclude=refs/heads/m* --all
203 test_expect_success
'shortlog with --output=<file>' '
204 git shortlog --output=shortlog -1 main >output &&
205 test_must_be_empty output &&
206 test_line_count = 3 shortlog
209 test_expect_success
'shortlog --committer (internal)' '
210 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 &&
215 cat >expect <<-\EOF &&
219 git shortlog -nsc HEAD >actual &&
220 test_cmp expect actual
223 test_expect_success
'shortlog --committer (external)' '
224 git log --format=full | git shortlog -nsc >actual &&
225 test_cmp expect actual
228 test_expect_success
'--group=committer is the same as --committer' '
229 git shortlog -ns --group=committer HEAD >actual &&
230 test_cmp expect actual
233 test_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>
243 git shortlog -nse --group=trailer:signed-off-by HEAD >actual &&
244 test_cmp expect actual
247 test_expect_success
'shortlog --group=format' '
248 git shortlog -s --date="format:%Y" --group="format:%cN (%cd)" \
250 cat >expect <<-\EOF &&
254 test_cmp expect actual
257 test_expect_success
'shortlog --group=<format> DWIM' '
258 git shortlog -s --date="format:%Y" --group="%cN (%cd)" HEAD >actual &&
259 test_cmp expect actual
262 test_expect_success
'shortlog bogus --group' '
263 test_must_fail git shortlog --group=bogus HEAD 2>err &&
264 grep "unknown group type" err
267 test_expect_success
'trailer idents are split' '
268 cat >expect <<-\EOF &&
272 git shortlog -ns --group=trailer:signed-off-by HEAD >actual &&
273 test_cmp expect actual
276 test_expect_success
'trailer idents are mailmapped' '
277 cat >expect <<-\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
287 test_expect_success
'shortlog de-duplicates trailers in a single commit' '
288 git commit --allow-empty -F - <<-\EOF &&
291 this message has two distinct values, plus a repeat
293 Repeated-trailer: Foo
294 Repeated-trailer: Bar
295 Repeated-trailer: Foo
298 git commit --allow-empty -F - <<-\EOF &&
301 similar to the previous, but without the second distinct value
303 Repeated-trailer: Foo
304 Repeated-trailer: Foo
307 cat >expect <<-\EOF &&
311 git shortlog -ns --group=trailer:repeated-trailer -2 HEAD >actual &&
312 test_cmp expect actual
315 test_expect_success
'shortlog can match multiple groups' '
316 git commit --allow-empty -F - <<-\EOF &&
319 this has two trailers that are distinct from the author; it will count
320 3 times in the output
322 Some-trailer: User A <a@example.com>
323 Another-trailer: User B <b@example.com>
326 git commit --allow-empty -F - <<-\EOF &&
329 this one has two trailers, one of which is a duplicate with the author;
330 it will only be counted once for them
332 Another-trailer: A U Thor <author@example.com>
333 Some-trailer: User B <b@example.com>
336 cat >expect <<-\EOF &&
343 --group=trailer:some-trailer \
344 --group=trailer:another-trailer \
346 test_cmp expect actual
349 test_expect_success
'shortlog can match multiple format groups' '
350 GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" \
351 git commit --allow-empty -m "identical names" &&
353 cat >expect <<-\EOF &&
357 git shortlog -ns --group="%cn" --group="%an" -2 HEAD >actual &&
358 test_cmp expect actual
361 test_expect_success
'set up option selection tests' '
362 git commit --allow-empty -F - <<-\EOF
367 Trailer-one: value-one
368 Trailer-two: value-two
372 test_expect_success
'--no-group resets group list to author' '
373 cat >expect <<-\EOF &&
378 --group=trailer:trailer-one \
381 test_cmp expect actual
384 test_expect_success
'--no-group resets trailer list' '
385 cat >expect <<-\EOF &&
389 --group=trailer:trailer-one \
391 --group=trailer:trailer-two \
393 test_cmp expect actual
396 test_expect_success
'stdin with multiple groups reports error' '
398 test_must_fail git shortlog --group=author --group=committer <log