]>
Commit | Line | Data |
---|---|---|
fa21b602 JK |
1 | #!/bin/sh |
2 | ||
de6029a2 AS |
3 | # Copyright (c) 2009 Jens Lehmann |
4 | # Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests) | |
5 | ||
5be60078 | 6 | test_description='git rev-list --pretty=format test' |
fa21b602 JK |
7 | |
8 | . ./test-lib.sh | |
30825178 | 9 | . "$TEST_DIRECTORY"/lib-terminal.sh |
fa21b602 JK |
10 | |
11 | test_tick | |
ee3efaf6 AS |
12 | # Tested non-UTF-8 encoding |
13 | test_encoding="ISO8859-1" | |
14 | ||
17cc2ef1 AS |
15 | # String "added" in German |
16 | # (translated with Google Translate), | |
17 | # encoded in UTF-8, used as a commit log message below. | |
d928d810 AS |
18 | added_utf8_part=$(printf "\303\274") |
19 | added_utf8_part_iso88591=$(echo "$added_utf8_part" | iconv -f utf-8 -t $test_encoding) | |
20 | added=$(printf "added (hinzugef${added_utf8_part}gt) foo") | |
ee3efaf6 | 21 | added_iso88591=$(echo "$added" | iconv -f utf-8 -t $test_encoding) |
de6029a2 | 22 | # same but "changed" |
d928d810 AS |
23 | changed_utf8_part=$(printf "\303\244") |
24 | changed_utf8_part_iso88591=$(echo "$changed_utf8_part" | iconv -f utf-8 -t $test_encoding) | |
25 | changed=$(printf "changed (ge${changed_utf8_part}ndert) foo") | |
ee3efaf6 | 26 | changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding) |
de6029a2 | 27 | |
d928d810 AS |
28 | # Count of char to truncate |
29 | # Number is chosen so, that non-ACSII characters | |
30 | # (see $added_utf8_part and $changed_utf8_part) | |
31 | # fall into truncated parts of appropriate words both from left and right | |
32 | truncate_count=20 | |
33 | ||
fa21b602 | 34 | test_expect_success 'setup' ' |
77a6815d AS |
35 | : >foo && |
36 | git add foo && | |
ee3efaf6 | 37 | git config i18n.commitEncoding $test_encoding && |
e6ce2be2 | 38 | echo "$added_iso88591" | git commit -F - && |
77a6815d AS |
39 | head1=$(git rev-parse --verify HEAD) && |
40 | head1_short=$(git rev-parse --verify --short $head1) && | |
41 | tree1=$(git rev-parse --verify HEAD:) && | |
42 | tree1_short=$(git rev-parse --verify --short $tree1) && | |
de6029a2 | 43 | echo "$changed" > foo && |
e6ce2be2 | 44 | echo "$changed_iso88591" | git commit -a -F - && |
77a6815d AS |
45 | head2=$(git rev-parse --verify HEAD) && |
46 | head2_short=$(git rev-parse --verify --short $head2) && | |
47 | tree2=$(git rev-parse --verify HEAD:) && | |
99094a7a | 48 | tree2_short=$(git rev-parse --verify --short $tree2) && |
de6029a2 | 49 | git config --unset i18n.commitEncoding |
fa21b602 JK |
50 | ' |
51 | ||
17cc2ef1 | 52 | # usage: test_format name format_string [failure] <expected_output |
2581ad5e | 53 | test_format () { |
fa21b602 | 54 | cat >expect.$1 |
17cc2ef1 AS |
55 | test_expect_${3:-success} "format $1" " |
56 | git rev-list --pretty=format:'$2' master >output.$1 && | |
57 | test_cmp expect.$1 output.$1 | |
58 | " | |
fa21b602 JK |
59 | } |
60 | ||
30825178 JH |
61 | # Feed to --format to provide predictable colored sequences. |
62 | AUTO_COLOR='%C(auto,red)foo%C(auto,reset)' | |
63 | has_color () { | |
64 | printf '\033[31mfoo\033[m\n' >expect && | |
65 | test_cmp expect "$1" | |
66 | } | |
67 | ||
68 | has_no_color () { | |
69 | echo foo >expect && | |
70 | test_cmp expect "$1" | |
71 | } | |
72 | ||
77a6815d AS |
73 | test_format percent %%h <<EOF |
74 | commit $head2 | |
0a0416a3 | 75 | %h |
77a6815d | 76 | commit $head1 |
0a0416a3 JK |
77 | %h |
78 | EOF | |
79 | ||
77a6815d AS |
80 | test_format hash %H%n%h <<EOF |
81 | commit $head2 | |
82 | $head2 | |
83 | $head2_short | |
84 | commit $head1 | |
85 | $head1 | |
86 | $head1_short | |
fa21b602 JK |
87 | EOF |
88 | ||
77a6815d AS |
89 | test_format tree %T%n%t <<EOF |
90 | commit $head2 | |
91 | $tree2 | |
92 | $tree2_short | |
93 | commit $head1 | |
94 | $tree1 | |
95 | $tree1_short | |
fa21b602 JK |
96 | EOF |
97 | ||
77a6815d AS |
98 | test_format parents %P%n%p <<EOF |
99 | commit $head2 | |
100 | $head1 | |
101 | $head1_short | |
102 | commit $head1 | |
542e165c JH |
103 | |
104 | ||
fa21b602 JK |
105 | EOF |
106 | ||
107 | # we don't test relative here | |
77a6815d AS |
108 | test_format author %an%n%ae%n%ad%n%aD%n%at <<EOF |
109 | commit $head2 | |
fa21b602 JK |
110 | A U Thor |
111 | author@example.com | |
112 | Thu Apr 7 15:13:13 2005 -0700 | |
113 | Thu, 7 Apr 2005 15:13:13 -0700 | |
114 | 1112911993 | |
77a6815d | 115 | commit $head1 |
fa21b602 JK |
116 | A U Thor |
117 | author@example.com | |
118 | Thu Apr 7 15:13:13 2005 -0700 | |
119 | Thu, 7 Apr 2005 15:13:13 -0700 | |
120 | 1112911993 | |
121 | EOF | |
122 | ||
77a6815d AS |
123 | test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<EOF |
124 | commit $head2 | |
fa21b602 JK |
125 | C O Mitter |
126 | committer@example.com | |
127 | Thu Apr 7 15:13:13 2005 -0700 | |
128 | Thu, 7 Apr 2005 15:13:13 -0700 | |
129 | 1112911993 | |
77a6815d | 130 | commit $head1 |
fa21b602 JK |
131 | C O Mitter |
132 | committer@example.com | |
133 | Thu Apr 7 15:13:13 2005 -0700 | |
134 | Thu, 7 Apr 2005 15:13:13 -0700 | |
135 | 1112911993 | |
136 | EOF | |
137 | ||
77a6815d AS |
138 | test_format encoding %e <<EOF |
139 | commit $head2 | |
ee3efaf6 | 140 | $test_encoding |
77a6815d | 141 | commit $head1 |
ee3efaf6 | 142 | $test_encoding |
fa21b602 JK |
143 | EOF |
144 | ||
ecaee805 | 145 | test_format subject %s <<EOF |
77a6815d | 146 | commit $head2 |
de6029a2 | 147 | $changed |
77a6815d | 148 | commit $head1 |
de6029a2 | 149 | $added |
fa21b602 JK |
150 | EOF |
151 | ||
d928d810 AS |
152 | test_format subject-truncated "%<($truncate_count,trunc)%s" <<EOF |
153 | commit $head2 | |
154 | changed (ge${changed_utf8_part}ndert).. | |
155 | commit $head1 | |
156 | added (hinzugef${added_utf8_part}gt.. | |
157 | EOF | |
158 | ||
77a6815d AS |
159 | test_format body %b <<EOF |
160 | commit $head2 | |
161 | commit $head1 | |
fa21b602 JK |
162 | EOF |
163 | ||
ecaee805 | 164 | test_format raw-body %B <<EOF |
77a6815d | 165 | commit $head2 |
de6029a2 | 166 | $changed |
1367b12a | 167 | |
77a6815d | 168 | commit $head1 |
de6029a2 | 169 | $added |
1367b12a EB |
170 | |
171 | EOF | |
172 | ||
77a6815d AS |
173 | test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<EOF |
174 | commit $head2 | |
fa21b602 | 175 | \e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy |
77a6815d | 176 | commit $head1 |
fa21b602 JK |
177 | \e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy |
178 | EOF | |
179 | ||
77a6815d AS |
180 | test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<EOF |
181 | commit $head2 | |
c002922a | 182 | \e[1;31;43mfoo\e[m |
77a6815d | 183 | commit $head1 |
c002922a JK |
184 | \e[1;31;43mfoo\e[m |
185 | EOF | |
186 | ||
b15a3e00 | 187 | test_expect_success '%C(auto,...) does not enable color by default' ' |
30825178 JH |
188 | git log --format=$AUTO_COLOR -1 >actual && |
189 | has_no_color actual | |
190 | ' | |
191 | ||
b15a3e00 | 192 | test_expect_success '%C(auto,...) enables colors for color.diff' ' |
30825178 JH |
193 | git -c color.diff=always log --format=$AUTO_COLOR -1 >actual && |
194 | has_color actual | |
195 | ' | |
196 | ||
b15a3e00 | 197 | test_expect_success '%C(auto,...) enables colors for color.ui' ' |
30825178 JH |
198 | git -c color.ui=always log --format=$AUTO_COLOR -1 >actual && |
199 | has_color actual | |
200 | ' | |
201 | ||
b15a3e00 | 202 | test_expect_success '%C(auto,...) respects --color' ' |
30825178 JH |
203 | git log --format=$AUTO_COLOR -1 --color >actual && |
204 | has_color actual | |
205 | ' | |
206 | ||
b15a3e00 | 207 | test_expect_success '%C(auto,...) respects --no-color' ' |
30825178 JH |
208 | git -c color.ui=always log --format=$AUTO_COLOR -1 --no-color >actual && |
209 | has_no_color actual | |
210 | ' | |
211 | ||
b15a3e00 | 212 | test_expect_success TTY '%C(auto,...) respects --color=auto (stdout is tty)' ' |
512477b1 DT |
213 | test_terminal env TERM=vt100 \ |
214 | git log --format=$AUTO_COLOR -1 --color=auto >actual && | |
215 | has_color actual | |
30825178 JH |
216 | ' |
217 | ||
b15a3e00 | 218 | test_expect_success '%C(auto,...) respects --color=auto (stdout not tty)' ' |
30825178 JH |
219 | ( |
220 | TERM=vt100 && export TERM && | |
221 | git log --format=$AUTO_COLOR -1 --color=auto >actual && | |
222 | has_no_color actual | |
223 | ) | |
224 | ' | |
225 | ||
b15a3e00 ET |
226 | test_expect_success '%C(auto) respects --color' ' |
227 | git log --color --format="%C(auto)%H" -1 >actual && | |
82b83da8 | 228 | printf "\\033[33m%s\\033[m\\n" $(git rev-parse HEAD) >expect && |
b15a3e00 ET |
229 | test_cmp expect actual |
230 | ' | |
231 | ||
232 | test_expect_success '%C(auto) respects --no-color' ' | |
233 | git log --no-color --format="%C(auto)%H" -1 >actual && | |
234 | git rev-parse HEAD >expect && | |
235 | test_cmp expect actual | |
236 | ' | |
237 | ||
ee3efaf6 | 238 | iconv -f utf-8 -t $test_encoding > commit-msg <<EOF |
03bcaaca JK |
239 | Test printing of complex bodies |
240 | ||
241 | This commit message is much longer than the others, | |
ee3efaf6 AS |
242 | and it will be encoded in $test_encoding. We should therefore |
243 | include an ISO8859 character: ¡bueno! | |
03bcaaca | 244 | EOF |
77a6815d | 245 | |
03bcaaca | 246 | test_expect_success 'setup complex body' ' |
ee3efaf6 | 247 | git config i18n.commitencoding $test_encoding && |
77a6815d AS |
248 | echo change2 >foo && git commit -a -F commit-msg && |
249 | head3=$(git rev-parse --verify HEAD) && | |
0fe6df3c | 250 | head3_short=$(git rev-parse --short $head3) |
03bcaaca JK |
251 | ' |
252 | ||
77a6815d AS |
253 | test_format complex-encoding %e <<EOF |
254 | commit $head3 | |
ee3efaf6 | 255 | $test_encoding |
77a6815d | 256 | commit $head2 |
ee3efaf6 | 257 | $test_encoding |
77a6815d | 258 | commit $head1 |
ee3efaf6 | 259 | $test_encoding |
03bcaaca JK |
260 | EOF |
261 | ||
ecaee805 | 262 | test_format complex-subject %s <<EOF |
77a6815d | 263 | commit $head3 |
03bcaaca | 264 | Test printing of complex bodies |
77a6815d | 265 | commit $head2 |
0fe6df3c | 266 | $changed_iso88591 |
77a6815d | 267 | commit $head1 |
0fe6df3c | 268 | $added_iso88591 |
03bcaaca JK |
269 | EOF |
270 | ||
7d509878 | 271 | test_format complex-subject-trunc "%<($truncate_count,trunc)%s" <<EOF |
d928d810 AS |
272 | commit $head3 |
273 | Test printing of c.. | |
274 | commit $head2 | |
275 | changed (ge${changed_utf8_part_iso88591}ndert).. | |
276 | commit $head1 | |
277 | added (hinzugef${added_utf8_part_iso88591}gt.. | |
278 | EOF | |
279 | ||
7d509878 | 280 | test_format complex-subject-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF |
d928d810 AS |
281 | commit $head3 |
282 | Test prin..ex bodies | |
283 | commit $head2 | |
284 | changed (..dert) foo | |
285 | commit $head1 | |
286 | added (hi..f${added_utf8_part_iso88591}gt) foo | |
287 | EOF | |
288 | ||
7d509878 | 289 | test_format complex-subject-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF |
d928d810 AS |
290 | commit $head3 |
291 | .. of complex bodies | |
292 | commit $head2 | |
293 | ..ged (ge${changed_utf8_part_iso88591}ndert) foo | |
294 | commit $head1 | |
295 | .. (hinzugef${added_utf8_part_iso88591}gt) foo | |
296 | EOF | |
297 | ||
0fe6df3c AS |
298 | test_expect_success 'prepare expected messages (for test %b)' ' |
299 | cat <<-EOF >expected.utf-8 && | |
300 | commit $head3 | |
301 | This commit message is much longer than the others, | |
ee3efaf6 AS |
302 | and it will be encoded in $test_encoding. We should therefore |
303 | include an ISO8859 character: ¡bueno! | |
0fe6df3c AS |
304 | |
305 | commit $head2 | |
306 | commit $head1 | |
307 | EOF | |
ee3efaf6 | 308 | iconv -f utf-8 -t $test_encoding expected.utf-8 >expected.ISO8859-1 |
0fe6df3c AS |
309 | ' |
310 | ||
ee3efaf6 | 311 | test_format complex-body %b <expected.ISO8859-1 |
03bcaaca | 312 | |
0fe6df3c AS |
313 | # Git uses i18n.commitEncoding if no i18n.logOutputEncoding set |
314 | # so unset i18n.commitEncoding to test encoding conversion | |
315 | git config --unset i18n.commitEncoding | |
316 | ||
317 | test_format complex-subject-commitencoding-unset %s <<EOF | |
318 | commit $head3 | |
319 | Test printing of complex bodies | |
77a6815d | 320 | commit $head2 |
0fe6df3c | 321 | $changed |
77a6815d | 322 | commit $head1 |
0fe6df3c | 323 | $added |
03bcaaca JK |
324 | EOF |
325 | ||
d928d810 AS |
326 | test_format complex-subject-commitencoding-unset-trunc "%<($truncate_count,trunc)%s" <<EOF |
327 | commit $head3 | |
328 | Test printing of c.. | |
329 | commit $head2 | |
330 | changed (ge${changed_utf8_part}ndert).. | |
331 | commit $head1 | |
332 | added (hinzugef${added_utf8_part}gt.. | |
333 | EOF | |
334 | ||
335 | test_format complex-subject-commitencoding-unset-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF | |
336 | commit $head3 | |
337 | Test prin..ex bodies | |
338 | commit $head2 | |
339 | changed (..dert) foo | |
340 | commit $head1 | |
341 | added (hi..f${added_utf8_part}gt) foo | |
342 | EOF | |
343 | ||
344 | test_format complex-subject-commitencoding-unset-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF | |
345 | commit $head3 | |
346 | .. of complex bodies | |
347 | commit $head2 | |
348 | ..ged (ge${changed_utf8_part}ndert) foo | |
349 | commit $head1 | |
350 | .. (hinzugef${added_utf8_part}gt) foo | |
351 | EOF | |
352 | ||
0fe6df3c AS |
353 | test_format complex-body-commitencoding-unset %b <expected.utf-8 |
354 | ||
9130ac9f | 355 | test_expect_success '%x00 shows NUL' ' |
77a6815d | 356 | echo >expect commit $head3 && |
9130ac9f JK |
357 | echo >>expect fooQbar && |
358 | git rev-list -1 --format=foo%x00bar HEAD >actual.nul && | |
359 | nul_to_q <actual.nul >actual && | |
360 | test_cmp expect actual | |
361 | ' | |
362 | ||
d36f8679 JK |
363 | test_expect_success '%ad respects --date=' ' |
364 | echo 2005-04-07 >expect.ad-short && | |
365 | git log -1 --date=short --pretty=tformat:%ad >output.ad-short master && | |
366 | test_cmp expect.ad-short output.ad-short | |
367 | ' | |
368 | ||
f7ab5c79 JH |
369 | test_expect_success 'empty email' ' |
370 | test_tick && | |
371 | C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) && | |
372 | A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) && | |
a167ece0 | 373 | verbose test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700" |
f7ab5c79 JH |
374 | ' |
375 | ||
9fa708da JH |
376 | test_expect_success 'del LF before empty (1)' ' |
377 | git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD^^ >actual && | |
3fb0459b | 378 | test_line_count = 2 actual |
9fa708da JH |
379 | ' |
380 | ||
381 | test_expect_success 'del LF before empty (2)' ' | |
382 | git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD >actual && | |
3fb0459b | 383 | test_line_count = 6 actual && |
9fa708da JH |
384 | grep "^$" actual |
385 | ' | |
386 | ||
387 | test_expect_success 'add LF before non-empty (1)' ' | |
388 | git show -s --pretty=format:"%s%+b%nThanks%n" HEAD^^ >actual && | |
3fb0459b | 389 | test_line_count = 2 actual |
9fa708da JH |
390 | ' |
391 | ||
392 | test_expect_success 'add LF before non-empty (2)' ' | |
393 | git show -s --pretty=format:"%s%+b%nThanks%n" HEAD >actual && | |
3fb0459b | 394 | test_line_count = 6 actual && |
9fa708da JH |
395 | grep "^$" actual |
396 | ' | |
397 | ||
7b88176e MG |
398 | test_expect_success 'add SP before non-empty (1)' ' |
399 | git show -s --pretty=format:"%s% bThanks" HEAD^^ >actual && | |
de6029a2 | 400 | test $(wc -w <actual) = 3 |
7b88176e MG |
401 | ' |
402 | ||
403 | test_expect_success 'add SP before non-empty (2)' ' | |
404 | git show -s --pretty=format:"%s% sThanks" HEAD^^ >actual && | |
de6029a2 | 405 | test $(wc -w <actual) = 6 |
7b88176e MG |
406 | ' |
407 | ||
c1977021 WP |
408 | test_expect_success '--abbrev' ' |
409 | echo SHORT SHORT SHORT >expect2 && | |
410 | echo LONG LONG LONG >expect3 && | |
411 | git log -1 --format="%h %h %h" HEAD >actual1 && | |
412 | git log -1 --abbrev=5 --format="%h %h %h" HEAD >actual2 && | |
413 | git log -1 --abbrev=5 --format="%H %H %H" HEAD >actual3 && | |
414 | sed -e "s/$_x40/LONG/g" -e "s/$_x05/SHORT/g" <actual2 >fuzzy2 && | |
415 | sed -e "s/$_x40/LONG/g" -e "s/$_x05/SHORT/g" <actual3 >fuzzy3 && | |
416 | test_cmp expect2 fuzzy2 && | |
417 | test_cmp expect3 fuzzy3 && | |
418 | ! test_cmp actual1 actual2 | |
419 | ' | |
420 | ||
421 | test_expect_success '%H is not affected by --abbrev-commit' ' | |
422 | git log -1 --format=%H --abbrev-commit --abbrev=20 HEAD >actual && | |
423 | len=$(wc -c <actual) && | |
424 | test $len = 41 | |
425 | ' | |
426 | ||
427 | test_expect_success '%h is not affected by --abbrev-commit' ' | |
428 | git log -1 --format=%h --abbrev-commit --abbrev=20 HEAD >actual && | |
429 | len=$(wc -c <actual) && | |
430 | test $len = 21 | |
431 | ' | |
432 | ||
8f8f5476 TR |
433 | test_expect_success '"%h %gD: %gs" is same as git-reflog' ' |
434 | git reflog >expect && | |
435 | git log -g --format="%h %gD: %gs" >actual && | |
436 | test_cmp expect actual | |
437 | ' | |
438 | ||
439 | test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' ' | |
440 | git reflog --date=raw >expect && | |
441 | git log -g --format="%h %gD: %gs" --date=raw >actual && | |
442 | test_cmp expect actual | |
443 | ' | |
444 | ||
c1977021 WP |
445 | test_expect_success '"%h %gD: %gs" is same as git-reflog (with --abbrev)' ' |
446 | git reflog --abbrev=13 --date=raw >expect && | |
447 | git log -g --abbrev=13 --format="%h %gD: %gs" --date=raw >actual && | |
448 | test_cmp expect actual | |
449 | ' | |
450 | ||
8f8f5476 TR |
451 | test_expect_success '%gd shortens ref name' ' |
452 | echo "master@{0}" >expect.gd-short && | |
453 | git log -g -1 --format=%gd refs/heads/master >actual.gd-short && | |
454 | test_cmp expect.gd-short actual.gd-short | |
455 | ' | |
456 | ||
cd1957f5 JK |
457 | test_expect_success 'reflog identity' ' |
458 | echo "C O Mitter:committer@example.com" >expect && | |
459 | git log -g -1 --format="%gn:%ge" >actual && | |
460 | test_cmp expect actual | |
461 | ' | |
462 | ||
1fb5fdd2 EFL |
463 | test_expect_success 'oneline with empty message' ' |
464 | git commit -m "dummy" --allow-empty && | |
465 | git commit -m "dummy" --allow-empty && | |
466 | git filter-branch --msg-filter "sed -e s/dummy//" HEAD^^.. && | |
f02dd06e | 467 | git rev-list --oneline HEAD >test.txt && |
3fb0459b SL |
468 | test_line_count = 5 test.txt && |
469 | git rev-list --oneline --graph HEAD >testg.txt && | |
470 | test_line_count = 5 testg.txt | |
1fb5fdd2 EFL |
471 | ' |
472 | ||
d9955fd6 JK |
473 | test_expect_success 'single-character name is parsed correctly' ' |
474 | git commit --author="a <a@example.com>" --allow-empty -m foo && | |
475 | echo "a <a@example.com>" >expect && | |
476 | git log -1 --format="%an <%ae>" >actual && | |
477 | test_cmp expect actual | |
478 | ' | |
479 | ||
958b2eb2 JK |
480 | test_expect_success 'unused %G placeholders are passed through' ' |
481 | echo "%GX %G" >expect && | |
482 | git log -1 --format="%GX %G" >actual && | |
483 | test_cmp expect actual | |
484 | ' | |
485 | ||
fa21b602 | 486 | test_done |