]>
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 | 7 | |
1550bb6e | 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
10 | ||
fa21b602 | 11 | . ./test-lib.sh |
30825178 | 12 | . "$TEST_DIRECTORY"/lib-terminal.sh |
fa21b602 JK |
13 | |
14 | test_tick | |
ee3efaf6 AS |
15 | # Tested non-UTF-8 encoding |
16 | test_encoding="ISO8859-1" | |
17 | ||
17cc2ef1 AS |
18 | # String "added" in German |
19 | # (translated with Google Translate), | |
20 | # encoded in UTF-8, used as a commit log message below. | |
d928d810 AS |
21 | added_utf8_part=$(printf "\303\274") |
22 | added_utf8_part_iso88591=$(echo "$added_utf8_part" | iconv -f utf-8 -t $test_encoding) | |
23 | added=$(printf "added (hinzugef${added_utf8_part}gt) foo") | |
ee3efaf6 | 24 | added_iso88591=$(echo "$added" | iconv -f utf-8 -t $test_encoding) |
de6029a2 | 25 | # same but "changed" |
d928d810 AS |
26 | changed_utf8_part=$(printf "\303\244") |
27 | changed_utf8_part_iso88591=$(echo "$changed_utf8_part" | iconv -f utf-8 -t $test_encoding) | |
28 | changed=$(printf "changed (ge${changed_utf8_part}ndert) foo") | |
ee3efaf6 | 29 | changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding) |
de6029a2 | 30 | |
d928d810 AS |
31 | # Count of char to truncate |
32 | # Number is chosen so, that non-ACSII characters | |
33 | # (see $added_utf8_part and $changed_utf8_part) | |
34 | # fall into truncated parts of appropriate words both from left and right | |
35 | truncate_count=20 | |
36 | ||
fa21b602 | 37 | test_expect_success 'setup' ' |
77a6815d AS |
38 | : >foo && |
39 | git add foo && | |
ee3efaf6 | 40 | git config i18n.commitEncoding $test_encoding && |
e6ce2be2 | 41 | echo "$added_iso88591" | git commit -F - && |
77a6815d AS |
42 | head1=$(git rev-parse --verify HEAD) && |
43 | head1_short=$(git rev-parse --verify --short $head1) && | |
d1c5ae78 | 44 | head1_short4=$(git rev-parse --verify --short=4 $head1) && |
77a6815d AS |
45 | tree1=$(git rev-parse --verify HEAD:) && |
46 | tree1_short=$(git rev-parse --verify --short $tree1) && | |
de6029a2 | 47 | echo "$changed" > foo && |
e6ce2be2 | 48 | echo "$changed_iso88591" | git commit -a -F - && |
77a6815d AS |
49 | head2=$(git rev-parse --verify HEAD) && |
50 | head2_short=$(git rev-parse --verify --short $head2) && | |
d1c5ae78 | 51 | head2_short4=$(git rev-parse --verify --short=4 $head2) && |
77a6815d | 52 | tree2=$(git rev-parse --verify HEAD:) && |
99094a7a | 53 | tree2_short=$(git rev-parse --verify --short $tree2) && |
de6029a2 | 54 | git config --unset i18n.commitEncoding |
fa21b602 JK |
55 | ' |
56 | ||
d1c5ae78 | 57 | # usage: test_format [argument...] name format_string [failure] <expected_output |
2581ad5e | 58 | test_format () { |
d1c5ae78 | 59 | local args= |
60 | while true | |
61 | do | |
62 | case "$1" in | |
63 | --*) | |
64 | args="$args $1" | |
65 | shift;; | |
66 | *) | |
67 | break;; | |
68 | esac | |
69 | done | |
fa21b602 | 70 | cat >expect.$1 |
17cc2ef1 | 71 | test_expect_${3:-success} "format $1" " |
d1c5ae78 | 72 | git rev-list $args --pretty=format:'$2' main >output.$1 && |
73 | test_cmp expect.$1 output.$1 | |
74 | " | |
75 | } | |
76 | ||
77 | # usage: test_pretty [argument...] name format_name [failure] <expected_output | |
78 | test_pretty () { | |
79 | local args= | |
80 | while true | |
81 | do | |
82 | case "$1" in | |
83 | --*) | |
84 | args="$args $1" | |
85 | shift;; | |
86 | *) | |
87 | break;; | |
88 | esac | |
89 | done | |
90 | cat >expect.$1 | |
91 | test_expect_${3:-success} "pretty $1 (without --no-commit-header)" " | |
92 | git rev-list $args --pretty='$2' main >output.$1 && | |
93 | test_cmp expect.$1 output.$1 | |
94 | " | |
95 | test_expect_${3:-success} "pretty $1 (with --no-commit-header)" " | |
96 | git rev-list $args --no-commit-header --pretty='$2' main >output.$1 && | |
17cc2ef1 AS |
97 | test_cmp expect.$1 output.$1 |
98 | " | |
fa21b602 JK |
99 | } |
100 | ||
30825178 | 101 | # Feed to --format to provide predictable colored sequences. |
18fb7ffc JK |
102 | BASIC_COLOR='%Credfoo%Creset' |
103 | COLOR='%C(red)foo%C(reset)' | |
30825178 | 104 | AUTO_COLOR='%C(auto,red)foo%C(auto,reset)' |
18fb7ffc | 105 | ALWAYS_COLOR='%C(always,red)foo%C(always,reset)' |
30825178 | 106 | has_color () { |
097b681b JK |
107 | test_decode_color <"$1" >decoded && |
108 | echo "<RED>foo<RESET>" >expect && | |
109 | test_cmp expect decoded | |
30825178 JH |
110 | } |
111 | ||
112 | has_no_color () { | |
113 | echo foo >expect && | |
114 | test_cmp expect "$1" | |
115 | } | |
116 | ||
77a6815d AS |
117 | test_format percent %%h <<EOF |
118 | commit $head2 | |
0a0416a3 | 119 | %h |
77a6815d | 120 | commit $head1 |
0a0416a3 JK |
121 | %h |
122 | EOF | |
123 | ||
77a6815d AS |
124 | test_format hash %H%n%h <<EOF |
125 | commit $head2 | |
126 | $head2 | |
127 | $head2_short | |
128 | commit $head1 | |
129 | $head1 | |
130 | $head1_short | |
fa21b602 JK |
131 | EOF |
132 | ||
d1c5ae78 | 133 | test_format --no-commit-header hash-no-header %H%n%h <<EOF |
134 | $head2 | |
135 | $head2_short | |
136 | $head1 | |
137 | $head1_short | |
138 | EOF | |
139 | ||
140 | test_format --abbrev-commit --abbrev=0 --no-commit-header hash-no-header-abbrev %H%n%h <<EOF | |
141 | $head2 | |
142 | $head2_short4 | |
143 | $head1 | |
144 | $head1_short4 | |
145 | EOF | |
146 | ||
77a6815d AS |
147 | test_format tree %T%n%t <<EOF |
148 | commit $head2 | |
149 | $tree2 | |
150 | $tree2_short | |
151 | commit $head1 | |
152 | $tree1 | |
153 | $tree1_short | |
fa21b602 JK |
154 | EOF |
155 | ||
77a6815d AS |
156 | test_format parents %P%n%p <<EOF |
157 | commit $head2 | |
158 | $head1 | |
159 | $head1_short | |
160 | commit $head1 | |
542e165c JH |
161 | |
162 | ||
fa21b602 JK |
163 | EOF |
164 | ||
165 | # we don't test relative here | |
d8b8217c | 166 | test_format author %an%n%ae%n%al%n%ad%n%aD%n%at <<EOF |
77a6815d | 167 | commit $head2 |
2ae4944a PB |
168 | $GIT_AUTHOR_NAME |
169 | $GIT_AUTHOR_EMAIL | |
d8b8217c | 170 | $TEST_AUTHOR_LOCALNAME |
fa21b602 JK |
171 | Thu Apr 7 15:13:13 2005 -0700 |
172 | Thu, 7 Apr 2005 15:13:13 -0700 | |
173 | 1112911993 | |
77a6815d | 174 | commit $head1 |
2ae4944a PB |
175 | $GIT_AUTHOR_NAME |
176 | $GIT_AUTHOR_EMAIL | |
d8b8217c | 177 | $TEST_AUTHOR_LOCALNAME |
fa21b602 JK |
178 | Thu Apr 7 15:13:13 2005 -0700 |
179 | Thu, 7 Apr 2005 15:13:13 -0700 | |
180 | 1112911993 | |
181 | EOF | |
182 | ||
d8b8217c | 183 | test_format committer %cn%n%ce%n%cl%n%cd%n%cD%n%ct <<EOF |
77a6815d | 184 | commit $head2 |
2ae4944a PB |
185 | $GIT_COMMITTER_NAME |
186 | $GIT_COMMITTER_EMAIL | |
d8b8217c | 187 | $TEST_COMMITTER_LOCALNAME |
fa21b602 JK |
188 | Thu Apr 7 15:13:13 2005 -0700 |
189 | Thu, 7 Apr 2005 15:13:13 -0700 | |
190 | 1112911993 | |
77a6815d | 191 | commit $head1 |
2ae4944a PB |
192 | $GIT_COMMITTER_NAME |
193 | $GIT_COMMITTER_EMAIL | |
d8b8217c | 194 | $TEST_COMMITTER_LOCALNAME |
fa21b602 JK |
195 | Thu Apr 7 15:13:13 2005 -0700 |
196 | Thu, 7 Apr 2005 15:13:13 -0700 | |
197 | 1112911993 | |
198 | EOF | |
199 | ||
77a6815d AS |
200 | test_format encoding %e <<EOF |
201 | commit $head2 | |
ee3efaf6 | 202 | $test_encoding |
77a6815d | 203 | commit $head1 |
ee3efaf6 | 204 | $test_encoding |
fa21b602 JK |
205 | EOF |
206 | ||
ecaee805 | 207 | test_format subject %s <<EOF |
77a6815d | 208 | commit $head2 |
de6029a2 | 209 | $changed |
77a6815d | 210 | commit $head1 |
de6029a2 | 211 | $added |
fa21b602 JK |
212 | EOF |
213 | ||
d928d810 AS |
214 | test_format subject-truncated "%<($truncate_count,trunc)%s" <<EOF |
215 | commit $head2 | |
216 | changed (ge${changed_utf8_part}ndert).. | |
217 | commit $head1 | |
218 | added (hinzugef${added_utf8_part}gt.. | |
219 | EOF | |
220 | ||
77a6815d AS |
221 | test_format body %b <<EOF |
222 | commit $head2 | |
223 | commit $head1 | |
fa21b602 JK |
224 | EOF |
225 | ||
ecaee805 | 226 | test_format raw-body %B <<EOF |
77a6815d | 227 | commit $head2 |
de6029a2 | 228 | $changed |
1367b12a | 229 | |
77a6815d | 230 | commit $head1 |
de6029a2 | 231 | $added |
1367b12a EB |
232 | |
233 | EOF | |
234 | ||
d1c5ae78 | 235 | test_format --no-commit-header raw-body-no-header %B <<EOF |
236 | $changed | |
237 | ||
238 | $added | |
239 | ||
240 | EOF | |
241 | ||
242 | test_pretty oneline oneline <<EOF | |
243 | $head2 $changed | |
244 | $head1 $added | |
245 | EOF | |
246 | ||
247 | test_pretty short short <<EOF | |
248 | commit $head2 | |
249 | Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> | |
250 | ||
251 | $changed | |
252 | ||
253 | commit $head1 | |
254 | Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> | |
255 | ||
256 | $added | |
257 | ||
258 | EOF | |
259 | ||
097b681b JK |
260 | test_expect_success 'basic colors' ' |
261 | cat >expect <<-EOF && | |
262 | commit $head2 | |
263 | <RED>foo<GREEN>bar<BLUE>baz<RESET>xyzzy | |
264 | EOF | |
265 | format="%Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy" && | |
1550bb6e | 266 | git rev-list --color --format="$format" -1 main >actual.raw && |
097b681b JK |
267 | test_decode_color <actual.raw >actual && |
268 | test_cmp expect actual | |
269 | ' | |
fa21b602 | 270 | |
ad6f028f | 271 | test_expect_success '%S is not a placeholder for rev-list yet' ' |
1550bb6e | 272 | git rev-list --format="%S" -1 main | grep "%S" |
ad6f028f IT |
273 | ' |
274 | ||
097b681b JK |
275 | test_expect_success 'advanced colors' ' |
276 | cat >expect <<-EOF && | |
277 | commit $head2 | |
278 | <BOLD;RED;BYELLOW>foo<RESET> | |
279 | EOF | |
280 | format="%C(red yellow bold)foo%C(reset)" && | |
1550bb6e | 281 | git rev-list --color --format="$format" -1 main >actual.raw && |
097b681b JK |
282 | test_decode_color <actual.raw >actual && |
283 | test_cmp expect actual | |
284 | ' | |
c002922a | 285 | |
18fb7ffc JK |
286 | for spec in \ |
287 | "%Cred:$BASIC_COLOR" \ | |
288 | "%C(...):$COLOR" \ | |
289 | "%C(auto,...):$AUTO_COLOR" | |
290 | do | |
291 | desc=${spec%%:*} | |
292 | color=${spec#*:} | |
293 | test_expect_success "$desc does not enable color by default" ' | |
294 | git log --format=$color -1 >actual && | |
295 | has_no_color actual | |
296 | ' | |
30825178 | 297 | |
1d4b12fe JK |
298 | test_expect_success "$desc enables colors for color.diff" ' |
299 | git -c color.diff=always log --format=$color -1 >actual && | |
300 | has_color actual | |
301 | ' | |
302 | ||
303 | test_expect_success "$desc enables colors for color.ui" ' | |
304 | git -c color.ui=always log --format=$color -1 >actual && | |
305 | has_color actual | |
306 | ' | |
307 | ||
18fb7ffc JK |
308 | test_expect_success "$desc respects --color" ' |
309 | git log --format=$color -1 --color >actual && | |
310 | has_color actual | |
311 | ' | |
30825178 | 312 | |
1d4b12fe JK |
313 | test_expect_success "$desc respects --no-color" ' |
314 | git -c color.ui=always log --format=$color -1 --no-color >actual && | |
315 | has_no_color actual | |
316 | ' | |
317 | ||
18fb7ffc | 318 | test_expect_success TTY "$desc respects --color=auto (stdout is tty)" ' |
e433749d | 319 | test_terminal git log --format=$color -1 --color=auto >actual && |
18fb7ffc JK |
320 | has_color actual |
321 | ' | |
322 | ||
323 | test_expect_success "$desc respects --color=auto (stdout not tty)" ' | |
324 | ( | |
325 | TERM=vt100 && export TERM && | |
326 | git log --format=$color -1 --color=auto >actual && | |
327 | has_no_color actual | |
328 | ) | |
329 | ' | |
330 | done | |
331 | ||
332 | test_expect_success '%C(always,...) enables color even without tty' ' | |
333 | git log --format=$ALWAYS_COLOR -1 >actual && | |
334 | has_color actual | |
30825178 JH |
335 | ' |
336 | ||
b15a3e00 | 337 | test_expect_success '%C(auto) respects --color' ' |
097b681b JK |
338 | git log --color --format="%C(auto)%H" -1 >actual.raw && |
339 | test_decode_color <actual.raw >actual && | |
340 | echo "<YELLOW>$(git rev-parse HEAD)<RESET>" >expect && | |
b15a3e00 ET |
341 | test_cmp expect actual |
342 | ' | |
343 | ||
344 | test_expect_success '%C(auto) respects --no-color' ' | |
345 | git log --no-color --format="%C(auto)%H" -1 >actual && | |
346 | git rev-parse HEAD >expect && | |
347 | test_cmp expect actual | |
348 | ' | |
349 | ||
d75dfb10 JK |
350 | test_expect_success 'rev-list %C(auto,...) respects --color' ' |
351 | git rev-list --color --format="%C(auto,green)foo%C(auto,reset)" \ | |
352 | -1 HEAD >actual.raw && | |
353 | test_decode_color <actual.raw >actual && | |
354 | cat >expect <<-EOF && | |
355 | commit $(git rev-parse HEAD) | |
356 | <GREEN>foo<RESET> | |
357 | EOF | |
358 | test_cmp expect actual | |
359 | ' | |
360 | ||
ee3efaf6 | 361 | iconv -f utf-8 -t $test_encoding > commit-msg <<EOF |
03bcaaca JK |
362 | Test printing of complex bodies |
363 | ||
364 | This commit message is much longer than the others, | |
ee3efaf6 AS |
365 | and it will be encoded in $test_encoding. We should therefore |
366 | include an ISO8859 character: ¡bueno! | |
03bcaaca | 367 | EOF |
77a6815d | 368 | |
03bcaaca | 369 | test_expect_success 'setup complex body' ' |
ee3efaf6 | 370 | git config i18n.commitencoding $test_encoding && |
77a6815d AS |
371 | echo change2 >foo && git commit -a -F commit-msg && |
372 | head3=$(git rev-parse --verify HEAD) && | |
0fe6df3c | 373 | head3_short=$(git rev-parse --short $head3) |
03bcaaca JK |
374 | ' |
375 | ||
77a6815d AS |
376 | test_format complex-encoding %e <<EOF |
377 | commit $head3 | |
ee3efaf6 | 378 | $test_encoding |
77a6815d | 379 | commit $head2 |
ee3efaf6 | 380 | $test_encoding |
77a6815d | 381 | commit $head1 |
ee3efaf6 | 382 | $test_encoding |
03bcaaca JK |
383 | EOF |
384 | ||
ecaee805 | 385 | test_format complex-subject %s <<EOF |
77a6815d | 386 | commit $head3 |
03bcaaca | 387 | Test printing of complex bodies |
77a6815d | 388 | commit $head2 |
0fe6df3c | 389 | $changed_iso88591 |
77a6815d | 390 | commit $head1 |
0fe6df3c | 391 | $added_iso88591 |
03bcaaca JK |
392 | EOF |
393 | ||
7d509878 | 394 | test_format complex-subject-trunc "%<($truncate_count,trunc)%s" <<EOF |
d928d810 AS |
395 | commit $head3 |
396 | Test printing of c.. | |
397 | commit $head2 | |
398 | changed (ge${changed_utf8_part_iso88591}ndert).. | |
399 | commit $head1 | |
400 | added (hinzugef${added_utf8_part_iso88591}gt.. | |
401 | EOF | |
402 | ||
7d509878 | 403 | test_format complex-subject-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF |
d928d810 AS |
404 | commit $head3 |
405 | Test prin..ex bodies | |
406 | commit $head2 | |
407 | changed (..dert) foo | |
408 | commit $head1 | |
409 | added (hi..f${added_utf8_part_iso88591}gt) foo | |
410 | EOF | |
411 | ||
7d509878 | 412 | test_format complex-subject-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF |
d928d810 AS |
413 | commit $head3 |
414 | .. of complex bodies | |
415 | commit $head2 | |
416 | ..ged (ge${changed_utf8_part_iso88591}ndert) foo | |
417 | commit $head1 | |
418 | .. (hinzugef${added_utf8_part_iso88591}gt) foo | |
419 | EOF | |
420 | ||
2ba31ebd | 421 | test_expect_success 'setup expected messages (for test %b)' ' |
0fe6df3c AS |
422 | cat <<-EOF >expected.utf-8 && |
423 | commit $head3 | |
424 | This commit message is much longer than the others, | |
ee3efaf6 AS |
425 | and it will be encoded in $test_encoding. We should therefore |
426 | include an ISO8859 character: ¡bueno! | |
0fe6df3c AS |
427 | |
428 | commit $head2 | |
429 | commit $head1 | |
430 | EOF | |
ee3efaf6 | 431 | iconv -f utf-8 -t $test_encoding expected.utf-8 >expected.ISO8859-1 |
0fe6df3c AS |
432 | ' |
433 | ||
ee3efaf6 | 434 | test_format complex-body %b <expected.ISO8859-1 |
03bcaaca | 435 | |
0fe6df3c AS |
436 | # Git uses i18n.commitEncoding if no i18n.logOutputEncoding set |
437 | # so unset i18n.commitEncoding to test encoding conversion | |
438 | git config --unset i18n.commitEncoding | |
439 | ||
440 | test_format complex-subject-commitencoding-unset %s <<EOF | |
441 | commit $head3 | |
442 | Test printing of complex bodies | |
77a6815d | 443 | commit $head2 |
0fe6df3c | 444 | $changed |
77a6815d | 445 | commit $head1 |
0fe6df3c | 446 | $added |
03bcaaca JK |
447 | EOF |
448 | ||
d928d810 AS |
449 | test_format complex-subject-commitencoding-unset-trunc "%<($truncate_count,trunc)%s" <<EOF |
450 | commit $head3 | |
451 | Test printing of c.. | |
452 | commit $head2 | |
453 | changed (ge${changed_utf8_part}ndert).. | |
454 | commit $head1 | |
455 | added (hinzugef${added_utf8_part}gt.. | |
456 | EOF | |
457 | ||
458 | test_format complex-subject-commitencoding-unset-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF | |
459 | commit $head3 | |
460 | Test prin..ex bodies | |
461 | commit $head2 | |
462 | changed (..dert) foo | |
463 | commit $head1 | |
464 | added (hi..f${added_utf8_part}gt) foo | |
465 | EOF | |
466 | ||
467 | test_format complex-subject-commitencoding-unset-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF | |
468 | commit $head3 | |
469 | .. of complex bodies | |
470 | commit $head2 | |
471 | ..ged (ge${changed_utf8_part}ndert) foo | |
472 | commit $head1 | |
473 | .. (hinzugef${added_utf8_part}gt) foo | |
474 | EOF | |
475 | ||
0fe6df3c AS |
476 | test_format complex-body-commitencoding-unset %b <expected.utf-8 |
477 | ||
9130ac9f | 478 | test_expect_success '%x00 shows NUL' ' |
77a6815d | 479 | echo >expect commit $head3 && |
9130ac9f JK |
480 | echo >>expect fooQbar && |
481 | git rev-list -1 --format=foo%x00bar HEAD >actual.nul && | |
482 | nul_to_q <actual.nul >actual && | |
483 | test_cmp expect actual | |
484 | ' | |
485 | ||
d36f8679 JK |
486 | test_expect_success '%ad respects --date=' ' |
487 | echo 2005-04-07 >expect.ad-short && | |
1550bb6e | 488 | git log -1 --date=short --pretty=tformat:%ad >output.ad-short main && |
d36f8679 JK |
489 | test_cmp expect.ad-short output.ad-short |
490 | ' | |
491 | ||
f7ab5c79 JH |
492 | test_expect_success 'empty email' ' |
493 | test_tick && | |
494 | C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) && | |
495 | A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) && | |
8ddfce71 | 496 | test "$A" = "$GIT_AUTHOR_NAME,,Thu Apr 7 15:14:13 2005 -0700" |
f7ab5c79 JH |
497 | ' |
498 | ||
9fa708da JH |
499 | test_expect_success 'del LF before empty (1)' ' |
500 | git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD^^ >actual && | |
3fb0459b | 501 | test_line_count = 2 actual |
9fa708da JH |
502 | ' |
503 | ||
504 | test_expect_success 'del LF before empty (2)' ' | |
505 | git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD >actual && | |
3fb0459b | 506 | test_line_count = 6 actual && |
9fa708da JH |
507 | grep "^$" actual |
508 | ' | |
509 | ||
510 | test_expect_success 'add LF before non-empty (1)' ' | |
511 | git show -s --pretty=format:"%s%+b%nThanks%n" HEAD^^ >actual && | |
3fb0459b | 512 | test_line_count = 2 actual |
9fa708da JH |
513 | ' |
514 | ||
515 | test_expect_success 'add LF before non-empty (2)' ' | |
516 | git show -s --pretty=format:"%s%+b%nThanks%n" HEAD >actual && | |
3fb0459b | 517 | test_line_count = 6 actual && |
9fa708da JH |
518 | grep "^$" actual |
519 | ' | |
520 | ||
7b88176e MG |
521 | test_expect_success 'add SP before non-empty (1)' ' |
522 | git show -s --pretty=format:"%s% bThanks" HEAD^^ >actual && | |
de6029a2 | 523 | test $(wc -w <actual) = 3 |
7b88176e MG |
524 | ' |
525 | ||
526 | test_expect_success 'add SP before non-empty (2)' ' | |
527 | git show -s --pretty=format:"%s% sThanks" HEAD^^ >actual && | |
de6029a2 | 528 | test $(wc -w <actual) = 6 |
7b88176e MG |
529 | ' |
530 | ||
c1977021 WP |
531 | test_expect_success '--abbrev' ' |
532 | echo SHORT SHORT SHORT >expect2 && | |
533 | echo LONG LONG LONG >expect3 && | |
534 | git log -1 --format="%h %h %h" HEAD >actual1 && | |
535 | git log -1 --abbrev=5 --format="%h %h %h" HEAD >actual2 && | |
536 | git log -1 --abbrev=5 --format="%H %H %H" HEAD >actual3 && | |
2ece6ad2 | 537 | sed -e "s/$OID_REGEX/LONG/g" -e "s/$_x05/SHORT/g" <actual2 >fuzzy2 && |
538 | sed -e "s/$OID_REGEX/LONG/g" -e "s/$_x05/SHORT/g" <actual3 >fuzzy3 && | |
c1977021 WP |
539 | test_cmp expect2 fuzzy2 && |
540 | test_cmp expect3 fuzzy3 && | |
541 | ! test_cmp actual1 actual2 | |
542 | ' | |
543 | ||
544 | test_expect_success '%H is not affected by --abbrev-commit' ' | |
edf04243 | 545 | expected=$(($(test_oid hexsz) + 1)) && |
c1977021 WP |
546 | git log -1 --format=%H --abbrev-commit --abbrev=20 HEAD >actual && |
547 | len=$(wc -c <actual) && | |
edf04243 | 548 | test $len = $expected |
c1977021 WP |
549 | ' |
550 | ||
551 | test_expect_success '%h is not affected by --abbrev-commit' ' | |
552 | git log -1 --format=%h --abbrev-commit --abbrev=20 HEAD >actual && | |
553 | len=$(wc -c <actual) && | |
554 | test $len = 21 | |
555 | ' | |
556 | ||
8f8f5476 TR |
557 | test_expect_success '"%h %gD: %gs" is same as git-reflog' ' |
558 | git reflog >expect && | |
559 | git log -g --format="%h %gD: %gs" >actual && | |
560 | test_cmp expect actual | |
561 | ' | |
562 | ||
563 | test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' ' | |
564 | git reflog --date=raw >expect && | |
565 | git log -g --format="%h %gD: %gs" --date=raw >actual && | |
566 | test_cmp expect actual | |
567 | ' | |
568 | ||
c1977021 WP |
569 | test_expect_success '"%h %gD: %gs" is same as git-reflog (with --abbrev)' ' |
570 | git reflog --abbrev=13 --date=raw >expect && | |
571 | git log -g --abbrev=13 --format="%h %gD: %gs" --date=raw >actual && | |
572 | test_cmp expect actual | |
573 | ' | |
574 | ||
8f8f5476 | 575 | test_expect_success '%gd shortens ref name' ' |
1550bb6e JS |
576 | echo "main@{0}" >expect.gd-short && |
577 | git log -g -1 --format=%gd refs/heads/main >actual.gd-short && | |
8f8f5476 TR |
578 | test_cmp expect.gd-short actual.gd-short |
579 | ' | |
580 | ||
cd1957f5 | 581 | test_expect_success 'reflog identity' ' |
2ae4944a | 582 | echo "$GIT_COMMITTER_NAME:$GIT_COMMITTER_EMAIL" >expect && |
cd1957f5 JK |
583 | git log -g -1 --format="%gn:%ge" >actual && |
584 | test_cmp expect actual | |
585 | ' | |
586 | ||
1fb5fdd2 | 587 | test_expect_success 'oneline with empty message' ' |
7b6ad979 EN |
588 | git commit --allow-empty --cleanup=verbatim -m "$LF" && |
589 | git commit --allow-empty --allow-empty-message && | |
f02dd06e | 590 | git rev-list --oneline HEAD >test.txt && |
3fb0459b SL |
591 | test_line_count = 5 test.txt && |
592 | git rev-list --oneline --graph HEAD >testg.txt && | |
593 | test_line_count = 5 testg.txt | |
1fb5fdd2 EFL |
594 | ' |
595 | ||
d9955fd6 JK |
596 | test_expect_success 'single-character name is parsed correctly' ' |
597 | git commit --author="a <a@example.com>" --allow-empty -m foo && | |
598 | echo "a <a@example.com>" >expect && | |
599 | git log -1 --format="%an <%ae>" >actual && | |
600 | test_cmp expect actual | |
601 | ' | |
602 | ||
958b2eb2 JK |
603 | test_expect_success 'unused %G placeholders are passed through' ' |
604 | echo "%GX %G" >expect && | |
605 | git log -1 --format="%GX %G" >actual && | |
606 | test_cmp expect actual | |
607 | ' | |
608 | ||
fa21b602 | 609 | test_done |