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
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
'--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 &&
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
114 Commit by someone else
117 git shortlog -w HEAD >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 &&
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 &&
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 &&
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
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: áæï"
177 test_expect_success
!MINGW
'shortlog encoding' '
178 git reset --hard "$commit" &&
179 git config --unset i18n.commitencoding &&
181 git commit --quiet -m "$MSG1" --author="$DSCHOE" a1 &&
182 git config i18n.commitencoding "ISO8859-1" &&
184 git commit --quiet -m "$(iconvfromutf8toiso88591 "$MSG2")" \
185 --author="$(iconvfromutf8toiso88591 "$DSCHOE")" a1 &&
186 git config --unset i18n.commitencoding &&
187 git shortlog HEAD~2.. > 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 &&
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 &&
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 &&
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 &&
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 &&
274 similar to the previous, but without the second distinct value
276 Repeated-trailer: Foo
277 Repeated-trailer: Foo
280 cat >expect <<-\EOF &&
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 &&
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 &&
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 &&
316 --group=trailer:some-trailer \
317 --group=trailer:another-trailer \
319 test_cmp expect actual
322 test_expect_success
'set up option selection tests' '
323 git commit --allow-empty -F - <<-\EOF
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 &&
339 --group=trailer:trailer-one \
342 test_cmp expect actual
345 test_expect_success
'--no-group resets trailer list' '
346 cat >expect <<-\EOF &&
350 --group=trailer:trailer-one \
352 --group=trailer:trailer-two \
354 test_cmp expect actual
357 test_expect_success
'stdin with multiple groups reports error' '
359 test_must_fail git shortlog --group=author --group=committer <log