]>
Commit | Line | Data |
---|---|---|
8028184e WP |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2010, Will Palmer | |
de6029a2 | 4 | # Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests) |
8028184e WP |
5 | # |
6 | ||
7 | test_description='Test pretty formats' | |
8 | . ./test-lib.sh | |
9 | ||
de6029a2 AS |
10 | commit_msg () { |
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") | |
14 | if test -n "$1" | |
15 | then | |
16 | msg=$(echo $msg | iconv -f utf-8 -t $1) | |
17 | fi | |
18 | if test -n "$2" -a -n "$3" | |
19 | then | |
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../") | |
26 | fi | |
27 | echo $msg | |
28 | } | |
29 | ||
8028184e WP |
30 | test_expect_success 'set up basic repos' ' |
31 | >foo && | |
32 | >bar && | |
33 | git add foo && | |
34 | test_tick && | |
de6029a2 AS |
35 | git config i18n.commitEncoding iso-8859-1 && |
36 | git commit -m "$(commit_msg iso-8859-1)" && | |
8028184e WP |
37 | git add bar && |
38 | test_tick && | |
de6029a2 AS |
39 | git commit -m "add bar" && |
40 | git config --unset i18n.commitEncoding | |
8028184e WP |
41 | ' |
42 | ||
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 | |
48 | ' | |
49 | ||
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 | |
55 | ' | |
56 | ||
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 | |
62 | ' | |
63 | ||
de6029a2 AS |
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 | |
70 | ' | |
71 | ||
72 | test_expect_failure '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 | |
76 | ' | |
77 | ||
8028184e WP |
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 | |
83 | ' | |
84 | ||
7be8b3ba | 85 | test_expect_success 'alias non-existent format' ' |
8028184e WP |
86 | git config pretty.test-alias format-that-will-never-exist && |
87 | test_must_fail git log --pretty=test-alias | |
88 | ' | |
89 | ||
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 | |
95 | ' | |
96 | ||
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 | |
103 | ' | |
104 | ||
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 | |
109 | ' | |
110 | ||
de6029a2 AS |
111 | test_expect_failure 'NUL separation' ' |
112 | printf "add bar\0$(commit_msg)" >expected && | |
3e065308 JK |
113 | git log -z --pretty="format:%s" >actual && |
114 | test_cmp expected actual | |
115 | ' | |
116 | ||
de6029a2 AS |
117 | test_expect_failure 'NUL termination' ' |
118 | printf "add bar\0$(commit_msg)\0" >expected && | |
3e065308 JK |
119 | git log -z --pretty="tformat:%s" >actual && |
120 | test_cmp expected actual | |
121 | ' | |
122 | ||
de6029a2 | 123 | test_expect_failure 'NUL separation with --stat' ' |
fafd3829 | 124 | stat0_part=$(git diff --stat HEAD^ HEAD) && |
74faaa16 | 125 | stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) && |
de6029a2 | 126 | printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected && |
fafd3829 | 127 | git log -z --stat --pretty="format:%s" >actual && |
b354f11b | 128 | test_i18ncmp expected actual |
fafd3829 JH |
129 | ' |
130 | ||
131 | test_expect_failure 'NUL termination with --stat' ' | |
132 | stat0_part=$(git diff --stat HEAD^ HEAD) && | |
74faaa16 | 133 | stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) && |
de6029a2 | 134 | printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected && |
fafd3829 | 135 | git log -z --stat --pretty="tformat:%s" >actual && |
b354f11b | 136 | test_i18ncmp expected actual |
fafd3829 JH |
137 | ' |
138 | ||
a5752342 NTND |
139 | test_expect_success 'setup more commits' ' |
140 | test_commit "message one" one one message-one && | |
a742f2a0 AS |
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) | |
a5752342 NTND |
146 | ' |
147 | ||
de6029a2 AS |
148 | test_expect_failure 'left alignment formatting' " |
149 | git log --pretty='format:%<(40)%s' >actual && | |
a5752342 NTND |
150 | # complete the incomplete line at the end |
151 | echo >>actual && | |
152 | qz_to_tab_space <<\EOF >expected && | |
153 | message two Z | |
154 | message one Z | |
155 | add bar Z | |
de6029a2 | 156 | $(commit_msg) Z |
a5752342 NTND |
157 | EOF |
158 | test_cmp expected actual | |
de6029a2 | 159 | " |
a5752342 | 160 | |
de6029a2 | 161 | test_expect_failure 'left alignment formatting at the nth column' " |
a742f2a0 | 162 | git log --pretty='format:%h %<|(40)%s' >actual && |
a5752342 NTND |
163 | # complete the incomplete line at the end |
164 | echo >>actual && | |
165 | qz_to_tab_space <<\EOF >expected && | |
a742f2a0 AS |
166 | $head1 message two Z |
167 | $head2 message one Z | |
168 | $head3 add bar Z | |
de6029a2 | 169 | $head4 $(commit_msg) Z |
a5752342 NTND |
170 | EOF |
171 | test_cmp expected actual | |
a742f2a0 | 172 | " |
a5752342 | 173 | |
de6029a2 AS |
174 | test_expect_failure 'left alignment formatting with no padding' " |
175 | git log --pretty='format:%<(1)%s' >actual && | |
a5752342 NTND |
176 | # complete the incomplete line at the end |
177 | echo >>actual && | |
178 | cat <<\EOF >expected && | |
179 | message two | |
180 | message one | |
181 | add bar | |
de6029a2 | 182 | $(commit_msg) |
a5752342 NTND |
183 | EOF |
184 | test_cmp expected actual | |
de6029a2 | 185 | " |
a5752342 | 186 | |
de6029a2 AS |
187 | test_expect_failure 'left alignment formatting with trunc' " |
188 | git log --pretty='format:%<(10,trunc)%s' >actual && | |
a7f01c6b NTND |
189 | # complete the incomplete line at the end |
190 | echo >>actual && | |
191 | qz_to_tab_space <<\EOF >expected && | |
192 | message .. | |
193 | message .. | |
194 | add bar Z | |
de6029a2 | 195 | $(commit_msg "" "8" ".\+$") |
a7f01c6b NTND |
196 | EOF |
197 | test_cmp expected actual | |
de6029a2 | 198 | " |
a7f01c6b | 199 | |
de6029a2 AS |
200 | test_expect_failure 'left alignment formatting with ltrunc' " |
201 | git log --pretty='format:%<(10,ltrunc)%s' >actual && | |
a7f01c6b NTND |
202 | # complete the incomplete line at the end |
203 | echo >>actual && | |
204 | qz_to_tab_space <<\EOF >expected && | |
205 | ..sage two | |
206 | ..sage one | |
207 | add bar Z | |
de6029a2 | 208 | $(commit_msg "" "0" ".\{11\}") |
a7f01c6b NTND |
209 | EOF |
210 | test_cmp expected actual | |
de6029a2 | 211 | " |
a7f01c6b | 212 | |
de6029a2 AS |
213 | test_expect_failure 'left alignment formatting with mtrunc' " |
214 | git log --pretty='format:%<(10,mtrunc)%s' >actual && | |
a7f01c6b NTND |
215 | # complete the incomplete line at the end |
216 | echo >>actual && | |
217 | qz_to_tab_space <<\EOF >expected && | |
218 | mess.. two | |
219 | mess.. one | |
220 | add bar Z | |
de6029a2 | 221 | $(commit_msg "" "4" ".\{11\}") |
a7f01c6b NTND |
222 | EOF |
223 | test_cmp expected actual | |
de6029a2 | 224 | " |
a7f01c6b | 225 | |
de6029a2 AS |
226 | test_expect_failure 'right alignment formatting' " |
227 | git log --pretty='format:%>(40)%s' >actual && | |
a5752342 NTND |
228 | # complete the incomplete line at the end |
229 | echo >>actual && | |
230 | qz_to_tab_space <<\EOF >expected && | |
231 | Z message two | |
232 | Z message one | |
233 | Z add bar | |
de6029a2 | 234 | Z $(commit_msg) |
a5752342 NTND |
235 | EOF |
236 | test_cmp expected actual | |
de6029a2 | 237 | " |
a5752342 | 238 | |
de6029a2 | 239 | test_expect_failure 'right alignment formatting at the nth column' " |
a742f2a0 | 240 | git log --pretty='format:%h %>|(40)%s' >actual && |
a5752342 NTND |
241 | # complete the incomplete line at the end |
242 | echo >>actual && | |
243 | qz_to_tab_space <<\EOF >expected && | |
a742f2a0 AS |
244 | $head1 message two |
245 | $head2 message one | |
246 | $head3 add bar | |
de6029a2 | 247 | $head4 $(commit_msg) |
a5752342 NTND |
248 | EOF |
249 | test_cmp expected actual | |
a742f2a0 | 250 | " |
a5752342 | 251 | |
de6029a2 AS |
252 | test_expect_failure 'right alignment formatting with no padding' " |
253 | git log --pretty='format:%>(1)%s' >actual && | |
a5752342 NTND |
254 | # complete the incomplete line at the end |
255 | echo >>actual && | |
256 | cat <<\EOF >expected && | |
257 | message two | |
258 | message one | |
259 | add bar | |
de6029a2 | 260 | $(commit_msg) |
a5752342 NTND |
261 | EOF |
262 | test_cmp expected actual | |
de6029a2 | 263 | " |
a5752342 | 264 | |
de6029a2 AS |
265 | test_expect_failure 'center alignment formatting' " |
266 | git log --pretty='format:%><(40)%s' >actual && | |
a5752342 NTND |
267 | # complete the incomplete line at the end |
268 | echo >>actual && | |
269 | qz_to_tab_space <<\EOF >expected && | |
270 | Z message two Z | |
271 | Z message one Z | |
272 | Z add bar Z | |
de6029a2 | 273 | Z $(commit_msg) Z |
a5752342 NTND |
274 | EOF |
275 | test_cmp expected actual | |
de6029a2 | 276 | " |
a5752342 | 277 | |
de6029a2 | 278 | test_expect_failure 'center alignment formatting at the nth column' " |
a742f2a0 | 279 | git log --pretty='format:%h %><|(40)%s' >actual && |
a5752342 NTND |
280 | # complete the incomplete line at the end |
281 | echo >>actual && | |
282 | qz_to_tab_space <<\EOF >expected && | |
a742f2a0 AS |
283 | $head1 message two Z |
284 | $head2 message one Z | |
285 | $head3 add bar Z | |
de6029a2 | 286 | $head4 $(commit_msg) Z |
a5752342 NTND |
287 | EOF |
288 | test_cmp expected actual | |
a742f2a0 | 289 | " |
a5752342 | 290 | |
de6029a2 AS |
291 | test_expect_failure 'center alignment formatting with no padding' " |
292 | git log --pretty='format:%><(1)%s' >actual && | |
a5752342 NTND |
293 | # complete the incomplete line at the end |
294 | echo >>actual && | |
295 | cat <<\EOF >expected && | |
296 | message two | |
297 | message one | |
298 | add bar | |
de6029a2 | 299 | $(commit_msg) |
a5752342 NTND |
300 | EOF |
301 | test_cmp expected actual | |
de6029a2 | 302 | " |
a5752342 | 303 | |
de6029a2 AS |
304 | test_expect_failure '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 && | |
1640632b NTND |
307 | # complete the incomplete line at the end |
308 | echo >>actual && | |
309 | cat <<\EOF >expected && | |
310 | short long long long | |
311 | message .. A U Thor | |
312 | add bar A U Thor | |
de6029a2 | 313 | $(commit_msg "" "8" ".\+$") A U Thor |
1640632b NTND |
314 | EOF |
315 | test_cmp expected actual | |
de6029a2 | 316 | " |
1640632b | 317 | |
8028184e | 318 | test_done |