]>
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 | |
de6029a2 AS |
12 | # String "added" in German (translated with Google Translate), encoded in UTF-8, |
13 | # used as a commit log message below. | |
14 | added=$(printf "added (hinzugef\303\274gt) foo") | |
15 | added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso-8859-1) | |
16 | # same but "changed" | |
17 | changed=$(printf "changed (ge\303\244ndert) foo") | |
18 | changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso-8859-1) | |
19 | ||
fa21b602 | 20 | test_expect_success 'setup' ' |
77a6815d AS |
21 | : >foo && |
22 | git add foo && | |
de6029a2 AS |
23 | git config i18n.commitEncoding iso-8859-1 && |
24 | git commit -m "$added_iso88591" && | |
77a6815d AS |
25 | head1=$(git rev-parse --verify HEAD) && |
26 | head1_short=$(git rev-parse --verify --short $head1) && | |
27 | tree1=$(git rev-parse --verify HEAD:) && | |
28 | tree1_short=$(git rev-parse --verify --short $tree1) && | |
de6029a2 AS |
29 | echo "$changed" > foo && |
30 | git commit -a -m "$changed_iso88591" && | |
77a6815d AS |
31 | head2=$(git rev-parse --verify HEAD) && |
32 | head2_short=$(git rev-parse --verify --short $head2) && | |
33 | tree2=$(git rev-parse --verify HEAD:) && | |
34 | tree2_short=$(git rev-parse --verify --short $tree2) | |
de6029a2 | 35 | git config --unset i18n.commitEncoding |
fa21b602 JK |
36 | ' |
37 | ||
de6029a2 | 38 | # usage: test_format [failure] name format_string <expected_output |
2581ad5e | 39 | test_format () { |
de6029a2 AS |
40 | must_fail=0 |
41 | # if parameters count is more than 2 then test must fail | |
42 | if test $# -gt 2 | |
43 | then | |
44 | must_fail=1 | |
45 | # remove first parameter which is flag for test failure | |
46 | shift | |
47 | fi | |
fa21b602 | 48 | cat >expect.$1 |
de6029a2 AS |
49 | name="format $1" |
50 | command="git rev-list --pretty=format:'$2' master >output.$1 && | |
51 | test_cmp expect.$1 output.$1" | |
52 | if test $must_fail -eq 1 | |
53 | then | |
54 | test_expect_failure "$name" "$command" | |
55 | else | |
56 | test_expect_success "$name" "$command" | |
57 | fi | |
fa21b602 JK |
58 | } |
59 | ||
30825178 JH |
60 | # Feed to --format to provide predictable colored sequences. |
61 | AUTO_COLOR='%C(auto,red)foo%C(auto,reset)' | |
62 | has_color () { | |
63 | printf '\033[31mfoo\033[m\n' >expect && | |
64 | test_cmp expect "$1" | |
65 | } | |
66 | ||
67 | has_no_color () { | |
68 | echo foo >expect && | |
69 | test_cmp expect "$1" | |
70 | } | |
71 | ||
77a6815d AS |
72 | test_format percent %%h <<EOF |
73 | commit $head2 | |
0a0416a3 | 74 | %h |
77a6815d | 75 | commit $head1 |
0a0416a3 JK |
76 | %h |
77 | EOF | |
78 | ||
77a6815d AS |
79 | test_format hash %H%n%h <<EOF |
80 | commit $head2 | |
81 | $head2 | |
82 | $head2_short | |
83 | commit $head1 | |
84 | $head1 | |
85 | $head1_short | |
fa21b602 JK |
86 | EOF |
87 | ||
77a6815d AS |
88 | test_format tree %T%n%t <<EOF |
89 | commit $head2 | |
90 | $tree2 | |
91 | $tree2_short | |
92 | commit $head1 | |
93 | $tree1 | |
94 | $tree1_short | |
fa21b602 JK |
95 | EOF |
96 | ||
77a6815d AS |
97 | test_format parents %P%n%p <<EOF |
98 | commit $head2 | |
99 | $head1 | |
100 | $head1_short | |
101 | commit $head1 | |
542e165c JH |
102 | |
103 | ||
fa21b602 JK |
104 | EOF |
105 | ||
106 | # we don't test relative here | |
77a6815d AS |
107 | test_format author %an%n%ae%n%ad%n%aD%n%at <<EOF |
108 | commit $head2 | |
fa21b602 JK |
109 | A U Thor |
110 | author@example.com | |
111 | Thu Apr 7 15:13:13 2005 -0700 | |
112 | Thu, 7 Apr 2005 15:13:13 -0700 | |
113 | 1112911993 | |
77a6815d | 114 | commit $head1 |
fa21b602 JK |
115 | A U Thor |
116 | author@example.com | |
117 | Thu Apr 7 15:13:13 2005 -0700 | |
118 | Thu, 7 Apr 2005 15:13:13 -0700 | |
119 | 1112911993 | |
120 | EOF | |
121 | ||
77a6815d AS |
122 | test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<EOF |
123 | commit $head2 | |
fa21b602 JK |
124 | C O Mitter |
125 | committer@example.com | |
126 | Thu Apr 7 15:13:13 2005 -0700 | |
127 | Thu, 7 Apr 2005 15:13:13 -0700 | |
128 | 1112911993 | |
77a6815d | 129 | commit $head1 |
fa21b602 JK |
130 | C O Mitter |
131 | committer@example.com | |
132 | Thu Apr 7 15:13:13 2005 -0700 | |
133 | Thu, 7 Apr 2005 15:13:13 -0700 | |
134 | 1112911993 | |
135 | EOF | |
136 | ||
77a6815d AS |
137 | test_format encoding %e <<EOF |
138 | commit $head2 | |
de6029a2 | 139 | iso-8859-1 |
77a6815d | 140 | commit $head1 |
de6029a2 | 141 | iso-8859-1 |
fa21b602 JK |
142 | EOF |
143 | ||
de6029a2 | 144 | test_format failure subject %s <<EOF |
77a6815d | 145 | commit $head2 |
de6029a2 | 146 | $changed |
77a6815d | 147 | commit $head1 |
de6029a2 | 148 | $added |
fa21b602 JK |
149 | EOF |
150 | ||
77a6815d AS |
151 | test_format body %b <<EOF |
152 | commit $head2 | |
153 | commit $head1 | |
fa21b602 JK |
154 | EOF |
155 | ||
de6029a2 | 156 | test_format failure raw-body %B <<EOF |
77a6815d | 157 | commit $head2 |
de6029a2 | 158 | $changed |
1367b12a | 159 | |
77a6815d | 160 | commit $head1 |
de6029a2 | 161 | $added |
1367b12a EB |
162 | |
163 | EOF | |
164 | ||
77a6815d AS |
165 | test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<EOF |
166 | commit $head2 | |
fa21b602 | 167 | \e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy |
77a6815d | 168 | commit $head1 |
fa21b602 JK |
169 | \e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy |
170 | EOF | |
171 | ||
77a6815d AS |
172 | test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<EOF |
173 | commit $head2 | |
c002922a | 174 | \e[1;31;43mfoo\e[m |
77a6815d | 175 | commit $head1 |
c002922a JK |
176 | \e[1;31;43mfoo\e[m |
177 | EOF | |
178 | ||
30825178 JH |
179 | test_expect_success '%C(auto) does not enable color by default' ' |
180 | git log --format=$AUTO_COLOR -1 >actual && | |
181 | has_no_color actual | |
182 | ' | |
183 | ||
184 | test_expect_success '%C(auto) enables colors for color.diff' ' | |
185 | git -c color.diff=always log --format=$AUTO_COLOR -1 >actual && | |
186 | has_color actual | |
187 | ' | |
188 | ||
189 | test_expect_success '%C(auto) enables colors for color.ui' ' | |
190 | git -c color.ui=always log --format=$AUTO_COLOR -1 >actual && | |
191 | has_color actual | |
192 | ' | |
193 | ||
194 | test_expect_success '%C(auto) respects --color' ' | |
195 | git log --format=$AUTO_COLOR -1 --color >actual && | |
196 | has_color actual | |
197 | ' | |
198 | ||
199 | test_expect_success '%C(auto) respects --no-color' ' | |
200 | git -c color.ui=always log --format=$AUTO_COLOR -1 --no-color >actual && | |
201 | has_no_color actual | |
202 | ' | |
203 | ||
204 | test_expect_success TTY '%C(auto) respects --color=auto (stdout is tty)' ' | |
205 | ( | |
206 | TERM=vt100 && export TERM && | |
207 | test_terminal \ | |
208 | git log --format=$AUTO_COLOR -1 --color=auto >actual && | |
209 | has_color actual | |
210 | ) | |
211 | ' | |
212 | ||
213 | test_expect_success '%C(auto) respects --color=auto (stdout not tty)' ' | |
214 | ( | |
215 | TERM=vt100 && export TERM && | |
216 | git log --format=$AUTO_COLOR -1 --color=auto >actual && | |
217 | has_no_color actual | |
218 | ) | |
219 | ' | |
220 | ||
de6029a2 | 221 | iconv -f utf-8 -t iso8859-1 > commit-msg <<EOF |
03bcaaca JK |
222 | Test printing of complex bodies |
223 | ||
224 | This commit message is much longer than the others, | |
225 | and it will be encoded in iso8859-1. We should therefore | |
de6029a2 | 226 | include an iso8859 character: ¡bueno! |
03bcaaca | 227 | EOF |
77a6815d | 228 | |
03bcaaca | 229 | test_expect_success 'setup complex body' ' |
77a6815d AS |
230 | git config i18n.commitencoding iso8859-1 && |
231 | echo change2 >foo && git commit -a -F commit-msg && | |
232 | head3=$(git rev-parse --verify HEAD) && | |
de6029a2 AS |
233 | head3_short=$(git rev-parse --short $head3) && |
234 | # unset commit encoding config | |
235 | # otherwise %e does not print encoding value | |
236 | # and following test fails | |
237 | git config --unset i18n.commitEncoding | |
238 | ||
03bcaaca JK |
239 | ' |
240 | ||
77a6815d AS |
241 | test_format complex-encoding %e <<EOF |
242 | commit $head3 | |
03bcaaca | 243 | iso8859-1 |
77a6815d | 244 | commit $head2 |
de6029a2 | 245 | iso-8859-1 |
77a6815d | 246 | commit $head1 |
de6029a2 | 247 | iso-8859-1 |
03bcaaca JK |
248 | EOF |
249 | ||
de6029a2 | 250 | test_format failure complex-subject %s <<EOF |
77a6815d | 251 | commit $head3 |
03bcaaca | 252 | Test printing of complex bodies |
77a6815d | 253 | commit $head2 |
de6029a2 | 254 | $changed |
77a6815d | 255 | commit $head1 |
de6029a2 | 256 | $added |
03bcaaca JK |
257 | EOF |
258 | ||
de6029a2 | 259 | test_format failure complex-body %b <<EOF |
77a6815d | 260 | commit $head3 |
03bcaaca JK |
261 | This commit message is much longer than the others, |
262 | and it will be encoded in iso8859-1. We should therefore | |
de6029a2 | 263 | include an iso8859 character: ¡bueno! |
03bcaaca | 264 | |
77a6815d AS |
265 | commit $head2 |
266 | commit $head1 | |
03bcaaca JK |
267 | EOF |
268 | ||
9130ac9f | 269 | test_expect_success '%x00 shows NUL' ' |
77a6815d | 270 | echo >expect commit $head3 && |
9130ac9f JK |
271 | echo >>expect fooQbar && |
272 | git rev-list -1 --format=foo%x00bar HEAD >actual.nul && | |
273 | nul_to_q <actual.nul >actual && | |
274 | test_cmp expect actual | |
275 | ' | |
276 | ||
d36f8679 JK |
277 | test_expect_success '%ad respects --date=' ' |
278 | echo 2005-04-07 >expect.ad-short && | |
279 | git log -1 --date=short --pretty=tformat:%ad >output.ad-short master && | |
280 | test_cmp expect.ad-short output.ad-short | |
281 | ' | |
282 | ||
f7ab5c79 JH |
283 | test_expect_success 'empty email' ' |
284 | test_tick && | |
285 | C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) && | |
286 | A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) && | |
287 | test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700" || { | |
288 | echo "Eh? $A" >failure | |
289 | false | |
290 | } | |
291 | ' | |
292 | ||
9fa708da JH |
293 | test_expect_success 'del LF before empty (1)' ' |
294 | git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD^^ >actual && | |
3fb0459b | 295 | test_line_count = 2 actual |
9fa708da JH |
296 | ' |
297 | ||
298 | test_expect_success 'del LF before empty (2)' ' | |
299 | git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD >actual && | |
3fb0459b | 300 | test_line_count = 6 actual && |
9fa708da JH |
301 | grep "^$" actual |
302 | ' | |
303 | ||
304 | test_expect_success 'add LF before non-empty (1)' ' | |
305 | git show -s --pretty=format:"%s%+b%nThanks%n" HEAD^^ >actual && | |
3fb0459b | 306 | test_line_count = 2 actual |
9fa708da JH |
307 | ' |
308 | ||
309 | test_expect_success 'add LF before non-empty (2)' ' | |
310 | git show -s --pretty=format:"%s%+b%nThanks%n" HEAD >actual && | |
3fb0459b | 311 | test_line_count = 6 actual && |
9fa708da JH |
312 | grep "^$" actual |
313 | ' | |
314 | ||
7b88176e MG |
315 | test_expect_success 'add SP before non-empty (1)' ' |
316 | git show -s --pretty=format:"%s% bThanks" HEAD^^ >actual && | |
de6029a2 | 317 | test $(wc -w <actual) = 3 |
7b88176e MG |
318 | ' |
319 | ||
320 | test_expect_success 'add SP before non-empty (2)' ' | |
321 | git show -s --pretty=format:"%s% sThanks" HEAD^^ >actual && | |
de6029a2 | 322 | test $(wc -w <actual) = 6 |
7b88176e MG |
323 | ' |
324 | ||
c1977021 WP |
325 | test_expect_success '--abbrev' ' |
326 | echo SHORT SHORT SHORT >expect2 && | |
327 | echo LONG LONG LONG >expect3 && | |
328 | git log -1 --format="%h %h %h" HEAD >actual1 && | |
329 | git log -1 --abbrev=5 --format="%h %h %h" HEAD >actual2 && | |
330 | git log -1 --abbrev=5 --format="%H %H %H" HEAD >actual3 && | |
331 | sed -e "s/$_x40/LONG/g" -e "s/$_x05/SHORT/g" <actual2 >fuzzy2 && | |
332 | sed -e "s/$_x40/LONG/g" -e "s/$_x05/SHORT/g" <actual3 >fuzzy3 && | |
333 | test_cmp expect2 fuzzy2 && | |
334 | test_cmp expect3 fuzzy3 && | |
335 | ! test_cmp actual1 actual2 | |
336 | ' | |
337 | ||
338 | test_expect_success '%H is not affected by --abbrev-commit' ' | |
339 | git log -1 --format=%H --abbrev-commit --abbrev=20 HEAD >actual && | |
340 | len=$(wc -c <actual) && | |
341 | test $len = 41 | |
342 | ' | |
343 | ||
344 | test_expect_success '%h is not affected by --abbrev-commit' ' | |
345 | git log -1 --format=%h --abbrev-commit --abbrev=20 HEAD >actual && | |
346 | len=$(wc -c <actual) && | |
347 | test $len = 21 | |
348 | ' | |
349 | ||
8f8f5476 TR |
350 | test_expect_success '"%h %gD: %gs" is same as git-reflog' ' |
351 | git reflog >expect && | |
352 | git log -g --format="%h %gD: %gs" >actual && | |
353 | test_cmp expect actual | |
354 | ' | |
355 | ||
356 | test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' ' | |
357 | git reflog --date=raw >expect && | |
358 | git log -g --format="%h %gD: %gs" --date=raw >actual && | |
359 | test_cmp expect actual | |
360 | ' | |
361 | ||
c1977021 WP |
362 | test_expect_success '"%h %gD: %gs" is same as git-reflog (with --abbrev)' ' |
363 | git reflog --abbrev=13 --date=raw >expect && | |
364 | git log -g --abbrev=13 --format="%h %gD: %gs" --date=raw >actual && | |
365 | test_cmp expect actual | |
366 | ' | |
367 | ||
8f8f5476 TR |
368 | test_expect_success '%gd shortens ref name' ' |
369 | echo "master@{0}" >expect.gd-short && | |
370 | git log -g -1 --format=%gd refs/heads/master >actual.gd-short && | |
371 | test_cmp expect.gd-short actual.gd-short | |
372 | ' | |
373 | ||
cd1957f5 JK |
374 | test_expect_success 'reflog identity' ' |
375 | echo "C O Mitter:committer@example.com" >expect && | |
376 | git log -g -1 --format="%gn:%ge" >actual && | |
377 | test_cmp expect actual | |
378 | ' | |
379 | ||
1fb5fdd2 EFL |
380 | test_expect_success 'oneline with empty message' ' |
381 | git commit -m "dummy" --allow-empty && | |
382 | git commit -m "dummy" --allow-empty && | |
383 | git filter-branch --msg-filter "sed -e s/dummy//" HEAD^^.. && | |
f02dd06e | 384 | git rev-list --oneline HEAD >test.txt && |
3fb0459b SL |
385 | test_line_count = 5 test.txt && |
386 | git rev-list --oneline --graph HEAD >testg.txt && | |
387 | test_line_count = 5 testg.txt | |
1fb5fdd2 EFL |
388 | ' |
389 | ||
d9955fd6 JK |
390 | test_expect_success 'single-character name is parsed correctly' ' |
391 | git commit --author="a <a@example.com>" --allow-empty -m foo && | |
392 | echo "a <a@example.com>" >expect && | |
393 | git log -1 --format="%an <%ae>" >actual && | |
394 | test_cmp expect actual | |
395 | ' | |
396 | ||
fa21b602 | 397 | test_done |