Merge branch 'nd/fetch-into-shallow' into maint
[git.git] / t / t4205-log-pretty-formats.sh
blobfb000411395d50639334c3c0395b2b975aa4bc12
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 "$(commit_msg iso8859-1)" &&
32 git add bar &&
33 test_tick &&
34 git commit -m "add bar" &&
35 git config --unset i18n.commitEncoding
38 test_expect_success 'alias builtin format' '
39 git log --pretty=oneline >expected &&
40 git config pretty.test-alias oneline &&
41 git log --pretty=test-alias >actual &&
42 test_cmp expected actual
45 test_expect_success 'alias masking builtin format' '
46 git log --pretty=oneline >expected &&
47 git config pretty.oneline "%H" &&
48 git log --pretty=oneline >actual &&
49 test_cmp expected actual
52 test_expect_success 'alias user-defined format' '
53 git log --pretty="format:%h" >expected &&
54 git config pretty.test-alias "format:%h" &&
55 git log --pretty=test-alias >actual &&
56 test_cmp expected actual
59 test_expect_success 'alias user-defined tformat with %s (iso8859-1 encoding)' '
60 git config i18n.logOutputEncoding iso8859-1 &&
61 git log --oneline >expected-s &&
62 git log --pretty="tformat:%h %s" >actual-s &&
63 git config --unset i18n.logOutputEncoding &&
64 test_cmp expected-s actual-s
67 test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
68 git log --oneline >expected-s &&
69 git log --pretty="tformat:%h %s" >actual-s &&
70 test_cmp expected-s actual-s
73 test_expect_success 'alias user-defined tformat' '
74 git log --pretty="tformat:%h" >expected &&
75 git config pretty.test-alias "tformat:%h" &&
76 git log --pretty=test-alias >actual &&
77 test_cmp expected actual
80 test_expect_success 'alias non-existent format' '
81 git config pretty.test-alias format-that-will-never-exist &&
82 test_must_fail git log --pretty=test-alias
85 test_expect_success 'alias of an alias' '
86 git log --pretty="tformat:%h" >expected &&
87 git config pretty.test-foo "tformat:%h" &&
88 git config pretty.test-bar test-foo &&
89 git log --pretty=test-bar >actual && test_cmp expected actual
92 test_expect_success 'alias masking an alias' '
93 git log --pretty=format:"Two %H" >expected &&
94 git config pretty.duplicate "format:One %H" &&
95 git config --add pretty.duplicate "format:Two %H" &&
96 git log --pretty=duplicate >actual &&
97 test_cmp expected actual
100 test_expect_success 'alias loop' '
101 git config pretty.test-foo test-bar &&
102 git config pretty.test-bar test-foo &&
103 test_must_fail git log --pretty=test-foo
106 test_expect_success 'NUL separation' '
107 printf "add bar\0$(commit_msg)" >expected &&
108 git log -z --pretty="format:%s" >actual &&
109 test_cmp expected actual
112 test_expect_success 'NUL termination' '
113 printf "add bar\0$(commit_msg)\0" >expected &&
114 git log -z --pretty="tformat:%s" >actual &&
115 test_cmp expected actual
118 test_expect_success 'NUL separation with --stat' '
119 stat0_part=$(git diff --stat HEAD^ HEAD) &&
120 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
121 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
122 git log -z --stat --pretty="format:%s" >actual &&
123 test_i18ncmp expected actual
126 test_expect_failure 'NUL termination with --stat' '
127 stat0_part=$(git diff --stat HEAD^ HEAD) &&
128 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
129 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected &&
130 git log -z --stat --pretty="tformat:%s" >actual &&
131 test_i18ncmp expected actual
134 test_expect_success 'setup more commits' '
135 test_commit "message one" one one message-one &&
136 test_commit "message two" two two message-two &&
137 head1=$(git rev-parse --verify --short HEAD~0) &&
138 head2=$(git rev-parse --verify --short HEAD~1) &&
139 head3=$(git rev-parse --verify --short HEAD~2) &&
140 head4=$(git rev-parse --verify --short HEAD~3)
143 test_expect_success 'left alignment formatting' '
144 git log --pretty="format:%<(40)%s" >actual &&
145 # complete the incomplete line at the end
146 echo >>actual &&
147 qz_to_tab_space <<EOF >expected &&
148 message two Z
149 message one Z
150 add bar Z
151 $(commit_msg) Z
153 test_cmp expected actual
156 test_expect_success 'left alignment formatting at the nth column' '
157 git log --pretty="format:%h %<|(40)%s" >actual &&
158 # complete the incomplete line at the end
159 echo >>actual &&
160 qz_to_tab_space <<EOF >expected &&
161 $head1 message two Z
162 $head2 message one Z
163 $head3 add bar Z
164 $head4 $(commit_msg) Z
166 test_cmp expected actual
169 test_expect_success 'left alignment formatting with no padding' '
170 git log --pretty="format:%<(1)%s" >actual &&
171 # complete the incomplete line at the end
172 echo >>actual &&
173 cat <<EOF >expected &&
174 message two
175 message one
176 add bar
177 $(commit_msg)
179 test_cmp expected actual
182 test_expect_success 'left alignment formatting with trunc' '
183 git log --pretty="format:%<(10,trunc)%s" >actual &&
184 # complete the incomplete line at the end
185 echo >>actual &&
186 qz_to_tab_space <<EOF >expected &&
187 message ..
188 message ..
189 add bar Z
190 initial...
192 test_cmp expected actual
195 test_expect_success 'left alignment formatting with ltrunc' '
196 git log --pretty="format:%<(10,ltrunc)%s" >actual &&
197 # complete the incomplete line at the end
198 echo >>actual &&
199 qz_to_tab_space <<EOF >expected &&
200 ..sage two
201 ..sage one
202 add bar Z
203 ..${sample_utf8_part}lich
205 test_cmp expected actual
208 test_expect_success 'left alignment formatting with mtrunc' '
209 git log --pretty="format:%<(10,mtrunc)%s" >actual &&
210 # complete the incomplete line at the end
211 echo >>actual &&
212 qz_to_tab_space <<EOF >expected &&
213 mess.. two
214 mess.. one
215 add bar Z
216 init..lich
218 test_cmp expected actual
221 test_expect_success 'right alignment formatting' '
222 git log --pretty="format:%>(40)%s" >actual &&
223 # complete the incomplete line at the end
224 echo >>actual &&
225 qz_to_tab_space <<EOF >expected &&
226 Z message two
227 Z message one
228 Z add bar
229 Z $(commit_msg)
231 test_cmp expected actual
234 test_expect_success 'right alignment formatting at the nth column' '
235 git log --pretty="format:%h %>|(40)%s" >actual &&
236 # complete the incomplete line at the end
237 echo >>actual &&
238 qz_to_tab_space <<EOF >expected &&
239 $head1 message two
240 $head2 message one
241 $head3 add bar
242 $head4 $(commit_msg)
244 test_cmp expected actual
247 test_expect_success 'right alignment formatting with no padding' '
248 git log --pretty="format:%>(1)%s" >actual &&
249 # complete the incomplete line at the end
250 echo >>actual &&
251 cat <<EOF >expected &&
252 message two
253 message one
254 add bar
255 $(commit_msg)
257 test_cmp expected actual
260 test_expect_success 'center alignment formatting' '
261 git log --pretty="format:%><(40)%s" >actual &&
262 # complete the incomplete line at the end
263 echo >>actual &&
264 qz_to_tab_space <<EOF >expected &&
265 Z message two Z
266 Z message one Z
267 Z add bar Z
268 Z $(commit_msg) Z
270 test_cmp expected actual
273 test_expect_success 'center alignment formatting at the nth column' '
274 git log --pretty="format:%h %><|(40)%s" >actual &&
275 # complete the incomplete line at the end
276 echo >>actual &&
277 qz_to_tab_space <<EOF >expected &&
278 $head1 message two Z
279 $head2 message one Z
280 $head3 add bar Z
281 $head4 $(commit_msg) Z
283 test_cmp expected actual
286 test_expect_success 'center alignment formatting with no padding' '
287 git log --pretty="format:%><(1)%s" >actual &&
288 # complete the incomplete line at the end
289 echo >>actual &&
290 cat <<EOF >expected &&
291 message two
292 message one
293 add bar
294 $(commit_msg)
296 test_cmp expected actual
299 test_expect_success 'left/right alignment formatting with stealing' '
300 git commit --amend -m short --author "long long long <long@me.com>" &&
301 git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
302 # complete the incomplete line at the end
303 echo >>actual &&
304 cat <<EOF >expected &&
305 short long long long
306 message .. A U Thor
307 add bar A U Thor
308 initial... A U Thor
310 test_cmp expected actual
313 test_done