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