]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4205-log-pretty-formats.sh
t4041, t4205, t6006, t7102: don't hardcode tested encoding value
[thirdparty/git.git] / t / t4205-log-pretty-formats.sh
CommitLineData
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
7test_description='Test pretty formats'
8. ./test-lib.sh
9
ee3efaf6
AS
10# Tested non-UTF-8 encoding
11test_encoding="ISO8859-1"
12
37eb772e
AS
13sample_utf8_part=$(printf "f\303\244ng")
14
de6029a2 15commit_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
28test_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
41test_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
48test_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
55test_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
62test_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 70test_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
76test_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 83test_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
88test_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
95test_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
103test_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 109test_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 115test_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 121test_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
129test_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
137test_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
146test_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
151message two Z
152message one Z
153add bar Z
de6029a2 154$(commit_msg) Z
a5752342
NTND
155EOF
156 test_cmp expected actual
f3445f78 157'
a5752342 158
f3445f78
AS
159test_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
168EOF
169 test_cmp expected actual
f3445f78 170'
a5752342 171
f3445f78
AS
172test_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
177message two
178message one
179add bar
de6029a2 180$(commit_msg)
a5752342
NTND
181EOF
182 test_cmp expected actual
f3445f78 183'
a5752342 184
f3445f78
AS
185test_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
190message ..
191message ..
192add bar Z
37eb772e 193initial...
a7f01c6b
NTND
194EOF
195 test_cmp expected actual
f3445f78 196'
a7f01c6b 197
f3445f78
AS
198test_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
205add bar Z
37eb772e 206..${sample_utf8_part}lich
a7f01c6b
NTND
207EOF
208 test_cmp expected actual
f3445f78 209'
a7f01c6b 210
f3445f78
AS
211test_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
216mess.. two
217mess.. one
218add bar Z
37eb772e 219init..lich
a7f01c6b
NTND
220EOF
221 test_cmp expected actual
f3445f78 222'
a7f01c6b 223
f3445f78
AS
224test_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
229Z message two
230Z message one
231Z add bar
de6029a2 232Z $(commit_msg)
a5752342
NTND
233EOF
234 test_cmp expected actual
f3445f78 235'
a5752342 236
f3445f78
AS
237test_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
246EOF
247 test_cmp expected actual
f3445f78 248'
a5752342 249
f3445f78
AS
250test_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
255message two
256message one
257add bar
de6029a2 258$(commit_msg)
a5752342
NTND
259EOF
260 test_cmp expected actual
f3445f78 261'
a5752342 262
f3445f78
AS
263test_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
268Z message two Z
269Z message one Z
270Z add bar Z
de6029a2 271Z $(commit_msg) Z
a5752342
NTND
272EOF
273 test_cmp expected actual
f3445f78 274'
a5752342 275
f3445f78
AS
276test_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
285EOF
286 test_cmp expected actual
f3445f78 287'
a5752342 288
f3445f78
AS
289test_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
294message two
295message one
296add bar
de6029a2 297$(commit_msg)
a5752342
NTND
298EOF
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
304old_head1=$(git rev-parse --verify HEAD~0)
305
f3445f78
AS
306test_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
312short long long long
313message .. A U Thor
314add bar A U Thor
37eb772e 315initial... A U Thor
1640632b
NTND
316EOF
317 test_cmp expected actual
f3445f78 318'
1640632b 319
496a6980
AS
320# get new digests (with no abbreviations)
321head1=$(git rev-parse --verify HEAD~0) &&
322head2=$(git rev-parse --verify HEAD~1) &&
323
5e1361cc 324test_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 334EOF
335 sort actual >actual1 &&
336 test_cmp expected actual1
337'
338
8028184e 339test_done