]>
git.ipfire.org Git - thirdparty/git.git/blob - t/t4205-log-pretty-formats.sh
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
12 # (translated with Google Translate),
13 # encoded in UTF-8, used as a commit log message below.
14 msg
=$
(printf "initial. anf\303\244nglich")
17 msg
=$
(echo $msg |
iconv -f utf-8
-t $1)
19 if test -n "$2" -a -n "$3"
21 # cut string, replace cut part with two dots
22 # $2 - chars count from the beginning of the string
23 # $3 - "trailing" chars
24 # LC_ALL is set to make `sed` interpret "." as a UTF-8 char not a byte
25 # as it does with C locale
26 msg
=$
(echo $msg | LC_ALL
=en_US.UTF-8
sed -e "s/^\(.\{$2\}\)$3/\1../")
31 test_expect_success
'set up basic repos' '
36 git config i18n.commitEncoding iso8859-1 &&
37 git commit -m "$(commit_msg iso8859-1)" &&
40 git commit -m "add bar" &&
41 git config --unset i18n.commitEncoding
44 test_expect_success
'alias builtin format' '
45 git log --pretty=oneline >expected &&
46 git config pretty.test-alias oneline &&
47 git log --pretty=test-alias >actual &&
48 test_cmp expected actual
51 test_expect_success
'alias masking builtin format' '
52 git log --pretty=oneline >expected &&
53 git config pretty.oneline "%H" &&
54 git log --pretty=oneline >actual &&
55 test_cmp expected actual
58 test_expect_success
'alias user-defined format' '
59 git log --pretty="format:%h" >expected &&
60 git config pretty.test-alias "format:%h" &&
61 git log --pretty=test-alias >actual &&
62 test_cmp expected actual
65 test_expect_success
'alias user-defined tformat with %s (iso8859-1 encoding)' '
66 git config i18n.logOutputEncoding iso8859-1 &&
67 git log --oneline >expected-s &&
68 git log --pretty="tformat:%h %s" >actual-s &&
69 git config --unset i18n.logOutputEncoding &&
70 test_cmp expected-s actual-s
73 test_expect_success
'alias user-defined tformat with %s (utf-8 encoding)' '
74 git log --oneline >expected-s &&
75 git log --pretty="tformat:%h %s" >actual-s &&
76 test_cmp expected-s actual-s
79 test_expect_success
'alias user-defined tformat' '
80 git log --pretty="tformat:%h" >expected &&
81 git config pretty.test-alias "tformat:%h" &&
82 git log --pretty=test-alias >actual &&
83 test_cmp expected actual
86 test_expect_success
'alias non-existent format' '
87 git config pretty.test-alias format-that-will-never-exist &&
88 test_must_fail git log --pretty=test-alias
91 test_expect_success
'alias of an alias' '
92 git log --pretty="tformat:%h" >expected &&
93 git config pretty.test-foo "tformat:%h" &&
94 git config pretty.test-bar test-foo &&
95 git log --pretty=test-bar >actual && test_cmp expected actual
98 test_expect_success
'alias masking an alias' '
99 git log --pretty=format:"Two %H" >expected &&
100 git config pretty.duplicate "format:One %H" &&
101 git config --add pretty.duplicate "format:Two %H" &&
102 git log --pretty=duplicate >actual &&
103 test_cmp expected actual
106 test_expect_success
'alias loop' '
107 git config pretty.test-foo test-bar &&
108 git config pretty.test-bar test-foo &&
109 test_must_fail git log --pretty=test-foo
112 test_expect_success
'NUL separation' '
113 printf "add bar\0$(commit_msg)" >expected &&
114 git log -z --pretty="format:%s" >actual &&
115 test_cmp expected actual
118 test_expect_success
'NUL termination' '
119 printf "add bar\0$(commit_msg)\0" >expected &&
120 git log -z --pretty="tformat:%s" >actual &&
121 test_cmp expected actual
124 test_expect_success
'NUL separation with --stat' '
125 stat0_part=$(git diff --stat HEAD^ HEAD) &&
126 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
127 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
128 git log -z --stat --pretty="format:%s" >actual &&
129 test_i18ncmp expected actual
132 test_expect_failure
'NUL termination with --stat' '
133 stat0_part=$(git diff --stat HEAD^ HEAD) &&
134 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
135 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected &&
136 git log -z --stat --pretty="tformat:%s" >actual &&
137 test_i18ncmp expected actual
140 test_expect_success
'setup more commits' '
141 test_commit "message one" one one message-one &&
142 test_commit "message two" two two message-two &&
143 head1=$(git rev-parse --verify --short HEAD~0) &&
144 head2=$(git rev-parse --verify --short HEAD~1) &&
145 head3=$(git rev-parse --verify --short HEAD~2) &&
146 head4=$(git rev-parse --verify --short HEAD~3)
149 test_expect_success
'left alignment formatting' '
150 git log --pretty="format:%<(40)%s" >actual &&
151 # complete the incomplete line at the end
153 qz_to_tab_space <<EOF >expected &&
159 test_cmp expected actual
162 test_expect_success
'left alignment formatting at the nth column' '
163 git log --pretty="format:%h %<|(40)%s" >actual &&
164 # complete the incomplete line at the end
166 qz_to_tab_space <<EOF >expected &&
170 $head4 $(commit_msg) Z
172 test_cmp expected actual
175 test_expect_success
'left alignment formatting with no padding' '
176 git log --pretty="format:%<(1)%s" >actual &&
177 # complete the incomplete line at the end
179 cat <<EOF >expected &&
185 test_cmp expected actual
188 test_expect_success
'left alignment formatting with trunc' '
189 git log --pretty="format:%<(10,trunc)%s" >actual &&
190 # complete the incomplete line at the end
192 qz_to_tab_space <<EOF >expected &&
196 $(commit_msg "" "8" "..*$")
198 test_cmp expected actual
201 test_expect_success
'left alignment formatting with ltrunc' '
202 git log --pretty="format:%<(10,ltrunc)%s" >actual &&
203 # complete the incomplete line at the end
205 qz_to_tab_space <<EOF >expected &&
209 $(commit_msg "" "0" ".\{11\}")
211 test_cmp expected actual
214 test_expect_success
'left alignment formatting with mtrunc' '
215 git log --pretty="format:%<(10,mtrunc)%s" >actual &&
216 # complete the incomplete line at the end
218 qz_to_tab_space <<EOF >expected &&
222 $(commit_msg "" "4" ".\{11\}")
224 test_cmp expected actual
227 test_expect_success
'right alignment formatting' '
228 git log --pretty="format:%>(40)%s" >actual &&
229 # complete the incomplete line at the end
231 qz_to_tab_space <<EOF >expected &&
237 test_cmp expected actual
240 test_expect_success
'right alignment formatting at the nth column' '
241 git log --pretty="format:%h %>|(40)%s" >actual &&
242 # complete the incomplete line at the end
244 qz_to_tab_space <<EOF >expected &&
250 test_cmp expected actual
253 test_expect_success
'right alignment formatting with no padding' '
254 git log --pretty="format:%>(1)%s" >actual &&
255 # complete the incomplete line at the end
257 cat <<EOF >expected &&
263 test_cmp expected actual
266 test_expect_success
'center alignment formatting' '
267 git log --pretty="format:%><(40)%s" >actual &&
268 # complete the incomplete line at the end
270 qz_to_tab_space <<EOF >expected &&
276 test_cmp expected actual
279 test_expect_success
'center alignment formatting at the nth column' '
280 git log --pretty="format:%h %><|(40)%s" >actual &&
281 # complete the incomplete line at the end
283 qz_to_tab_space <<EOF >expected &&
287 $head4 $(commit_msg) Z
289 test_cmp expected actual
292 test_expect_success
'center alignment formatting with no padding' '
293 git log --pretty="format:%><(1)%s" >actual &&
294 # complete the incomplete line at the end
296 cat <<EOF >expected &&
302 test_cmp expected actual
305 test_expect_success
'left/right alignment formatting with stealing' '
306 git commit --amend -m short --author "long long long <long@me.com>" &&
307 git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
308 # complete the incomplete line at the end
310 cat <<EOF >expected &&
314 $(commit_msg "" "8" "..*$") A U Thor
316 test_cmp expected actual