t4041, t4205, t6006, t7102: don't hardcode tested encoding value
[git/jrn.git] / t / t4205-log-pretty-formats.sh
blobf5ea3f89324cbd62df3a678bed534b1c0c20b335
1 #!/bin/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'
8 . ./test-lib.sh
10 # Tested non-UTF-8 encoding
11 test_encoding="ISO8859-1"
13 sample_utf8_part=$(printf "f\303\244ng")
15 commit_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"
28 test_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
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
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
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
62 test_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
70 test_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
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
83 test_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
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
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
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
109 test_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
115 test_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
121 test_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
129 test_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
137 test_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)
146 test_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 &&
151 message two Z
152 message one Z
153 add bar Z
154 $(commit_msg) Z
156 test_cmp expected actual
159 test_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
169 test_cmp expected actual
172 test_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 &&
177 message two
178 message one
179 add bar
180 $(commit_msg)
182 test_cmp expected actual
185 test_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 &&
190 message ..
191 message ..
192 add bar Z
193 initial...
195 test_cmp expected actual
198 test_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
205 add bar Z
206 ..${sample_utf8_part}lich
208 test_cmp expected actual
211 test_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 &&
216 mess.. two
217 mess.. one
218 add bar Z
219 init..lich
221 test_cmp expected actual
224 test_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 &&
229 Z message two
230 Z message one
231 Z add bar
232 Z $(commit_msg)
234 test_cmp expected actual
237 test_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)
247 test_cmp expected actual
250 test_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 &&
255 message two
256 message one
257 add bar
258 $(commit_msg)
260 test_cmp expected actual
263 test_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 &&
268 Z message two Z
269 Z message one Z
270 Z add bar Z
271 Z $(commit_msg) Z
273 test_cmp expected actual
276 test_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
286 test_cmp expected actual
289 test_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 &&
294 message two
295 message one
296 add bar
297 $(commit_msg)
299 test_cmp expected actual
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)
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 &&
309 # complete the incomplete line at the end
310 echo >>actual &&
311 cat <<EOF >expected &&
312 short long long long
313 message .. A U Thor
314 add bar A U Thor
315 initial... A U Thor
317 test_cmp expected actual
320 # get new digests (with no abbreviations)
321 head1=$(git rev-parse --verify HEAD~0) &&
322 head2=$(git rev-parse --verify HEAD~1) &&
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 &&
331 $head1 (tag: refs/tags/tag2)
332 $head2 (tag: refs/tags/message-one)
333 $old_head1 (tag: refs/tags/message-two)
335 sort actual >actual1 &&
336 test_cmp expected actual1
339 test_done