Merge branch 'ek/alt-odb-entry-fix'
[git/mingw/j6t.git] / t / t4201-shortlog.sh
blob97fcb31d6eb516b195e9e26a8716dbf484fcc616
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 echo 1 >a1 &&
13 git add a1 &&
14 tree=$(git write-tree) &&
15 commit=$(printf "%s\n" "Test" "" | git commit-tree "$tree") &&
16 git update-ref HEAD "$commit" &&
18 echo 2 >a1 &&
19 git commit --quiet -m "This is a very, very long first line for the commit message to see if it is wrapped correctly" a1 &&
21 # test if the wrapping is still valid
22 # when replacing all is by treble clefs.
23 echo 3 >a1 &&
24 git commit --quiet -m "$(
25 echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" |
26 sed "s/i/1234/g" |
27 tr 1234 "\360\235\204\236")" a1 &&
29 # now fsck up the utf8
30 git config i18n.commitencoding non-utf-8 &&
31 echo 4 >a1 &&
32 git commit --quiet -m "$(
33 echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" |
34 sed "s/i/1234/g" |
35 tr 1234 "\370\235\204\236")" a1 &&
37 echo 5 >a1 &&
38 git commit --quiet -m "a 12 34 56 78" a1 &&
40 echo 6 >a1 &&
41 git commit --quiet -m "Commit by someone else" \
42 --author="Someone else <not!me>" a1 &&
44 cat >expect.template <<-\EOF
45 A U Thor (5):
46 SUBJECT
47 SUBJECT
48 SUBJECT
49 SUBJECT
50 SUBJECT
52 Someone else (1):
53 SUBJECT
55 EOF
58 fuzz() {
59 file=$1 &&
60 sed "
61 s/$_x40/OBJECT_NAME/g
62 s/$_x05/OBJID/g
63 s/^ \{6\}[CTa].*/ SUBJECT/g
64 s/^ \{8\}[^ ].*/ CONTINUATION/g
65 " <"$file" >"$file.fuzzy" &&
66 sed "/CONTINUATION/ d" <"$file.fuzzy"
69 test_expect_success 'default output format' '
70 git shortlog HEAD >log &&
71 fuzz log >log.predictable &&
72 test_cmp expect.template log.predictable
75 test_expect_success 'pretty format' '
76 sed s/SUBJECT/OBJECT_NAME/ expect.template >expect &&
77 git shortlog --format="%H" HEAD >log &&
78 fuzz log >log.predictable &&
79 test_cmp expect log.predictable
82 test_expect_success '--abbrev' '
83 sed s/SUBJECT/OBJID/ expect.template >expect &&
84 git shortlog --format="%h" --abbrev=5 HEAD >log &&
85 fuzz log >log.predictable &&
86 test_cmp expect log.predictable
89 test_expect_success 'output from user-defined format is re-wrapped' '
90 sed "s/SUBJECT/two lines/" expect.template >expect &&
91 git shortlog --format="two%nlines" HEAD >log &&
92 fuzz log >log.predictable &&
93 test_cmp expect log.predictable
96 test_expect_success 'shortlog wrapping' '
97 cat >expect <<\EOF &&
98 A U Thor (5):
99 Test
100 This is a very, very long first line for the commit message to see if
101 it is wrapped correctly
102 Th𝄞s 𝄞s a very, very long f𝄞rst l𝄞ne for the comm𝄞t message to see 𝄞f
103 𝄞t 𝄞s wrapped correctly
104 Thø�„žs ø�„žs a very, very long fø�„žrst lø�„žne for the commø�„žt
105 message to see ø�„žf ø�„žt ø�„žs wrapped correctly
106 a 12 34
107 56 78
109 Someone else (1):
110 Commit by someone else
113 git shortlog -w HEAD >out &&
114 test_cmp expect out
117 test_expect_success 'shortlog from non-git directory' '
118 git log HEAD >log &&
119 GIT_DIR=non-existing git shortlog -w <log >out &&
120 test_cmp expect out
123 test_expect_success 'shortlog should add newline when input line matches wraplen' '
124 cat >expect <<\EOF &&
125 A U Thor (2):
126 bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
127 aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
130 git shortlog -w >out <<\EOF &&
131 commit 0000000000000000000000000000000000000001
132 Author: A U Thor <author@example.com>
133 Date: Thu Apr 7 15:14:13 2005 -0700
135 aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
137 commit 0000000000000000000000000000000000000002
138 Author: A U Thor <author@example.com>
139 Date: Thu Apr 7 15:14:13 2005 -0700
141 bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
144 test_cmp expect out
147 iconvfromutf8toiso88591() {
148 printf "%s" "$*" | iconv -f UTF-8 -t ISO8859-1
151 DSCHO="Jöhännës \"Dschö\" Schindëlin"
152 DSCHOE="$DSCHO <Johannes.Schindelin@gmx.de>"
153 MSG1="set a1 to 2 and some non-ASCII chars: Äßø"
154 MSG2="set a1 to 3 and some non-ASCII chars: áæï"
155 cat > expect << EOF
156 $DSCHO (2):
157 $MSG1
158 $MSG2
162 test_expect_success 'shortlog encoding' '
163 git reset --hard "$commit" &&
164 git config --unset i18n.commitencoding &&
165 echo 2 > a1 &&
166 git commit --quiet -m "$MSG1" --author="$DSCHOE" a1 &&
167 git config i18n.commitencoding "ISO8859-1" &&
168 echo 3 > a1 &&
169 git commit --quiet -m "$(iconvfromutf8toiso88591 "$MSG2")" \
170 --author="$(iconvfromutf8toiso88591 "$DSCHOE")" a1 &&
171 git config --unset i18n.commitencoding &&
172 git shortlog HEAD~2.. > out &&
173 test_cmp expect out'
175 test_expect_success 'shortlog ignores commits with missing authors' '
176 git commit --allow-empty -m normal &&
177 git commit --allow-empty -m soon-to-be-broken &&
178 git cat-file commit HEAD >commit.tmp &&
179 sed "/^author/d" commit.tmp >broken.tmp &&
180 commit=$(git hash-object -w -t commit --stdin <broken.tmp) &&
181 git update-ref HEAD $commit &&
182 cat >expect <<-\EOF &&
183 A U Thor (1):
184 normal
187 git shortlog HEAD~2.. >actual &&
188 test_cmp expect actual
191 test_expect_success 'shortlog with revision pseudo options' '
192 git shortlog --all &&
193 git shortlog --branches &&
194 git shortlog --exclude=refs/heads/m* --all
197 test_done