t4041, t7102: do not pass iso8859-1 parameter
[git/mingw/4msysgit.git] / t / t4205-log-pretty-formats.sh
blobf27b0b390af13fb06a684cb251ab706ab629e19c
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 sample_utf8_part=$(printf "f\303\244ng")
12 commit_msg () {
13 # String "initial. initial" partly in German
14 # (translated with Google Translate),
15 # encoded in UTF-8, used as a commit log message below.
16 msg="initial. an${sample_utf8_part}lich\n"
17 if test -n "$1"
18 then
19 printf "$msg" | iconv -f utf-8 -t "$1"
20 else
21 printf "$msg"
25 test_expect_success 'set up basic repos' '
26 >foo &&
27 >bar &&
28 git add foo &&
29 test_tick &&
30 git config i18n.commitEncoding iso8859-1 &&
31 # "git commit -m" would break MinGW, as Windows refuse to pass
32 # iso8859-1 encoded parameter to git.
33 commit_msg iso8859-1 | git commit -F - &&
34 git add bar &&
35 test_tick &&
36 git commit -m "add bar" &&
37 git config --unset i18n.commitEncoding
40 test_expect_success 'alias builtin format' '
41 git log --pretty=oneline >expected &&
42 git config pretty.test-alias oneline &&
43 git log --pretty=test-alias >actual &&
44 test_cmp expected actual
47 test_expect_success 'alias masking builtin format' '
48 git log --pretty=oneline >expected &&
49 git config pretty.oneline "%H" &&
50 git log --pretty=oneline >actual &&
51 test_cmp expected actual
54 test_expect_success 'alias user-defined format' '
55 git log --pretty="format:%h" >expected &&
56 git config pretty.test-alias "format:%h" &&
57 git log --pretty=test-alias >actual &&
58 test_cmp expected actual
61 test_expect_success 'alias user-defined tformat with %s (iso8859-1 encoding)' '
62 git config i18n.logOutputEncoding iso8859-1 &&
63 git log --oneline >expected-s &&
64 git log --pretty="tformat:%h %s" >actual-s &&
65 git config --unset i18n.logOutputEncoding &&
66 test_cmp expected-s actual-s
69 test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
70 git log --oneline >expected-s &&
71 git log --pretty="tformat:%h %s" >actual-s &&
72 test_cmp expected-s actual-s
75 test_expect_success 'alias user-defined tformat' '
76 git log --pretty="tformat:%h" >expected &&
77 git config pretty.test-alias "tformat:%h" &&
78 git log --pretty=test-alias >actual &&
79 test_cmp expected actual
82 test_expect_success 'alias non-existent format' '
83 git config pretty.test-alias format-that-will-never-exist &&
84 test_must_fail git log --pretty=test-alias
87 test_expect_success 'alias of an alias' '
88 git log --pretty="tformat:%h" >expected &&
89 git config pretty.test-foo "tformat:%h" &&
90 git config pretty.test-bar test-foo &&
91 git log --pretty=test-bar >actual && test_cmp expected actual
94 test_expect_success 'alias masking an alias' '
95 git log --pretty=format:"Two %H" >expected &&
96 git config pretty.duplicate "format:One %H" &&
97 git config --add pretty.duplicate "format:Two %H" &&
98 git log --pretty=duplicate >actual &&
99 test_cmp expected actual
102 test_expect_success 'alias loop' '
103 git config pretty.test-foo test-bar &&
104 git config pretty.test-bar test-foo &&
105 test_must_fail git log --pretty=test-foo
108 test_expect_success 'NUL separation' '
109 printf "add bar\0$(commit_msg)" >expected &&
110 git log -z --pretty="format:%s" >actual &&
111 test_cmp expected actual
114 test_expect_success 'NUL termination' '
115 printf "add bar\0$(commit_msg)\0" >expected &&
116 git log -z --pretty="tformat:%s" >actual &&
117 test_cmp expected actual
120 test_expect_success 'NUL separation with --stat' '
121 stat0_part=$(git diff --stat HEAD^ HEAD) &&
122 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
123 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
124 git log -z --stat --pretty="format:%s" >actual &&
125 test_i18ncmp expected actual
128 test_expect_failure 'NUL termination with --stat' '
129 stat0_part=$(git diff --stat HEAD^ HEAD) &&
130 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
131 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected &&
132 git log -z --stat --pretty="tformat:%s" >actual &&
133 test_i18ncmp expected actual
136 test_expect_success 'setup more commits' '
137 test_commit "message one" one one message-one &&
138 test_commit "message two" two two message-two &&
139 head1=$(git rev-parse --verify --short HEAD~0) &&
140 head2=$(git rev-parse --verify --short HEAD~1) &&
141 head3=$(git rev-parse --verify --short HEAD~2) &&
142 head4=$(git rev-parse --verify --short HEAD~3)
145 test_expect_success 'left alignment formatting' '
146 git log --pretty="format:%<(40)%s" >actual &&
147 # complete the incomplete line at the end
148 echo >>actual &&
149 qz_to_tab_space <<EOF >expected &&
150 message two Z
151 message one Z
152 add bar Z
153 $(commit_msg) Z
155 test_cmp expected actual
158 test_expect_success 'left alignment formatting at the nth column' '
159 git log --pretty="format:%h %<|(40)%s" >actual &&
160 # complete the incomplete line at the end
161 echo >>actual &&
162 qz_to_tab_space <<EOF >expected &&
163 $head1 message two Z
164 $head2 message one Z
165 $head3 add bar Z
166 $head4 $(commit_msg) Z
168 test_cmp expected actual
171 test_expect_success 'left alignment formatting with no padding' '
172 git log --pretty="format:%<(1)%s" >actual &&
173 # complete the incomplete line at the end
174 echo >>actual &&
175 cat <<EOF >expected &&
176 message two
177 message one
178 add bar
179 $(commit_msg)
181 test_cmp expected actual
184 test_expect_success 'left alignment formatting with trunc' '
185 git log --pretty="format:%<(10,trunc)%s" >actual &&
186 # complete the incomplete line at the end
187 echo >>actual &&
188 qz_to_tab_space <<EOF >expected &&
189 message ..
190 message ..
191 add bar Z
192 initial...
194 test_cmp expected actual
197 test_expect_success 'left alignment formatting with ltrunc' '
198 git log --pretty="format:%<(10,ltrunc)%s" >actual &&
199 # complete the incomplete line at the end
200 echo >>actual &&
201 qz_to_tab_space <<EOF >expected &&
202 ..sage two
203 ..sage one
204 add bar Z
205 ..${sample_utf8_part}lich
207 test_cmp expected actual
210 test_expect_success 'left alignment formatting with mtrunc' '
211 git log --pretty="format:%<(10,mtrunc)%s" >actual &&
212 # complete the incomplete line at the end
213 echo >>actual &&
214 qz_to_tab_space <<EOF >expected &&
215 mess.. two
216 mess.. one
217 add bar Z
218 init..lich
220 test_cmp expected actual
223 test_expect_success 'right alignment formatting' '
224 git log --pretty="format:%>(40)%s" >actual &&
225 # complete the incomplete line at the end
226 echo >>actual &&
227 qz_to_tab_space <<EOF >expected &&
228 Z message two
229 Z message one
230 Z add bar
231 Z $(commit_msg)
233 test_cmp expected actual
236 test_expect_success 'right alignment formatting at the nth column' '
237 git log --pretty="format:%h %>|(40)%s" >actual &&
238 # complete the incomplete line at the end
239 echo >>actual &&
240 qz_to_tab_space <<EOF >expected &&
241 $head1 message two
242 $head2 message one
243 $head3 add bar
244 $head4 $(commit_msg)
246 test_cmp expected actual
249 test_expect_success 'right alignment formatting with no padding' '
250 git log --pretty="format:%>(1)%s" >actual &&
251 # complete the incomplete line at the end
252 echo >>actual &&
253 cat <<EOF >expected &&
254 message two
255 message one
256 add bar
257 $(commit_msg)
259 test_cmp expected actual
262 test_expect_success 'center alignment formatting' '
263 git log --pretty="format:%><(40)%s" >actual &&
264 # complete the incomplete line at the end
265 echo >>actual &&
266 qz_to_tab_space <<EOF >expected &&
267 Z message two Z
268 Z message one Z
269 Z add bar Z
270 Z $(commit_msg) Z
272 test_cmp expected actual
275 test_expect_success 'center alignment formatting at the nth column' '
276 git log --pretty="format:%h %><|(40)%s" >actual &&
277 # complete the incomplete line at the end
278 echo >>actual &&
279 qz_to_tab_space <<EOF >expected &&
280 $head1 message two Z
281 $head2 message one Z
282 $head3 add bar Z
283 $head4 $(commit_msg) Z
285 test_cmp expected actual
288 test_expect_success 'center alignment formatting with no padding' '
289 git log --pretty="format:%><(1)%s" >actual &&
290 # complete the incomplete line at the end
291 echo >>actual &&
292 cat <<EOF >expected &&
293 message two
294 message one
295 add bar
296 $(commit_msg)
298 test_cmp expected actual
301 test_expect_success 'left/right alignment formatting with stealing' '
302 git commit --amend -m short --author "long long long <long@me.com>" &&
303 git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
304 # complete the incomplete line at the end
305 echo >>actual &&
306 cat <<EOF >expected &&
307 short long long long
308 message .. A U Thor
309 add bar A U Thor
310 initial... A U Thor
312 test_cmp expected actual
315 test_expect_success 'log decoration properly follows tag chain' '
316 git tag -a tag1 -m tag1 &&
317 git tag -a tag2 -m tag2 tag1 &&
318 git tag -d tag1 &&
319 git commit --amend -m shorter &&
320 git log --no-walk --tags --pretty="%H %d" --decorate=full >actual &&
321 cat <<EOF >expected &&
322 6a908c10688b2503073c39c9ba26322c73902bb5 (tag: refs/tags/tag2)
323 9f716384d92283fb915a4eee5073f030638e05f9 (tag: refs/tags/message-one)
324 b87e4cccdb77336ea79d89224737be7ea8e95367 (tag: refs/tags/message-two)
326 sort actual >actual1 &&
327 test_cmp expected actual1
330 test_done