]>
Commit | Line | Data |
---|---|---|
8028184e WP |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2010, Will Palmer | |
de6029a2 | 4 | # Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests) |
8028184e WP |
5 | # |
6 | ||
7 | test_description='Test pretty formats' | |
8 | . ./test-lib.sh | |
9 | ||
ee3efaf6 AS |
10 | # Tested non-UTF-8 encoding |
11 | test_encoding="ISO8859-1" | |
12 | ||
37eb772e AS |
13 | sample_utf8_part=$(printf "f\303\244ng") |
14 | ||
de6029a2 | 15 | commit_msg () { |
17cc2ef1 AS |
16 | # String "initial. initial" partly in German |
17 | # (translated with Google Translate), | |
de6029a2 | 18 | # encoded in UTF-8, used as a commit log message below. |
37eb772e | 19 | msg="initial. an${sample_utf8_part}lich\n" |
de6029a2 AS |
20 | if test -n "$1" |
21 | then | |
37eb772e AS |
22 | printf "$msg" | iconv -f utf-8 -t "$1" |
23 | else | |
24 | printf "$msg" | |
de6029a2 | 25 | fi |
de6029a2 AS |
26 | } |
27 | ||
8028184e WP |
28 | test_expect_success 'set up basic repos' ' |
29 | >foo && | |
30 | >bar && | |
31 | git add foo && | |
32 | test_tick && | |
ee3efaf6 AS |
33 | git config i18n.commitEncoding $test_encoding && |
34 | git commit -m "$(commit_msg $test_encoding)" && | |
8028184e WP |
35 | git add bar && |
36 | test_tick && | |
de6029a2 AS |
37 | git commit -m "add bar" && |
38 | git config --unset i18n.commitEncoding | |
8028184e WP |
39 | ' |
40 | ||
41 | test_expect_success 'alias builtin format' ' | |
42 | git log --pretty=oneline >expected && | |
43 | git config pretty.test-alias oneline && | |
44 | git log --pretty=test-alias >actual && | |
45 | test_cmp expected actual | |
46 | ' | |
47 | ||
48 | test_expect_success 'alias masking builtin format' ' | |
49 | git log --pretty=oneline >expected && | |
50 | git config pretty.oneline "%H" && | |
51 | git log --pretty=oneline >actual && | |
52 | test_cmp expected actual | |
53 | ' | |
54 | ||
55 | test_expect_success 'alias user-defined format' ' | |
56 | git log --pretty="format:%h" >expected && | |
57 | git config pretty.test-alias "format:%h" && | |
58 | git log --pretty=test-alias >actual && | |
59 | test_cmp expected actual | |
60 | ' | |
61 | ||
ee3efaf6 AS |
62 | test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' ' |
63 | git config i18n.logOutputEncoding $test_encoding && | |
de6029a2 AS |
64 | git log --oneline >expected-s && |
65 | git log --pretty="tformat:%h %s" >actual-s && | |
66 | git config --unset i18n.logOutputEncoding && | |
67 | test_cmp expected-s actual-s | |
68 | ' | |
69 | ||
ecaee805 | 70 | test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' ' |
de6029a2 AS |
71 | git log --oneline >expected-s && |
72 | git log --pretty="tformat:%h %s" >actual-s && | |
73 | test_cmp expected-s actual-s | |
74 | ' | |
75 | ||
8028184e WP |
76 | test_expect_success 'alias user-defined tformat' ' |
77 | git log --pretty="tformat:%h" >expected && | |
78 | git config pretty.test-alias "tformat:%h" && | |
79 | git log --pretty=test-alias >actual && | |
80 | test_cmp expected actual | |
81 | ' | |
82 | ||
7be8b3ba | 83 | test_expect_success 'alias non-existent format' ' |
8028184e WP |
84 | git config pretty.test-alias format-that-will-never-exist && |
85 | test_must_fail git log --pretty=test-alias | |
86 | ' | |
87 | ||
88 | test_expect_success 'alias of an alias' ' | |
89 | git log --pretty="tformat:%h" >expected && | |
90 | git config pretty.test-foo "tformat:%h" && | |
91 | git config pretty.test-bar test-foo && | |
92 | git log --pretty=test-bar >actual && test_cmp expected actual | |
93 | ' | |
94 | ||
95 | test_expect_success 'alias masking an alias' ' | |
96 | git log --pretty=format:"Two %H" >expected && | |
97 | git config pretty.duplicate "format:One %H" && | |
98 | git config --add pretty.duplicate "format:Two %H" && | |
99 | git log --pretty=duplicate >actual && | |
100 | test_cmp expected actual | |
101 | ' | |
102 | ||
103 | test_expect_success 'alias loop' ' | |
104 | git config pretty.test-foo test-bar && | |
105 | git config pretty.test-bar test-foo && | |
106 | test_must_fail git log --pretty=test-foo | |
107 | ' | |
108 | ||
ecaee805 | 109 | test_expect_success 'NUL separation' ' |
de6029a2 | 110 | printf "add bar\0$(commit_msg)" >expected && |
3e065308 JK |
111 | git log -z --pretty="format:%s" >actual && |
112 | test_cmp expected actual | |
113 | ' | |
114 | ||
ecaee805 | 115 | test_expect_success 'NUL termination' ' |
de6029a2 | 116 | printf "add bar\0$(commit_msg)\0" >expected && |
3e065308 JK |
117 | git log -z --pretty="tformat:%s" >actual && |
118 | test_cmp expected actual | |
119 | ' | |
120 | ||
ecaee805 | 121 | test_expect_success 'NUL separation with --stat' ' |
fafd3829 | 122 | stat0_part=$(git diff --stat HEAD^ HEAD) && |
74faaa16 | 123 | stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) && |
de6029a2 | 124 | printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected && |
fafd3829 | 125 | git log -z --stat --pretty="format:%s" >actual && |
b354f11b | 126 | test_i18ncmp expected actual |
fafd3829 JH |
127 | ' |
128 | ||
129 | test_expect_failure 'NUL termination with --stat' ' | |
130 | stat0_part=$(git diff --stat HEAD^ HEAD) && | |
74faaa16 | 131 | stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) && |
de6029a2 | 132 | printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected && |
fafd3829 | 133 | git log -z --stat --pretty="tformat:%s" >actual && |
b354f11b | 134 | test_i18ncmp expected actual |
fafd3829 JH |
135 | ' |
136 | ||
a5752342 NTND |
137 | test_expect_success 'setup more commits' ' |
138 | test_commit "message one" one one message-one && | |
a742f2a0 AS |
139 | test_commit "message two" two two message-two && |
140 | head1=$(git rev-parse --verify --short HEAD~0) && | |
141 | head2=$(git rev-parse --verify --short HEAD~1) && | |
142 | head3=$(git rev-parse --verify --short HEAD~2) && | |
143 | head4=$(git rev-parse --verify --short HEAD~3) | |
a5752342 NTND |
144 | ' |
145 | ||
f3445f78 AS |
146 | test_expect_success 'left alignment formatting' ' |
147 | git log --pretty="format:%<(40)%s" >actual && | |
a5752342 NTND |
148 | # complete the incomplete line at the end |
149 | echo >>actual && | |
f3445f78 | 150 | qz_to_tab_space <<EOF >expected && |
a5752342 NTND |
151 | message two Z |
152 | message one Z | |
153 | add bar Z | |
de6029a2 | 154 | $(commit_msg) Z |
a5752342 NTND |
155 | EOF |
156 | test_cmp expected actual | |
f3445f78 | 157 | ' |
a5752342 | 158 | |
f3445f78 AS |
159 | test_expect_success 'left alignment formatting at the nth column' ' |
160 | git log --pretty="format:%h %<|(40)%s" >actual && | |
a5752342 NTND |
161 | # complete the incomplete line at the end |
162 | echo >>actual && | |
f3445f78 | 163 | qz_to_tab_space <<EOF >expected && |
a742f2a0 AS |
164 | $head1 message two Z |
165 | $head2 message one Z | |
166 | $head3 add bar Z | |
de6029a2 | 167 | $head4 $(commit_msg) Z |
a5752342 NTND |
168 | EOF |
169 | test_cmp expected actual | |
f3445f78 | 170 | ' |
a5752342 | 171 | |
f3445f78 AS |
172 | test_expect_success 'left alignment formatting with no padding' ' |
173 | git log --pretty="format:%<(1)%s" >actual && | |
a5752342 NTND |
174 | # complete the incomplete line at the end |
175 | echo >>actual && | |
f3445f78 | 176 | cat <<EOF >expected && |
a5752342 NTND |
177 | message two |
178 | message one | |
179 | add bar | |
de6029a2 | 180 | $(commit_msg) |
a5752342 NTND |
181 | EOF |
182 | test_cmp expected actual | |
f3445f78 | 183 | ' |
a5752342 | 184 | |
f3445f78 AS |
185 | test_expect_success 'left alignment formatting with trunc' ' |
186 | git log --pretty="format:%<(10,trunc)%s" >actual && | |
a7f01c6b NTND |
187 | # complete the incomplete line at the end |
188 | echo >>actual && | |
f3445f78 | 189 | qz_to_tab_space <<EOF >expected && |
a7f01c6b NTND |
190 | message .. |
191 | message .. | |
192 | add bar Z | |
37eb772e | 193 | initial... |
a7f01c6b NTND |
194 | EOF |
195 | test_cmp expected actual | |
f3445f78 | 196 | ' |
a7f01c6b | 197 | |
f3445f78 AS |
198 | test_expect_success 'left alignment formatting with ltrunc' ' |
199 | git log --pretty="format:%<(10,ltrunc)%s" >actual && | |
a7f01c6b NTND |
200 | # complete the incomplete line at the end |
201 | echo >>actual && | |
f3445f78 | 202 | qz_to_tab_space <<EOF >expected && |
a7f01c6b NTND |
203 | ..sage two |
204 | ..sage one | |
205 | add bar Z | |
37eb772e | 206 | ..${sample_utf8_part}lich |
a7f01c6b NTND |
207 | EOF |
208 | test_cmp expected actual | |
f3445f78 | 209 | ' |
a7f01c6b | 210 | |
f3445f78 AS |
211 | test_expect_success 'left alignment formatting with mtrunc' ' |
212 | git log --pretty="format:%<(10,mtrunc)%s" >actual && | |
a7f01c6b NTND |
213 | # complete the incomplete line at the end |
214 | echo >>actual && | |
f3445f78 | 215 | qz_to_tab_space <<EOF >expected && |
a7f01c6b NTND |
216 | mess.. two |
217 | mess.. one | |
218 | add bar Z | |
37eb772e | 219 | init..lich |
a7f01c6b NTND |
220 | EOF |
221 | test_cmp expected actual | |
f3445f78 | 222 | ' |
a7f01c6b | 223 | |
f3445f78 AS |
224 | test_expect_success 'right alignment formatting' ' |
225 | git log --pretty="format:%>(40)%s" >actual && | |
a5752342 NTND |
226 | # complete the incomplete line at the end |
227 | echo >>actual && | |
f3445f78 | 228 | qz_to_tab_space <<EOF >expected && |
a5752342 NTND |
229 | Z message two |
230 | Z message one | |
231 | Z add bar | |
de6029a2 | 232 | Z $(commit_msg) |
a5752342 NTND |
233 | EOF |
234 | test_cmp expected actual | |
f3445f78 | 235 | ' |
a5752342 | 236 | |
f3445f78 AS |
237 | test_expect_success 'right alignment formatting at the nth column' ' |
238 | git log --pretty="format:%h %>|(40)%s" >actual && | |
a5752342 NTND |
239 | # complete the incomplete line at the end |
240 | echo >>actual && | |
f3445f78 | 241 | qz_to_tab_space <<EOF >expected && |
a742f2a0 AS |
242 | $head1 message two |
243 | $head2 message one | |
244 | $head3 add bar | |
de6029a2 | 245 | $head4 $(commit_msg) |
a5752342 NTND |
246 | EOF |
247 | test_cmp expected actual | |
f3445f78 | 248 | ' |
a5752342 | 249 | |
f3445f78 AS |
250 | test_expect_success 'right alignment formatting with no padding' ' |
251 | git log --pretty="format:%>(1)%s" >actual && | |
a5752342 NTND |
252 | # complete the incomplete line at the end |
253 | echo >>actual && | |
f3445f78 | 254 | cat <<EOF >expected && |
a5752342 NTND |
255 | message two |
256 | message one | |
257 | add bar | |
de6029a2 | 258 | $(commit_msg) |
a5752342 NTND |
259 | EOF |
260 | test_cmp expected actual | |
f3445f78 | 261 | ' |
a5752342 | 262 | |
f3445f78 AS |
263 | test_expect_success 'center alignment formatting' ' |
264 | git log --pretty="format:%><(40)%s" >actual && | |
a5752342 NTND |
265 | # complete the incomplete line at the end |
266 | echo >>actual && | |
f3445f78 | 267 | qz_to_tab_space <<EOF >expected && |
a5752342 NTND |
268 | Z message two Z |
269 | Z message one Z | |
270 | Z add bar Z | |
de6029a2 | 271 | Z $(commit_msg) Z |
a5752342 NTND |
272 | EOF |
273 | test_cmp expected actual | |
f3445f78 | 274 | ' |
a5752342 | 275 | |
f3445f78 AS |
276 | test_expect_success 'center alignment formatting at the nth column' ' |
277 | git log --pretty="format:%h %><|(40)%s" >actual && | |
a5752342 NTND |
278 | # complete the incomplete line at the end |
279 | echo >>actual && | |
f3445f78 | 280 | qz_to_tab_space <<EOF >expected && |
a742f2a0 AS |
281 | $head1 message two Z |
282 | $head2 message one Z | |
283 | $head3 add bar Z | |
de6029a2 | 284 | $head4 $(commit_msg) Z |
a5752342 NTND |
285 | EOF |
286 | test_cmp expected actual | |
f3445f78 | 287 | ' |
a5752342 | 288 | |
f3445f78 AS |
289 | test_expect_success 'center alignment formatting with no padding' ' |
290 | git log --pretty="format:%><(1)%s" >actual && | |
a5752342 NTND |
291 | # complete the incomplete line at the end |
292 | echo >>actual && | |
f3445f78 | 293 | cat <<EOF >expected && |
a5752342 NTND |
294 | message two |
295 | message one | |
296 | add bar | |
de6029a2 | 297 | $(commit_msg) |
a5752342 NTND |
298 | EOF |
299 | test_cmp expected actual | |
f3445f78 | 300 | ' |
a5752342 | 301 | |
496a6980 AS |
302 | # save HEAD's SHA-1 digest (with no abbreviations) to use it below |
303 | # as far as the next test amends HEAD | |
304 | old_head1=$(git rev-parse --verify HEAD~0) | |
305 | ||
f3445f78 AS |
306 | test_expect_success 'left/right alignment formatting with stealing' ' |
307 | git commit --amend -m short --author "long long long <long@me.com>" && | |
308 | git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && | |
1640632b NTND |
309 | # complete the incomplete line at the end |
310 | echo >>actual && | |
f3445f78 | 311 | cat <<EOF >expected && |
1640632b NTND |
312 | short long long long |
313 | message .. A U Thor | |
314 | add bar A U Thor | |
37eb772e | 315 | initial... A U Thor |
1640632b NTND |
316 | EOF |
317 | test_cmp expected actual | |
f3445f78 | 318 | ' |
1640632b | 319 | |
496a6980 AS |
320 | # get new digests (with no abbreviations) |
321 | head1=$(git rev-parse --verify HEAD~0) && | |
322 | head2=$(git rev-parse --verify HEAD~1) && | |
323 | ||
5e1361cc | 324 | test_expect_success 'log decoration properly follows tag chain' ' |
325 | git tag -a tag1 -m tag1 && | |
326 | git tag -a tag2 -m tag2 tag1 && | |
327 | git tag -d tag1 && | |
328 | git commit --amend -m shorter && | |
329 | git log --no-walk --tags --pretty="%H %d" --decorate=full >actual && | |
330 | cat <<EOF >expected && | |
496a6980 AS |
331 | $head1 (tag: refs/tags/tag2) |
332 | $head2 (tag: refs/tags/message-one) | |
333 | $old_head1 (tag: refs/tags/message-two) | |
5e1361cc | 334 | EOF |
335 | sort actual >actual1 && | |
336 | test_cmp expected actual1 | |
337 | ' | |
338 | ||
8028184e | 339 | test_done |