archive: support compression levels beyond 9
[git/debian.git] / t / t4201-shortlog.sh
blob3d5c4a2086afbaa5f5ae275c957efb6ee809953b
1 #!/bin/sh
3 # Copyright (c) 2006 Johannes E. Schindelin
6 test_description='git shortlog
9 . ./test-lib.sh
11 test_expect_success 'setup' '
12 test_tick &&
13 echo 1 >a1 &&
14 git add a1 &&
15 tree=$(git write-tree) &&
16 commit=$(printf "%s\n" "Test" "" | git commit-tree "$tree") &&
17 git update-ref HEAD "$commit" &&
19 echo 2 >a1 &&
20 git commit --quiet -m "This is a very, very long first line for the commit message to see if it is wrapped correctly" a1 &&
22 # test if the wrapping is still valid
23 # when replacing all is by treble clefs.
24 echo 3 >a1 &&
25 git commit --quiet -m "$(
26 echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" |
27 sed "s/i/1234/g" |
28 tr 1234 "\360\235\204\236")" a1 &&
30 # now fsck up the utf8
31 git config i18n.commitencoding non-utf-8 &&
32 echo 4 >a1 &&
33 git commit --quiet -m "$(
34 echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" |
35 sed "s/i/1234/g" |
36 tr 1234 "\370\235\204\236")" a1 &&
38 echo 5 >a1 &&
39 git commit --quiet -m "a 12 34 56 78" a1 &&
41 echo 6 >a1 &&
42 git commit --quiet -m "Commit by someone else" \
43 --author="Someone else <not!me>" a1 &&
45 cat >expect.template <<-\EOF
46 A U Thor (5):
47 SUBJECT
48 SUBJECT
49 SUBJECT
50 SUBJECT
51 SUBJECT
53 Someone else (1):
54 SUBJECT
56 EOF
59 fuzz() {
60 file=$1 &&
61 sed "
62 s/$OID_REGEX/OBJECT_NAME/g
63 s/$_x35/OBJID/g
64 s/^ \{6\}[CTa].*/ SUBJECT/g
65 s/^ \{8\}[^ ].*/ CONTINUATION/g
66 " <"$file" >"$file.fuzzy" &&
67 sed "/CONTINUATION/ d" <"$file.fuzzy"
70 test_expect_success 'default output format' '
71 git shortlog HEAD >log &&
72 fuzz log >log.predictable &&
73 test_cmp expect.template log.predictable
76 test_expect_success 'pretty format' '
77 sed s/SUBJECT/OBJECT_NAME/ expect.template >expect &&
78 git shortlog --format="%H" HEAD >log &&
79 fuzz log >log.predictable &&
80 test_cmp expect log.predictable
83 test_expect_success '--abbrev' '
84 sed s/SUBJECT/OBJID/ expect.template >expect &&
85 git shortlog --format="%h" --abbrev=35 HEAD >log &&
86 fuzz log >log.predictable &&
87 test_cmp expect log.predictable
90 test_expect_success 'output from user-defined format is re-wrapped' '
91 sed "s/SUBJECT/two lines/" expect.template >expect &&
92 git shortlog --format="two%nlines" HEAD >log &&
93 fuzz log >log.predictable &&
94 test_cmp expect log.predictable
97 test_expect_success !MINGW 'shortlog wrapping' '
98 cat >expect <<\EOF &&
99 A U Thor (5):
100 Test
101 This is a very, very long first line for the commit message to see if
102 it is wrapped correctly
103 Th𝄞s 𝄞s a very, very long f𝄞rst l𝄞ne for the comm𝄞t message to see 𝄞f
104 𝄞t 𝄞s wrapped correctly
105 Thø�„žs ø�„žs a very, very long fø�„žrst lø�„žne for the commø�„žt
106 message to see ø�„žf ø�„žt ø�„žs wrapped correctly
107 a 12 34
108 56 78
110 Someone else (1):
111 Commit by someone else
114 git shortlog -w HEAD >out &&
115 test_cmp expect out
118 test_expect_success !MINGW 'shortlog from non-git directory' '
119 git log --no-expand-tabs HEAD >log &&
120 GIT_DIR=non-existing git shortlog -w <log >out &&
121 test_cmp expect out
124 test_expect_success !MINGW 'shortlog can read --format=raw output' '
125 git log --format=raw HEAD >log &&
126 GIT_DIR=non-existing git shortlog -w <log >out &&
127 test_cmp expect out
130 test_expect_success 'shortlog from non-git directory refuses extra arguments' '
131 test_must_fail env GIT_DIR=non-existing git shortlog foo 2>out &&
132 test_i18ngrep "too many arguments" out
135 test_expect_success 'shortlog should add newline when input line matches wraplen' '
136 cat >expect <<\EOF &&
137 A U Thor (2):
138 bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
139 aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
142 git shortlog -w >out <<\EOF &&
143 commit 0000000000000000000000000000000000000001
144 Author: A U Thor <author@example.com>
145 Date: Thu Apr 7 15:14:13 2005 -0700
147 aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
149 commit 0000000000000000000000000000000000000002
150 Author: A U Thor <author@example.com>
151 Date: Thu Apr 7 15:14:13 2005 -0700
153 bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
156 test_cmp expect out
159 iconvfromutf8toiso88591() {
160 printf "%s" "$*" | iconv -f UTF-8 -t ISO8859-1
163 DSCHO="Jöhännës \"Dschö\" Schindëlin"
164 DSCHOE="$DSCHO <Johannes.Schindelin@gmx.de>"
165 MSG1="set a1 to 2 and some non-ASCII chars: Äßø"
166 MSG2="set a1 to 3 and some non-ASCII chars: áæï"
167 cat > expect << EOF
168 $DSCHO (2):
169 $MSG1
170 $MSG2
174 test_expect_success !MINGW 'shortlog encoding' '
175 git reset --hard "$commit" &&
176 git config --unset i18n.commitencoding &&
177 echo 2 > a1 &&
178 git commit --quiet -m "$MSG1" --author="$DSCHOE" a1 &&
179 git config i18n.commitencoding "ISO8859-1" &&
180 echo 3 > a1 &&
181 git commit --quiet -m "$(iconvfromutf8toiso88591 "$MSG2")" \
182 --author="$(iconvfromutf8toiso88591 "$DSCHOE")" a1 &&
183 git config --unset i18n.commitencoding &&
184 git shortlog HEAD~2.. > out &&
185 test_cmp expect out'
187 test_expect_success 'shortlog with revision pseudo options' '
188 git shortlog --all &&
189 git shortlog --branches &&
190 git shortlog --exclude=refs/heads/m* --all
193 test_expect_success 'shortlog with --output=<file>' '
194 git shortlog --output=shortlog -1 master >output &&
195 test_must_be_empty output &&
196 test_line_count = 3 shortlog
199 test_expect_success 'shortlog --committer (internal)' '
200 git checkout --orphan side &&
201 git commit --allow-empty -m one &&
202 git commit --allow-empty -m two &&
203 GIT_COMMITTER_NAME="Sin Nombre" git commit --allow-empty -m three &&
205 cat >expect <<-\EOF &&
206 2 C O Mitter
207 1 Sin Nombre
209 git shortlog -nsc HEAD >actual &&
210 test_cmp expect actual
213 test_expect_success 'shortlog --committer (external)' '
214 git log --format=full | git shortlog -nsc >actual &&
215 test_cmp expect actual
218 test_expect_success '--group=committer is the same as --committer' '
219 git shortlog -ns --group=committer HEAD >actual &&
220 test_cmp expect actual
223 test_expect_success 'shortlog --group=trailer:signed-off-by' '
224 git commit --allow-empty -m foo -s &&
225 GIT_COMMITTER_NAME="SOB One" \
226 GIT_COMMITTER_EMAIL=sob@example.com \
227 git commit --allow-empty -m foo -s &&
228 git commit --allow-empty --amend --no-edit -s &&
229 cat >expect <<-\EOF &&
230 2 C O Mitter <committer@example.com>
231 1 SOB One <sob@example.com>
233 git shortlog -nse --group=trailer:signed-off-by HEAD >actual &&
234 test_cmp expect actual
237 test_expect_success 'trailer idents are split' '
238 cat >expect <<-\EOF &&
239 2 C O Mitter
240 1 SOB One
242 git shortlog -ns --group=trailer:signed-off-by HEAD >actual &&
243 test_cmp expect actual
246 test_expect_success 'trailer idents are mailmapped' '
247 cat >expect <<-\EOF &&
248 2 C O Mitter
249 1 Another Name
251 echo "Another Name <sob@example.com>" >mail.map &&
252 git -c mailmap.file=mail.map shortlog -ns \
253 --group=trailer:signed-off-by HEAD >actual &&
254 test_cmp expect actual
257 test_expect_success 'shortlog de-duplicates trailers in a single commit' '
258 git commit --allow-empty -F - <<-\EOF &&
259 subject one
261 this message has two distinct values, plus a repeat
263 Repeated-trailer: Foo
264 Repeated-trailer: Bar
265 Repeated-trailer: Foo
268 git commit --allow-empty -F - <<-\EOF &&
269 subject two
271 similar to the previous, but without the second distinct value
273 Repeated-trailer: Foo
274 Repeated-trailer: Foo
277 cat >expect <<-\EOF &&
278 2 Foo
279 1 Bar
281 git shortlog -ns --group=trailer:repeated-trailer -2 HEAD >actual &&
282 test_cmp expect actual
285 test_expect_success 'shortlog can match multiple groups' '
286 git commit --allow-empty -F - <<-\EOF &&
287 subject one
289 this has two trailers that are distinct from the author; it will count
290 3 times in the output
292 Some-trailer: User A <a@example.com>
293 Another-trailer: User B <b@example.com>
296 git commit --allow-empty -F - <<-\EOF &&
297 subject two
299 this one has two trailers, one of which is a duplicate with the author;
300 it will only be counted once for them
302 Another-trailer: A U Thor <author@example.com>
303 Some-trailer: User B <b@example.com>
306 cat >expect <<-\EOF &&
307 2 A U Thor
308 2 User B
309 1 User A
311 git shortlog -ns \
312 --group=author \
313 --group=trailer:some-trailer \
314 --group=trailer:another-trailer \
315 -2 HEAD >actual &&
316 test_cmp expect actual
319 test_expect_success 'set up option selection tests' '
320 git commit --allow-empty -F - <<-\EOF
321 subject
323 body
325 Trailer-one: value-one
326 Trailer-two: value-two
330 test_expect_success '--no-group resets group list to author' '
331 cat >expect <<-\EOF &&
332 1 A U Thor
334 git shortlog -ns \
335 --group=committer \
336 --group=trailer:trailer-one \
337 --no-group \
338 -1 HEAD >actual &&
339 test_cmp expect actual
342 test_expect_success '--no-group resets trailer list' '
343 cat >expect <<-\EOF &&
344 1 value-two
346 git shortlog -ns \
347 --group=trailer:trailer-one \
348 --no-group \
349 --group=trailer:trailer-two \
350 -1 HEAD >actual &&
351 test_cmp expect actual
354 test_expect_success 'stdin with multiple groups reports error' '
355 git log >log &&
356 test_must_fail git shortlog --group=author --group=committer <log
359 test_done