tests: mark tests relying on the current default for `init.defaultBranch`
[alt-git.git] / t / t4201-shortlog.sh
blobad6d3eebe5cf45acee057fce84bd1bf623cd4ab9
1 #!/bin/sh
3 # Copyright (c) 2006 Johannes E. Schindelin
6 test_description='git shortlog
9 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
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 '--abbrev' '
87 sed s/SUBJECT/OBJID/ expect.template >expect &&
88 git shortlog --format="%h" --abbrev=35 HEAD >log &&
89 fuzz log >log.predictable &&
90 test_cmp expect log.predictable
93 test_expect_success 'output from user-defined format is re-wrapped' '
94 sed "s/SUBJECT/two lines/" expect.template >expect &&
95 git shortlog --format="two%nlines" HEAD >log &&
96 fuzz log >log.predictable &&
97 test_cmp expect log.predictable
100 test_expect_success !MINGW 'shortlog wrapping' '
101 cat >expect <<\EOF &&
102 A U Thor (5):
103 Test
104 This is a very, very long first line for the commit message to see if
105 it is wrapped correctly
106 Th𝄞s 𝄞s a very, very long f𝄞rst l𝄞ne for the comm𝄞t message to see 𝄞f
107 𝄞t 𝄞s wrapped correctly
108 Thø�„žs ø�„žs a very, very long fø�„žrst lø�„žne for the commø�„žt
109 message to see ø�„žf ø�„žt ø�„žs wrapped correctly
110 a 12 34
111 56 78
113 Someone else (1):
114 Commit by someone else
117 git shortlog -w HEAD >out &&
118 test_cmp expect out
121 test_expect_success !MINGW 'shortlog from non-git directory' '
122 git log --no-expand-tabs HEAD >log &&
123 GIT_DIR=non-existing git shortlog -w <log >out &&
124 test_cmp expect out
127 test_expect_success !MINGW 'shortlog can read --format=raw output' '
128 git log --format=raw HEAD >log &&
129 GIT_DIR=non-existing git shortlog -w <log >out &&
130 test_cmp expect out
133 test_expect_success 'shortlog from non-git directory refuses extra arguments' '
134 test_must_fail env GIT_DIR=non-existing git shortlog foo 2>out &&
135 test_i18ngrep "too many arguments" out
138 test_expect_success 'shortlog should add newline when input line matches wraplen' '
139 cat >expect <<\EOF &&
140 A U Thor (2):
141 bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
142 aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
145 git shortlog -w >out <<\EOF &&
146 commit 0000000000000000000000000000000000000001
147 Author: A U Thor <author@example.com>
148 Date: Thu Apr 7 15:14:13 2005 -0700
150 aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
152 commit 0000000000000000000000000000000000000002
153 Author: A U Thor <author@example.com>
154 Date: Thu Apr 7 15:14:13 2005 -0700
156 bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
159 test_cmp expect out
162 iconvfromutf8toiso88591() {
163 printf "%s" "$*" | iconv -f UTF-8 -t ISO8859-1
166 DSCHO="Jöhännës \"Dschö\" Schindëlin"
167 DSCHOE="$DSCHO <Johannes.Schindelin@gmx.de>"
168 MSG1="set a1 to 2 and some non-ASCII chars: Äßø"
169 MSG2="set a1 to 3 and some non-ASCII chars: áæï"
170 cat > expect << EOF
171 $DSCHO (2):
172 $MSG1
173 $MSG2
177 test_expect_success !MINGW 'shortlog encoding' '
178 git reset --hard "$commit" &&
179 git config --unset i18n.commitencoding &&
180 echo 2 > a1 &&
181 git commit --quiet -m "$MSG1" --author="$DSCHOE" a1 &&
182 git config i18n.commitencoding "ISO8859-1" &&
183 echo 3 > a1 &&
184 git commit --quiet -m "$(iconvfromutf8toiso88591 "$MSG2")" \
185 --author="$(iconvfromutf8toiso88591 "$DSCHOE")" a1 &&
186 git config --unset i18n.commitencoding &&
187 git shortlog HEAD~2.. > out &&
188 test_cmp expect out'
190 test_expect_success 'shortlog with revision pseudo options' '
191 git shortlog --all &&
192 git shortlog --branches &&
193 git shortlog --exclude=refs/heads/m* --all
196 test_expect_success 'shortlog with --output=<file>' '
197 git shortlog --output=shortlog -1 master >output &&
198 test_must_be_empty output &&
199 test_line_count = 3 shortlog
202 test_expect_success 'shortlog --committer (internal)' '
203 git checkout --orphan side &&
204 git commit --allow-empty -m one &&
205 git commit --allow-empty -m two &&
206 GIT_COMMITTER_NAME="Sin Nombre" git commit --allow-empty -m three &&
208 cat >expect <<-\EOF &&
209 2 C O Mitter
210 1 Sin Nombre
212 git shortlog -nsc HEAD >actual &&
213 test_cmp expect actual
216 test_expect_success 'shortlog --committer (external)' '
217 git log --format=full | git shortlog -nsc >actual &&
218 test_cmp expect actual
221 test_expect_success '--group=committer is the same as --committer' '
222 git shortlog -ns --group=committer HEAD >actual &&
223 test_cmp expect actual
226 test_expect_success 'shortlog --group=trailer:signed-off-by' '
227 git commit --allow-empty -m foo -s &&
228 GIT_COMMITTER_NAME="SOB One" \
229 GIT_COMMITTER_EMAIL=sob@example.com \
230 git commit --allow-empty -m foo -s &&
231 git commit --allow-empty --amend --no-edit -s &&
232 cat >expect <<-\EOF &&
233 2 C O Mitter <committer@example.com>
234 1 SOB One <sob@example.com>
236 git shortlog -nse --group=trailer:signed-off-by HEAD >actual &&
237 test_cmp expect actual
240 test_expect_success 'trailer idents are split' '
241 cat >expect <<-\EOF &&
242 2 C O Mitter
243 1 SOB One
245 git shortlog -ns --group=trailer:signed-off-by HEAD >actual &&
246 test_cmp expect actual
249 test_expect_success 'trailer idents are mailmapped' '
250 cat >expect <<-\EOF &&
251 2 C O Mitter
252 1 Another Name
254 echo "Another Name <sob@example.com>" >mail.map &&
255 git -c mailmap.file=mail.map shortlog -ns \
256 --group=trailer:signed-off-by HEAD >actual &&
257 test_cmp expect actual
260 test_expect_success 'shortlog de-duplicates trailers in a single commit' '
261 git commit --allow-empty -F - <<-\EOF &&
262 subject one
264 this message has two distinct values, plus a repeat
266 Repeated-trailer: Foo
267 Repeated-trailer: Bar
268 Repeated-trailer: Foo
271 git commit --allow-empty -F - <<-\EOF &&
272 subject two
274 similar to the previous, but without the second distinct value
276 Repeated-trailer: Foo
277 Repeated-trailer: Foo
280 cat >expect <<-\EOF &&
281 2 Foo
282 1 Bar
284 git shortlog -ns --group=trailer:repeated-trailer -2 HEAD >actual &&
285 test_cmp expect actual
288 test_expect_success 'shortlog can match multiple groups' '
289 git commit --allow-empty -F - <<-\EOF &&
290 subject one
292 this has two trailers that are distinct from the author; it will count
293 3 times in the output
295 Some-trailer: User A <a@example.com>
296 Another-trailer: User B <b@example.com>
299 git commit --allow-empty -F - <<-\EOF &&
300 subject two
302 this one has two trailers, one of which is a duplicate with the author;
303 it will only be counted once for them
305 Another-trailer: A U Thor <author@example.com>
306 Some-trailer: User B <b@example.com>
309 cat >expect <<-\EOF &&
310 2 A U Thor
311 2 User B
312 1 User A
314 git shortlog -ns \
315 --group=author \
316 --group=trailer:some-trailer \
317 --group=trailer:another-trailer \
318 -2 HEAD >actual &&
319 test_cmp expect actual
322 test_expect_success 'set up option selection tests' '
323 git commit --allow-empty -F - <<-\EOF
324 subject
326 body
328 Trailer-one: value-one
329 Trailer-two: value-two
333 test_expect_success '--no-group resets group list to author' '
334 cat >expect <<-\EOF &&
335 1 A U Thor
337 git shortlog -ns \
338 --group=committer \
339 --group=trailer:trailer-one \
340 --no-group \
341 -1 HEAD >actual &&
342 test_cmp expect actual
345 test_expect_success '--no-group resets trailer list' '
346 cat >expect <<-\EOF &&
347 1 value-two
349 git shortlog -ns \
350 --group=trailer:trailer-one \
351 --no-group \
352 --group=trailer:trailer-two \
353 -1 HEAD >actual &&
354 test_cmp expect actual
357 test_expect_success 'stdin with multiple groups reports error' '
358 git log >log &&
359 test_must_fail git shortlog --group=author --group=committer <log
362 test_done