f5ea3f89324cbd62df3a678bed534b1c0c20b335
1#!/bin/sh
2#
3# Copyright (c) 2010, Will Palmer
4# Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests)
5#
6
7test_description='Test pretty formats'
8. ./test-lib.sh
9
10# Tested non-UTF-8 encoding
11test_encoding="ISO8859-1"
12
13sample_utf8_part=$(printf "f\303\244ng")
14
15commit_msg () {
16 # String "initial. initial" partly in German
17 # (translated with Google Translate),
18 # encoded in UTF-8, used as a commit log message below.
19 msg="initial. an${sample_utf8_part}lich\n"
20 if test -n "$1"
21 then
22 printf "$msg" | iconv -f utf-8 -t "$1"
23 else
24 printf "$msg"
25 fi
26}
27
28test_expect_success 'set up basic repos' '
29 >foo &&
30 >bar &&
31 git add foo &&
32 test_tick &&
33 git config i18n.commitEncoding $test_encoding &&
34 git commit -m "$(commit_msg $test_encoding)" &&
35 git add bar &&
36 test_tick &&
37 git commit -m "add bar" &&
38 git config --unset i18n.commitEncoding
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
62test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' '
63 git config i18n.logOutputEncoding $test_encoding &&
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
70test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
71 git log --oneline >expected-s &&
72 git log --pretty="tformat:%h %s" >actual-s &&
73 test_cmp expected-s actual-s
74'
75
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
83test_expect_success 'alias non-existent format' '
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
109test_expect_success 'NUL separation' '
110 printf "add bar\0$(commit_msg)" >expected &&
111 git log -z --pretty="format:%s" >actual &&
112 test_cmp expected actual
113'
114
115test_expect_success 'NUL termination' '
116 printf "add bar\0$(commit_msg)\0" >expected &&
117 git log -z --pretty="tformat:%s" >actual &&
118 test_cmp expected actual
119'
120
121test_expect_success 'NUL separation with --stat' '
122 stat0_part=$(git diff --stat HEAD^ HEAD) &&
123 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
124 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
125 git log -z --stat --pretty="format:%s" >actual &&
126 test_i18ncmp expected actual
127'
128
129test_expect_failure 'NUL termination with --stat' '
130 stat0_part=$(git diff --stat HEAD^ HEAD) &&
131 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
132 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected &&
133 git log -z --stat --pretty="tformat:%s" >actual &&
134 test_i18ncmp expected actual
135'
136
137test_expect_success 'setup more commits' '
138 test_commit "message one" one one message-one &&
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)
144'
145
146test_expect_success 'left alignment formatting' '
147 git log --pretty="format:%<(40)%s" >actual &&
148 # complete the incomplete line at the end
149 echo >>actual &&
150 qz_to_tab_space <<EOF >expected &&
151message two Z
152message one Z
153add bar Z
154$(commit_msg) Z
155EOF
156 test_cmp expected actual
157'
158
159test_expect_success 'left alignment formatting at the nth column' '
160 git log --pretty="format:%h %<|(40)%s" >actual &&
161 # complete the incomplete line at the end
162 echo >>actual &&
163 qz_to_tab_space <<EOF >expected &&
164$head1 message two Z
165$head2 message one Z
166$head3 add bar Z
167$head4 $(commit_msg) Z
168EOF
169 test_cmp expected actual
170'
171
172test_expect_success 'left alignment formatting with no padding' '
173 git log --pretty="format:%<(1)%s" >actual &&
174 # complete the incomplete line at the end
175 echo >>actual &&
176 cat <<EOF >expected &&
177message two
178message one
179add bar
180$(commit_msg)
181EOF
182 test_cmp expected actual
183'
184
185test_expect_success 'left alignment formatting with trunc' '
186 git log --pretty="format:%<(10,trunc)%s" >actual &&
187 # complete the incomplete line at the end
188 echo >>actual &&
189 qz_to_tab_space <<EOF >expected &&
190message ..
191message ..
192add bar Z
193initial...
194EOF
195 test_cmp expected actual
196'
197
198test_expect_success 'left alignment formatting with ltrunc' '
199 git log --pretty="format:%<(10,ltrunc)%s" >actual &&
200 # complete the incomplete line at the end
201 echo >>actual &&
202 qz_to_tab_space <<EOF >expected &&
203..sage two
204..sage one
205add bar Z
206..${sample_utf8_part}lich
207EOF
208 test_cmp expected actual
209'
210
211test_expect_success 'left alignment formatting with mtrunc' '
212 git log --pretty="format:%<(10,mtrunc)%s" >actual &&
213 # complete the incomplete line at the end
214 echo >>actual &&
215 qz_to_tab_space <<EOF >expected &&
216mess.. two
217mess.. one
218add bar Z
219init..lich
220EOF
221 test_cmp expected actual
222'
223
224test_expect_success 'right alignment formatting' '
225 git log --pretty="format:%>(40)%s" >actual &&
226 # complete the incomplete line at the end
227 echo >>actual &&
228 qz_to_tab_space <<EOF >expected &&
229Z message two
230Z message one
231Z add bar
232Z $(commit_msg)
233EOF
234 test_cmp expected actual
235'
236
237test_expect_success 'right alignment formatting at the nth column' '
238 git log --pretty="format:%h %>|(40)%s" >actual &&
239 # complete the incomplete line at the end
240 echo >>actual &&
241 qz_to_tab_space <<EOF >expected &&
242$head1 message two
243$head2 message one
244$head3 add bar
245$head4 $(commit_msg)
246EOF
247 test_cmp expected actual
248'
249
250test_expect_success 'right alignment formatting with no padding' '
251 git log --pretty="format:%>(1)%s" >actual &&
252 # complete the incomplete line at the end
253 echo >>actual &&
254 cat <<EOF >expected &&
255message two
256message one
257add bar
258$(commit_msg)
259EOF
260 test_cmp expected actual
261'
262
263test_expect_success 'center alignment formatting' '
264 git log --pretty="format:%><(40)%s" >actual &&
265 # complete the incomplete line at the end
266 echo >>actual &&
267 qz_to_tab_space <<EOF >expected &&
268Z message two Z
269Z message one Z
270Z add bar Z
271Z $(commit_msg) Z
272EOF
273 test_cmp expected actual
274'
275
276test_expect_success 'center alignment formatting at the nth column' '
277 git log --pretty="format:%h %><|(40)%s" >actual &&
278 # complete the incomplete line at the end
279 echo >>actual &&
280 qz_to_tab_space <<EOF >expected &&
281$head1 message two Z
282$head2 message one Z
283$head3 add bar Z
284$head4 $(commit_msg) Z
285EOF
286 test_cmp expected actual
287'
288
289test_expect_success 'center alignment formatting with no padding' '
290 git log --pretty="format:%><(1)%s" >actual &&
291 # complete the incomplete line at the end
292 echo >>actual &&
293 cat <<EOF >expected &&
294message two
295message one
296add bar
297$(commit_msg)
298EOF
299 test_cmp expected actual
300'
301
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
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 &&
309 # complete the incomplete line at the end
310 echo >>actual &&
311 cat <<EOF >expected &&
312short long long long
313message .. A U Thor
314add bar A U Thor
315initial... A U Thor
316EOF
317 test_cmp expected actual
318'
319
320# get new digests (with no abbreviations)
321head1=$(git rev-parse --verify HEAD~0) &&
322head2=$(git rev-parse --verify HEAD~1) &&
323
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 &&
331$head1 (tag: refs/tags/tag2)
332$head2 (tag: refs/tags/message-one)
333$old_head1 (tag: refs/tags/message-two)
334EOF
335 sort actual >actual1 &&
336 test_cmp expected actual1
337'
338
339test_done