3 # Copyright (c) 2010, Will Palmer
4 # Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests)
7 test_description
='Test pretty formats'
11 # String "initial. initial" partly in German (translated with Google Translate),
12 # encoded in UTF-8, used as a commit log message below.
13 msg
=$
(printf "initial. anf\303\244nglich")
16 msg
=$
(echo $msg |
iconv -f utf-8
-t $1)
18 if test -n "$2" -a -n "$3"
20 # cut string, replace cut part with two dots
21 # $2 - chars count from the beginning of the string
22 # $3 - "trailing" chars
23 # LC_ALL is set to make `sed` interpret "." as a UTF-8 char not a byte
24 # as it does with C locale
25 msg
=$
(echo $msg | LC_ALL
=en_US.UTF-8
sed -e "s/^\(.\{$2\}\)$3/\1../")
30 test_expect_success
'set up basic repos' '
35 git config i18n.commitEncoding iso-8859-1 &&
36 git commit -m "$(commit_msg iso-8859-1)" &&
39 git commit -m "add bar" &&
40 git config --unset i18n.commitEncoding
43 test_expect_success
'alias builtin format' '
44 git log --pretty=oneline >expected &&
45 git config pretty.test-alias oneline &&
46 git log --pretty=test-alias >actual &&
47 test_cmp expected actual
50 test_expect_success
'alias masking builtin format' '
51 git log --pretty=oneline >expected &&
52 git config pretty.oneline "%H" &&
53 git log --pretty=oneline >actual &&
54 test_cmp expected actual
57 test_expect_success
'alias user-defined format' '
58 git log --pretty="format:%h" >expected &&
59 git config pretty.test-alias "format:%h" &&
60 git log --pretty=test-alias >actual &&
61 test_cmp expected actual
64 test_expect_success
'alias user-defined tformat with %s (iso-8859-1 encoding)' '
65 git config i18n.logOutputEncoding iso-8859-1 &&
66 git log --oneline >expected-s &&
67 git log --pretty="tformat:%h %s" >actual-s &&
68 git config --unset i18n.logOutputEncoding &&
69 test_cmp expected-s actual-s
72 test_expect_success
'alias user-defined tformat with %s (utf-8 encoding)' '
73 git log --oneline >expected-s &&
74 git log --pretty="tformat:%h %s" >actual-s &&
75 test_cmp expected-s actual-s
78 test_expect_success
'alias user-defined tformat' '
79 git log --pretty="tformat:%h" >expected &&
80 git config pretty.test-alias "tformat:%h" &&
81 git log --pretty=test-alias >actual &&
82 test_cmp expected actual
85 test_expect_success
'alias non-existent format' '
86 git config pretty.test-alias format-that-will-never-exist &&
87 test_must_fail git log --pretty=test-alias
90 test_expect_success
'alias of an alias' '
91 git log --pretty="tformat:%h" >expected &&
92 git config pretty.test-foo "tformat:%h" &&
93 git config pretty.test-bar test-foo &&
94 git log --pretty=test-bar >actual && test_cmp expected actual
97 test_expect_success
'alias masking an alias' '
98 git log --pretty=format:"Two %H" >expected &&
99 git config pretty.duplicate "format:One %H" &&
100 git config --add pretty.duplicate "format:Two %H" &&
101 git log --pretty=duplicate >actual &&
102 test_cmp expected actual
105 test_expect_success
'alias loop' '
106 git config pretty.test-foo test-bar &&
107 git config pretty.test-bar test-foo &&
108 test_must_fail git log --pretty=test-foo
111 test_expect_success
'NUL separation' '
112 printf "add bar\0$(commit_msg)" >expected &&
113 git log -z --pretty="format:%s" >actual &&
114 test_cmp expected actual
117 test_expect_success
'NUL termination' '
118 printf "add bar\0$(commit_msg)\0" >expected &&
119 git log -z --pretty="tformat:%s" >actual &&
120 test_cmp expected actual
123 test_expect_success
'NUL separation with --stat' '
124 stat0_part=$(git diff --stat HEAD^ HEAD) &&
125 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
126 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
127 git log -z --stat --pretty="format:%s" >actual &&
128 test_i18ncmp expected actual
131 test_expect_failure
'NUL termination with --stat' '
132 stat0_part=$(git diff --stat HEAD^ HEAD) &&
133 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
134 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected &&
135 git log -z --stat --pretty="tformat:%s" >actual &&
136 test_i18ncmp expected actual
139 test_expect_success
'setup more commits' '
140 test_commit "message one" one one message-one &&
141 test_commit "message two" two two message-two &&
142 head1=$(git rev-parse --verify --short HEAD~0) &&
143 head2=$(git rev-parse --verify --short HEAD~1) &&
144 head3=$(git rev-parse --verify --short HEAD~2) &&
145 head4=$(git rev-parse --verify --short HEAD~3)
148 test_expect_success
'left alignment formatting' "
149 git log --pretty='format:%<(40)%s' >actual &&
150 # complete the incomplete line at the end
152 qz_to_tab_space <<\EOF >expected &&
158 test_cmp expected actual
161 test_expect_success
'left alignment formatting at the nth column' "
162 git log --pretty='format:%h %<|(40)%s' >actual &&
163 # complete the incomplete line at the end
165 qz_to_tab_space <<\EOF >expected &&
169 $head4 $(commit_msg) Z
171 test_cmp expected actual
174 test_expect_success
'left alignment formatting with no padding' "
175 git log --pretty='format:%<(1)%s' >actual &&
176 # complete the incomplete line at the end
178 cat <<\EOF >expected &&
184 test_cmp expected actual
187 test_expect_success
'left alignment formatting with trunc' "
188 git log --pretty='format:%<(10,trunc)%s' >actual &&
189 # complete the incomplete line at the end
191 qz_to_tab_space <<\EOF >expected &&
195 $(commit_msg "" "8" "..
*$
")
197 test_cmp expected actual
200 test_expect_success
'left alignment formatting with ltrunc' "
201 git log --pretty='format:%<(10,ltrunc)%s' >actual &&
202 # complete the incomplete line at the end
204 qz_to_tab_space <<\EOF >expected &&
208 $(commit_msg "" "0" ".\
{11\
}")
210 test_cmp expected actual
213 test_expect_success
'left alignment formatting with mtrunc' "
214 git log --pretty='format:%<(10,mtrunc)%s' >actual &&
215 # complete the incomplete line at the end
217 qz_to_tab_space <<\EOF >expected &&
221 $(commit_msg "" "4" ".\
{11\
}")
223 test_cmp expected actual
226 test_expect_success
'right alignment formatting' "
227 git log --pretty='format:%>(40)%s' >actual &&
228 # complete the incomplete line at the end
230 qz_to_tab_space <<\EOF >expected &&
236 test_cmp expected actual
239 test_expect_success
'right alignment formatting at the nth column' "
240 git log --pretty='format:%h %>|(40)%s' >actual &&
241 # complete the incomplete line at the end
243 qz_to_tab_space <<\EOF >expected &&
249 test_cmp expected actual
252 test_expect_success
'right alignment formatting with no padding' "
253 git log --pretty='format:%>(1)%s' >actual &&
254 # complete the incomplete line at the end
256 cat <<\EOF >expected &&
262 test_cmp expected actual
265 test_expect_success
'center alignment formatting' "
266 git log --pretty='format:%><(40)%s' >actual &&
267 # complete the incomplete line at the end
269 qz_to_tab_space <<\EOF >expected &&
275 test_cmp expected actual
278 test_expect_success
'center alignment formatting at the nth column' "
279 git log --pretty='format:%h %><|(40)%s' >actual &&
280 # complete the incomplete line at the end
282 qz_to_tab_space <<\EOF >expected &&
286 $head4 $(commit_msg) Z
288 test_cmp expected actual
291 test_expect_success
'center alignment formatting with no padding' "
292 git log --pretty='format:%><(1)%s' >actual &&
293 # complete the incomplete line at the end
295 cat <<\EOF >expected &&
301 test_cmp expected actual
304 test_expect_success
'left/right alignment formatting with stealing' "
305 git commit --amend -m short --author 'long long long <long@me.com>' &&
306 git log --pretty='format:%<(10,trunc)%s%>>(10,ltrunc)% an' >actual &&
307 # complete the incomplete line at the end
309 cat <<\EOF >expected &&
313 $(commit_msg "" "8" "..
*$
") A U Thor
315 test_cmp expected actual