blob: 573eb97a0f7f06e45d3358e65be8b55816ea47b3 [file] [log] [blame]
Jeff Kingfa21b602007-03-27 20:08:28 -04001#!/bin/sh
2
Alexey Shumkinde6029a2013-06-26 14:19:49 +04003# Copyright (c) 2009 Jens Lehmann
4# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
5
Junio C Hamano5be60072007-07-02 22:52:14 -07006test_description='git rev-list --pretty=format test'
Jeff Kingfa21b602007-03-27 20:08:28 -04007
Johannes Schindelin1550bb62020-11-18 23:44:36 +00008GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00009export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
Jeff Kingfa21b602007-03-27 20:08:28 -040011. ./test-lib.sh
Junio C Hamano30825172012-12-17 17:56:49 -050012. "$TEST_DIRECTORY"/lib-terminal.sh
Jeff Kingfa21b602007-03-27 20:08:28 -040013
14test_tick
Alexey Shumkinee3efaf2014-05-21 17:20:04 +040015# Tested non-UTF-8 encoding
16test_encoding="ISO8859-1"
17
Alexey Shumkin17cc2ef2013-07-05 16:01:48 +040018# String "added" in German
19# (translated with Google Translate),
20# encoded in UTF-8, used as a commit log message below.
Alexey Shumkind928d812014-05-21 17:20:06 +040021added_utf8_part=$(printf "\303\274")
22added_utf8_part_iso88591=$(echo "$added_utf8_part" | iconv -f utf-8 -t $test_encoding)
23added=$(printf "added (hinzugef${added_utf8_part}gt) foo")
Alexey Shumkinee3efaf2014-05-21 17:20:04 +040024added_iso88591=$(echo "$added" | iconv -f utf-8 -t $test_encoding)
Alexey Shumkinde6029a2013-06-26 14:19:49 +040025# same but "changed"
Alexey Shumkind928d812014-05-21 17:20:06 +040026changed_utf8_part=$(printf "\303\244")
27changed_utf8_part_iso88591=$(echo "$changed_utf8_part" | iconv -f utf-8 -t $test_encoding)
28changed=$(printf "changed (ge${changed_utf8_part}ndert) foo")
Alexey Shumkinee3efaf2014-05-21 17:20:04 +040029changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding)
Alexey Shumkinde6029a2013-06-26 14:19:49 +040030
Alexey Shumkind928d812014-05-21 17:20:06 +040031# 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
35truncate_count=20
36
Jeff Kingfa21b602007-03-27 20:08:28 -040037test_expect_success 'setup' '
Alexey Shumkin77a68152013-06-26 14:19:46 +040038 : >foo &&
39 git add foo &&
Alexey Shumkinee3efaf2014-05-21 17:20:04 +040040 git config i18n.commitEncoding $test_encoding &&
Pat Thoytse6ce2be2013-09-02 15:44:54 +010041 echo "$added_iso88591" | git commit -F - &&
Alexey Shumkin77a68152013-06-26 14:19:46 +040042 head1=$(git rev-parse --verify HEAD) &&
43 head1_short=$(git rev-parse --verify --short $head1) &&
brian m. carlsond1c5ae72021-07-11 21:55:10 +000044 head1_short4=$(git rev-parse --verify --short=4 $head1) &&
Alexey Shumkin77a68152013-06-26 14:19:46 +040045 tree1=$(git rev-parse --verify HEAD:) &&
46 tree1_short=$(git rev-parse --verify --short $tree1) &&
Alexey Shumkinde6029a2013-06-26 14:19:49 +040047 echo "$changed" > foo &&
Pat Thoytse6ce2be2013-09-02 15:44:54 +010048 echo "$changed_iso88591" | git commit -a -F - &&
Alexey Shumkin77a68152013-06-26 14:19:46 +040049 head2=$(git rev-parse --verify HEAD) &&
50 head2_short=$(git rev-parse --verify --short $head2) &&
brian m. carlsond1c5ae72021-07-11 21:55:10 +000051 head2_short4=$(git rev-parse --verify --short=4 $head2) &&
Alexey Shumkin77a68152013-06-26 14:19:46 +040052 tree2=$(git rev-parse --verify HEAD:) &&
Jeff King99094a72015-03-20 06:07:15 -040053 tree2_short=$(git rev-parse --verify --short $tree2) &&
Alexey Shumkinde6029a2013-06-26 14:19:49 +040054 git config --unset i18n.commitEncoding
Jeff Kingfa21b602007-03-27 20:08:28 -040055'
56
brian m. carlsond1c5ae72021-07-11 21:55:10 +000057# usage: test_format [argument...] name format_string [failure] <expected_output
Junio C Hamano2581ad52012-12-17 17:56:23 -050058test_format () {
brian m. carlsond1c5ae72021-07-11 21:55:10 +000059 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
Jeff Kingfa21b602007-03-27 20:08:28 -040070 cat >expect.$1
Alexey Shumkin17cc2ef2013-07-05 16:01:48 +040071 test_expect_${3:-success} "format $1" "
brian m. carlsond1c5ae72021-07-11 21:55:10 +000072 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
78test_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 &&
Alexey Shumkin17cc2ef2013-07-05 16:01:48 +040097 test_cmp expect.$1 output.$1
98 "
Jeff Kingfa21b602007-03-27 20:08:28 -040099}
100
Junio C Hamano30825172012-12-17 17:56:49 -0500101# Feed to --format to provide predictable colored sequences.
Jeff King18fb7ff2017-07-13 11:08:46 -0400102BASIC_COLOR='%Credfoo%Creset'
103COLOR='%C(red)foo%C(reset)'
Junio C Hamano30825172012-12-17 17:56:49 -0500104AUTO_COLOR='%C(auto,red)foo%C(auto,reset)'
Jeff King18fb7ff2017-07-13 11:08:46 -0400105ALWAYS_COLOR='%C(always,red)foo%C(always,reset)'
Junio C Hamano30825172012-12-17 17:56:49 -0500106has_color () {
Jeff King097b6812017-07-13 10:58:41 -0400107 test_decode_color <"$1" >decoded &&
108 echo "<RED>foo<RESET>" >expect &&
109 test_cmp expect decoded
Junio C Hamano30825172012-12-17 17:56:49 -0500110}
111
112has_no_color () {
113 echo foo >expect &&
114 test_cmp expect "$1"
115}
116
Alexey Shumkin77a68152013-06-26 14:19:46 +0400117test_format percent %%h <<EOF
118commit $head2
Jeff King0a0416a2010-01-13 12:35:31 -0500119%h
Alexey Shumkin77a68152013-06-26 14:19:46 +0400120commit $head1
Jeff King0a0416a2010-01-13 12:35:31 -0500121%h
122EOF
123
Alexey Shumkin77a68152013-06-26 14:19:46 +0400124test_format hash %H%n%h <<EOF
125commit $head2
126$head2
127$head2_short
128commit $head1
129$head1
130$head1_short
Jeff Kingfa21b602007-03-27 20:08:28 -0400131EOF
132
brian m. carlsond1c5ae72021-07-11 21:55:10 +0000133test_format --no-commit-header hash-no-header %H%n%h <<EOF
134$head2
135$head2_short
136$head1
137$head1_short
138EOF
139
140test_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
145EOF
146
Alexey Shumkin77a68152013-06-26 14:19:46 +0400147test_format tree %T%n%t <<EOF
148commit $head2
149$tree2
150$tree2_short
151commit $head1
152$tree1
153$tree1_short
Jeff Kingfa21b602007-03-27 20:08:28 -0400154EOF
155
Alexey Shumkin77a68152013-06-26 14:19:46 +0400156test_format parents %P%n%p <<EOF
157commit $head2
158$head1
159$head1_short
160commit $head1
Junio C Hamano542e1652007-03-28 13:33:37 -0700161
162
Jeff Kingfa21b602007-03-27 20:08:28 -0400163EOF
164
165# we don't test relative here
Prarit Bhargavad8b82172019-10-29 08:09:14 -0400166test_format author %an%n%ae%n%al%n%ad%n%aD%n%at <<EOF
Alexey Shumkin77a68152013-06-26 14:19:46 +0400167commit $head2
Prarit Bhargava2ae49442019-10-24 19:36:15 -0400168$GIT_AUTHOR_NAME
169$GIT_AUTHOR_EMAIL
Prarit Bhargavad8b82172019-10-29 08:09:14 -0400170$TEST_AUTHOR_LOCALNAME
Jeff Kingfa21b602007-03-27 20:08:28 -0400171Thu Apr 7 15:13:13 2005 -0700
172Thu, 7 Apr 2005 15:13:13 -0700
1731112911993
Alexey Shumkin77a68152013-06-26 14:19:46 +0400174commit $head1
Prarit Bhargava2ae49442019-10-24 19:36:15 -0400175$GIT_AUTHOR_NAME
176$GIT_AUTHOR_EMAIL
Prarit Bhargavad8b82172019-10-29 08:09:14 -0400177$TEST_AUTHOR_LOCALNAME
Jeff Kingfa21b602007-03-27 20:08:28 -0400178Thu Apr 7 15:13:13 2005 -0700
179Thu, 7 Apr 2005 15:13:13 -0700
1801112911993
181EOF
182
Prarit Bhargavad8b82172019-10-29 08:09:14 -0400183test_format committer %cn%n%ce%n%cl%n%cd%n%cD%n%ct <<EOF
Alexey Shumkin77a68152013-06-26 14:19:46 +0400184commit $head2
Prarit Bhargava2ae49442019-10-24 19:36:15 -0400185$GIT_COMMITTER_NAME
186$GIT_COMMITTER_EMAIL
Prarit Bhargavad8b82172019-10-29 08:09:14 -0400187$TEST_COMMITTER_LOCALNAME
Jeff Kingfa21b602007-03-27 20:08:28 -0400188Thu Apr 7 15:13:13 2005 -0700
189Thu, 7 Apr 2005 15:13:13 -0700
1901112911993
Alexey Shumkin77a68152013-06-26 14:19:46 +0400191commit $head1
Prarit Bhargava2ae49442019-10-24 19:36:15 -0400192$GIT_COMMITTER_NAME
193$GIT_COMMITTER_EMAIL
Prarit Bhargavad8b82172019-10-29 08:09:14 -0400194$TEST_COMMITTER_LOCALNAME
Jeff Kingfa21b602007-03-27 20:08:28 -0400195Thu Apr 7 15:13:13 2005 -0700
196Thu, 7 Apr 2005 15:13:13 -0700
1971112911993
198EOF
199
Alexey Shumkin77a68152013-06-26 14:19:46 +0400200test_format encoding %e <<EOF
201commit $head2
Alexey Shumkinee3efaf2014-05-21 17:20:04 +0400202$test_encoding
Alexey Shumkin77a68152013-06-26 14:19:46 +0400203commit $head1
Alexey Shumkinee3efaf2014-05-21 17:20:04 +0400204$test_encoding
Jeff Kingfa21b602007-03-27 20:08:28 -0400205EOF
206
Alexey Shumkinecaee802013-06-26 14:19:50 +0400207test_format subject %s <<EOF
Alexey Shumkin77a68152013-06-26 14:19:46 +0400208commit $head2
Alexey Shumkinde6029a2013-06-26 14:19:49 +0400209$changed
Alexey Shumkin77a68152013-06-26 14:19:46 +0400210commit $head1
Alexey Shumkinde6029a2013-06-26 14:19:49 +0400211$added
Jeff Kingfa21b602007-03-27 20:08:28 -0400212EOF
213
Alexey Shumkind928d812014-05-21 17:20:06 +0400214test_format subject-truncated "%<($truncate_count,trunc)%s" <<EOF
215commit $head2
216changed (ge${changed_utf8_part}ndert)..
217commit $head1
218added (hinzugef${added_utf8_part}gt..
219EOF
220
Alexey Shumkin77a68152013-06-26 14:19:46 +0400221test_format body %b <<EOF
222commit $head2
223commit $head1
Jeff Kingfa21b602007-03-27 20:08:28 -0400224EOF
225
Alexey Shumkinecaee802013-06-26 14:19:50 +0400226test_format raw-body %B <<EOF
Alexey Shumkin77a68152013-06-26 14:19:46 +0400227commit $head2
Alexey Shumkinde6029a2013-06-26 14:19:49 +0400228$changed
Eli Barzilay1367b122010-03-24 22:51:52 -0400229
Alexey Shumkin77a68152013-06-26 14:19:46 +0400230commit $head1
Alexey Shumkinde6029a2013-06-26 14:19:49 +0400231$added
Eli Barzilay1367b122010-03-24 22:51:52 -0400232
233EOF
234
brian m. carlsond1c5ae72021-07-11 21:55:10 +0000235test_format --no-commit-header raw-body-no-header %B <<EOF
236$changed
237
238$added
239
240EOF
241
242test_pretty oneline oneline <<EOF
243$head2 $changed
244$head1 $added
245EOF
246
247test_pretty short short <<EOF
248commit $head2
249Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
250
251 $changed
252
253commit $head1
254Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
255
256 $added
257
258EOF
259
Jeff King097b6812017-07-13 10:58:41 -0400260test_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" &&
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000266 git rev-list --color --format="$format" -1 main >actual.raw &&
Jeff King097b6812017-07-13 10:58:41 -0400267 test_decode_color <actual.raw >actual &&
268 test_cmp expect actual
269'
Jeff Kingfa21b602007-03-27 20:08:28 -0400270
Issac Trottsad6f0282019-01-10 22:30:46 -0800271test_expect_success '%S is not a placeholder for rev-list yet' '
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000272 git rev-list --format="%S" -1 main | grep "%S"
Issac Trottsad6f0282019-01-10 22:30:46 -0800273'
274
Jeff King097b6812017-07-13 10:58:41 -0400275test_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)" &&
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000281 git rev-list --color --format="$format" -1 main >actual.raw &&
Jeff King097b6812017-07-13 10:58:41 -0400282 test_decode_color <actual.raw >actual &&
283 test_cmp expect actual
284'
Jeff Kingc0029222009-01-17 10:38:46 -0500285
Jeff King18fb7ff2017-07-13 11:08:46 -0400286for spec in \
287 "%Cred:$BASIC_COLOR" \
288 "%C(...):$COLOR" \
289 "%C(auto,...):$AUTO_COLOR"
290do
291 desc=${spec%%:*}
292 color=${spec#*:}
293 test_expect_success "$desc does not enable color by default" '
294 git log --format=$color -1 >actual &&
Junio C Hamano30825172012-12-17 17:56:49 -0500295 has_no_color actual
Jeff King18fb7ff2017-07-13 11:08:46 -0400296 '
297
Jeff King1d4b12f2017-10-13 13:23:41 -0400298 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
Jeff King18fb7ff2017-07-13 11:08:46 -0400308 test_expect_success "$desc respects --color" '
309 git log --format=$color -1 --color >actual &&
310 has_color actual
311 '
312
Jeff King1d4b12f2017-10-13 13:23:41 -0400313 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
Jeff King18fb7ff2017-07-13 11:08:46 -0400318 test_expect_success TTY "$desc respects --color=auto (stdout is tty)" '
Jeff Kinge4337492017-10-03 09:39:34 -0400319 test_terminal git log --format=$color -1 --color=auto >actual &&
Jeff King18fb7ff2017-07-13 11:08:46 -0400320 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 '
330done
331
332test_expect_success '%C(always,...) enables color even without tty' '
333 git log --format=$ALWAYS_COLOR -1 >actual &&
334 has_color actual
Junio C Hamano30825172012-12-17 17:56:49 -0500335'
336
Edward Thomsonb15a3e02016-05-26 22:46:10 -0500337test_expect_success '%C(auto) respects --color' '
Jeff King097b6812017-07-13 10:58:41 -0400338 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 &&
Edward Thomsonb15a3e02016-05-26 22:46:10 -0500341 test_cmp expect actual
342'
343
344test_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
Jeff Kingd75dfb12017-07-13 11:07:30 -0400350test_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
Alexey Shumkinee3efaf2014-05-21 17:20:04 +0400361iconv -f utf-8 -t $test_encoding > commit-msg <<EOF
Jeff King03bcaac2007-03-28 17:08:36 -0400362Test printing of complex bodies
363
364This commit message is much longer than the others,
Alexey Shumkinee3efaf2014-05-21 17:20:04 +0400365and it will be encoded in $test_encoding. We should therefore
366include an ISO8859 character: ¡bueno!
Jeff King03bcaac2007-03-28 17:08:36 -0400367EOF
Alexey Shumkin77a68152013-06-26 14:19:46 +0400368
Jeff King03bcaac2007-03-28 17:08:36 -0400369test_expect_success 'setup complex body' '
Alexey Shumkinee3efaf2014-05-21 17:20:04 +0400370 git config i18n.commitencoding $test_encoding &&
Alexey Shumkin77a68152013-06-26 14:19:46 +0400371 echo change2 >foo && git commit -a -F commit-msg &&
372 head3=$(git rev-parse --verify HEAD) &&
Alexey Shumkin0fe6df32013-07-05 16:01:49 +0400373 head3_short=$(git rev-parse --short $head3)
Jeff King03bcaac2007-03-28 17:08:36 -0400374'
375
Alexey Shumkin77a68152013-06-26 14:19:46 +0400376test_format complex-encoding %e <<EOF
377commit $head3
Alexey Shumkinee3efaf2014-05-21 17:20:04 +0400378$test_encoding
Alexey Shumkin77a68152013-06-26 14:19:46 +0400379commit $head2
Alexey Shumkinee3efaf2014-05-21 17:20:04 +0400380$test_encoding
Alexey Shumkin77a68152013-06-26 14:19:46 +0400381commit $head1
Alexey Shumkinee3efaf2014-05-21 17:20:04 +0400382$test_encoding
Jeff King03bcaac2007-03-28 17:08:36 -0400383EOF
384
Alexey Shumkinecaee802013-06-26 14:19:50 +0400385test_format complex-subject %s <<EOF
Alexey Shumkin77a68152013-06-26 14:19:46 +0400386commit $head3
Jeff King03bcaac2007-03-28 17:08:36 -0400387Test printing of complex bodies
Alexey Shumkin77a68152013-06-26 14:19:46 +0400388commit $head2
Alexey Shumkin0fe6df32013-07-05 16:01:49 +0400389$changed_iso88591
390commit $head1
391$added_iso88591
392EOF
393
Alexey Shumkin7d509872014-05-21 17:20:07 +0400394test_format complex-subject-trunc "%<($truncate_count,trunc)%s" <<EOF
Alexey Shumkind928d812014-05-21 17:20:06 +0400395commit $head3
396Test printing of c..
397commit $head2
398changed (ge${changed_utf8_part_iso88591}ndert)..
399commit $head1
400added (hinzugef${added_utf8_part_iso88591}gt..
401EOF
402
Alexey Shumkin7d509872014-05-21 17:20:07 +0400403test_format complex-subject-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF
Alexey Shumkind928d812014-05-21 17:20:06 +0400404commit $head3
405Test prin..ex bodies
406commit $head2
407changed (..dert) foo
408commit $head1
409added (hi..f${added_utf8_part_iso88591}gt) foo
410EOF
411
Alexey Shumkin7d509872014-05-21 17:20:07 +0400412test_format complex-subject-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF
Alexey Shumkind928d812014-05-21 17:20:06 +0400413commit $head3
414.. of complex bodies
415commit $head2
416..ged (ge${changed_utf8_part_iso88591}ndert) foo
417commit $head1
418.. (hinzugef${added_utf8_part_iso88591}gt) foo
419EOF
420
Elijah Newren2ba31eb2020-10-18 00:23:46 +0000421test_expect_success 'setup expected messages (for test %b)' '
Alexey Shumkin0fe6df32013-07-05 16:01:49 +0400422 cat <<-EOF >expected.utf-8 &&
423 commit $head3
424 This commit message is much longer than the others,
Alexey Shumkinee3efaf2014-05-21 17:20:04 +0400425 and it will be encoded in $test_encoding. We should therefore
426 include an ISO8859 character: ¡bueno!
Alexey Shumkin0fe6df32013-07-05 16:01:49 +0400427
428 commit $head2
429 commit $head1
430 EOF
Alexey Shumkinee3efaf2014-05-21 17:20:04 +0400431 iconv -f utf-8 -t $test_encoding expected.utf-8 >expected.ISO8859-1
Alexey Shumkin0fe6df32013-07-05 16:01:49 +0400432'
433
Alexey Shumkinee3efaf2014-05-21 17:20:04 +0400434test_format complex-body %b <expected.ISO8859-1
Alexey Shumkin0fe6df32013-07-05 16:01:49 +0400435
436# Git uses i18n.commitEncoding if no i18n.logOutputEncoding set
437# so unset i18n.commitEncoding to test encoding conversion
438git config --unset i18n.commitEncoding
439
440test_format complex-subject-commitencoding-unset %s <<EOF
441commit $head3
442Test printing of complex bodies
443commit $head2
Alexey Shumkinde6029a2013-06-26 14:19:49 +0400444$changed
Alexey Shumkin77a68152013-06-26 14:19:46 +0400445commit $head1
Alexey Shumkinde6029a2013-06-26 14:19:49 +0400446$added
Jeff King03bcaac2007-03-28 17:08:36 -0400447EOF
448
Alexey Shumkind928d812014-05-21 17:20:06 +0400449test_format complex-subject-commitencoding-unset-trunc "%<($truncate_count,trunc)%s" <<EOF
450commit $head3
451Test printing of c..
452commit $head2
453changed (ge${changed_utf8_part}ndert)..
454commit $head1
455added (hinzugef${added_utf8_part}gt..
456EOF
457
458test_format complex-subject-commitencoding-unset-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF
459commit $head3
460Test prin..ex bodies
461commit $head2
462changed (..dert) foo
463commit $head1
464added (hi..f${added_utf8_part}gt) foo
465EOF
466
467test_format complex-subject-commitencoding-unset-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF
468commit $head3
469.. of complex bodies
470commit $head2
471..ged (ge${changed_utf8_part}ndert) foo
472commit $head1
473.. (hinzugef${added_utf8_part}gt) foo
474EOF
475
Alexey Shumkin0fe6df32013-07-05 16:01:49 +0400476test_format complex-body-commitencoding-unset %b <expected.utf-8
Jeff King03bcaac2007-03-28 17:08:36 -0400477
Jeff King9130ac92010-10-07 14:25:43 -0400478test_expect_success '%x00 shows NUL' '
Alexey Shumkin77a68152013-06-26 14:19:46 +0400479 echo >expect commit $head3 &&
Jeff King9130ac92010-10-07 14:25:43 -0400480 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
Jeff Kingd36f8672008-08-28 20:54:59 -0400486test_expect_success '%ad respects --date=' '
487 echo 2005-04-07 >expect.ad-short &&
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000488 git log -1 --date=short --pretty=tformat:%ad >output.ad-short main &&
Jeff Kingd36f8672008-08-28 20:54:59 -0400489 test_cmp expect.ad-short output.ad-short
490'
491
Junio C Hamanof7ab5c72008-01-06 04:21:07 -0800492test_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) &&
Jeff King8ddfce72023-05-08 15:04:57 -0400496 test "$A" = "$GIT_AUTHOR_NAME,,Thu Apr 7 15:14:13 2005 -0700"
Junio C Hamanof7ab5c72008-01-06 04:21:07 -0800497'
498
Junio C Hamano9fa708d2009-10-04 23:43:32 -0700499test_expect_success 'del LF before empty (1)' '
500 git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD^^ >actual &&
Stefano Lattarini3fb04592012-04-11 13:24:01 +0200501 test_line_count = 2 actual
Junio C Hamano9fa708d2009-10-04 23:43:32 -0700502'
503
504test_expect_success 'del LF before empty (2)' '
505 git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD >actual &&
Stefano Lattarini3fb04592012-04-11 13:24:01 +0200506 test_line_count = 6 actual &&
Junio C Hamano9fa708d2009-10-04 23:43:32 -0700507 grep "^$" actual
508'
509
510test_expect_success 'add LF before non-empty (1)' '
511 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD^^ >actual &&
Stefano Lattarini3fb04592012-04-11 13:24:01 +0200512 test_line_count = 2 actual
Junio C Hamano9fa708d2009-10-04 23:43:32 -0700513'
514
515test_expect_success 'add LF before non-empty (2)' '
516 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD >actual &&
Stefano Lattarini3fb04592012-04-11 13:24:01 +0200517 test_line_count = 6 actual &&
Junio C Hamano9fa708d2009-10-04 23:43:32 -0700518 grep "^$" actual
519'
520
Michael J Gruber7b881762010-06-14 18:12:29 +0200521test_expect_success 'add SP before non-empty (1)' '
522 git show -s --pretty=format:"%s% bThanks" HEAD^^ >actual &&
Alexey Shumkinde6029a2013-06-26 14:19:49 +0400523 test $(wc -w <actual) = 3
Michael J Gruber7b881762010-06-14 18:12:29 +0200524'
525
526test_expect_success 'add SP before non-empty (2)' '
527 git show -s --pretty=format:"%s% sThanks" HEAD^^ >actual &&
Alexey Shumkinde6029a2013-06-26 14:19:49 +0400528 test $(wc -w <actual) = 6
Michael J Gruber7b881762010-06-14 18:12:29 +0200529'
530
Will Palmerc1977022010-05-03 22:18:57 -0500531test_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 &&
brian m. carlson2ece6ad2018-05-13 02:24:15 +0000537 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 &&
Will Palmerc1977022010-05-03 22:18:57 -0500539 test_cmp expect2 fuzzy2 &&
540 test_cmp expect3 fuzzy3 &&
541 ! test_cmp actual1 actual2
542'
543
544test_expect_success '%H is not affected by --abbrev-commit' '
brian m. carlsonedf04242020-02-07 00:52:53 +0000545 expected=$(($(test_oid hexsz) + 1)) &&
Will Palmerc1977022010-05-03 22:18:57 -0500546 git log -1 --format=%H --abbrev-commit --abbrev=20 HEAD >actual &&
547 len=$(wc -c <actual) &&
brian m. carlsonedf04242020-02-07 00:52:53 +0000548 test $len = $expected
Will Palmerc1977022010-05-03 22:18:57 -0500549'
550
551test_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
Thomas Rast8f8f5472009-10-19 17:48:10 +0200557test_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
563test_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
Will Palmerc1977022010-05-03 22:18:57 -0500569test_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
Thomas Rast8f8f5472009-10-19 17:48:10 +0200575test_expect_success '%gd shortens ref name' '
Johannes Schindelin1550bb62020-11-18 23:44:36 +0000576 echo "main@{0}" >expect.gd-short &&
577 git log -g -1 --format=%gd refs/heads/main >actual.gd-short &&
Thomas Rast8f8f5472009-10-19 17:48:10 +0200578 test_cmp expect.gd-short actual.gd-short
579'
580
Jeff Kingcd1957f2011-12-16 06:40:24 -0500581test_expect_success 'reflog identity' '
Prarit Bhargava2ae49442019-10-24 19:36:15 -0400582 echo "$GIT_COMMITTER_NAME:$GIT_COMMITTER_EMAIL" >expect &&
Jeff Kingcd1957f2011-12-16 06:40:24 -0500583 git log -g -1 --format="%gn:%ge" >actual &&
584 test_cmp expect actual
585'
586
Erik Faye-Lund1fb5fdd2010-03-21 15:40:16 +0100587test_expect_success 'oneline with empty message' '
Elijah Newren7b6ad972019-09-04 15:32:37 -0700588 git commit --allow-empty --cleanup=verbatim -m "$LF" &&
589 git commit --allow-empty --allow-empty-message &&
Matthew Ogilvief02dd062010-04-16 20:29:18 -0600590 git rev-list --oneline HEAD >test.txt &&
Stefano Lattarini3fb04592012-04-11 13:24:01 +0200591 test_line_count = 5 test.txt &&
592 git rev-list --oneline --graph HEAD >testg.txt &&
593 test_line_count = 5 testg.txt
Erik Faye-Lund1fb5fdd2010-03-21 15:40:16 +0100594'
595
Jeff Kingd9955fd2012-05-22 02:12:20 -0400596test_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
Jeff King958b2eb2014-06-25 17:42:17 -0400603test_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
Jeff Kingfa21b602007-03-27 20:08:28 -0400609test_done