t7800: improve test descriptions with empty arguments
[alt-git.git] / t / t4201-shortlog.sh
blobd7382709fc11055be003751d802f953ed56b6eab
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-lib.sh
14 test_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" &&
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 &&
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 &&
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 &&
41 echo 5 >a1 &&
42 git commit --quiet -m "a 12 34 56 78" a1 &&
44 echo 6 >a1 &&
45 git commit --quiet -m "Commit by someone else" \
46 --author="Someone else <not!me>" a1 &&
48 cat >expect.template <<-\EOF
49 A U Thor (5):
50 SUBJECT
51 SUBJECT
52 SUBJECT
53 SUBJECT
54 SUBJECT
56 Someone else (1):
57 SUBJECT
59 EOF
62 fuzz() {
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"
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 &&
109 A 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
120 Someone else (1):
121 Commit by someone else
124 git shortlog -w HEAD >out &&
125 test_cmp expect 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 &&
131 test_cmp expect 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 &&
137 test_cmp expect 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 &&
147 A U Thor (2):
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
166 test_cmp expect out
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: áæï"
177 cat > expect << EOF
178 $DSCHO (2):
179 $MSG1
180 $MSG2
184 test_expect_success !MINGW 'shortlog encoding' '
185 git reset --hard "$commit" &&
186 git config --unset i18n.commitencoding &&
187 echo 2 > a1 &&
188 git commit --quiet -m "$MSG1" --author="$DSCHOE" a1 &&
189 git config i18n.commitencoding "ISO8859-1" &&
190 echo 3 > a1 &&
191 git commit --quiet -m "$(iconvfromutf8toiso88591 "$MSG2")" \
192 --author="$(iconvfromutf8toiso88591 "$DSCHOE")" a1 &&
193 git config --unset i18n.commitencoding &&
194 git shortlog HEAD~2.. > out &&
195 test_cmp expect 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 &&
216 2 C O Mitter
217 1 Sin Nombre
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)" \
249 HEAD >actual &&
250 cat >expect <<-\EOF &&
251 4 C O Mitter (2005)
252 1 Sin Nombre (2005)
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 &&
269 2 C O Mitter
270 1 SOB One
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 &&
278 2 C O Mitter
279 1 Another Name
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 &&
289 subject one
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 &&
299 subject two
301 similar to the previous, but without the second distinct value
303 Repeated-trailer: Foo
304 Repeated-trailer: Foo
307 cat >expect <<-\EOF &&
308 2 Foo
309 1 Bar
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 &&
317 subject one
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 &&
327 subject two
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 &&
337 2 A U Thor
338 2 User B
339 1 User A
341 git shortlog -ns \
342 --group=author \
343 --group=trailer:some-trailer \
344 --group=trailer:another-trailer \
345 -2 HEAD >actual &&
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" &&
352 test_tick &&
353 cat >expect <<-\EOF &&
354 2 A U Thor
355 1 C O Mitter
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
363 subject
365 body
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 &&
374 1 A U Thor
376 git shortlog -ns \
377 --group=committer \
378 --group=trailer:trailer-one \
379 --no-group \
380 -1 HEAD >actual &&
381 test_cmp expect actual
384 test_expect_success '--no-group resets trailer list' '
385 cat >expect <<-\EOF &&
386 1 value-two
388 git shortlog -ns \
389 --group=trailer:trailer-one \
390 --no-group \
391 --group=trailer:trailer-two \
392 -1 HEAD >actual &&
393 test_cmp expect actual
396 test_expect_success 'stdin with multiple groups reports error' '
397 git log >log &&
398 test_must_fail git shortlog --group=author --group=committer <log
401 test_done