t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs
[alt-git.git] / t / t6006-rev-list-format.sh
blobcc1008d0244558b23b30d6c62cdfd57fc81d9be9
1 #!/bin/sh
3 test_description='git rev-list --pretty=format test'
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-terminal.sh
8 test_tick
9 test_expect_success 'setup' '
10 : >foo &&
11 git add foo &&
12 git commit -m "added foo" &&
13 head1=$(git rev-parse --verify HEAD) &&
14 head1_short=$(git rev-parse --verify --short $head1) &&
15 tree1=$(git rev-parse --verify HEAD:) &&
16 tree1_short=$(git rev-parse --verify --short $tree1) &&
17 echo changed >foo &&
18 git commit -a -m "changed foo" &&
19 head2=$(git rev-parse --verify HEAD) &&
20 head2_short=$(git rev-parse --verify --short $head2) &&
21 tree2=$(git rev-parse --verify HEAD:) &&
22 tree2_short=$(git rev-parse --verify --short $tree2)
25 # usage: test_format name format_string <expected_output
26 test_format () {
27 cat >expect.$1
28 test_expect_success "format $1" "
29 git rev-list --pretty=format:'$2' master >output.$1 &&
30 test_cmp expect.$1 output.$1
34 # Feed to --format to provide predictable colored sequences.
35 AUTO_COLOR='%C(auto,red)foo%C(auto,reset)'
36 has_color () {
37 printf '\033[31mfoo\033[m\n' >expect &&
38 test_cmp expect "$1"
41 has_no_color () {
42 echo foo >expect &&
43 test_cmp expect "$1"
46 test_format percent %%h <<EOF
47 commit $head2
49 commit $head1
51 EOF
53 test_format hash %H%n%h <<EOF
54 commit $head2
55 $head2
56 $head2_short
57 commit $head1
58 $head1
59 $head1_short
60 EOF
62 test_format tree %T%n%t <<EOF
63 commit $head2
64 $tree2
65 $tree2_short
66 commit $head1
67 $tree1
68 $tree1_short
69 EOF
71 test_format parents %P%n%p <<EOF
72 commit $head2
73 $head1
74 $head1_short
75 commit $head1
78 EOF
80 # we don't test relative here
81 test_format author %an%n%ae%n%ad%n%aD%n%at <<EOF
82 commit $head2
83 A U Thor
84 author@example.com
85 Thu Apr 7 15:13:13 2005 -0700
86 Thu, 7 Apr 2005 15:13:13 -0700
87 1112911993
88 commit $head1
89 A U Thor
90 author@example.com
91 Thu Apr 7 15:13:13 2005 -0700
92 Thu, 7 Apr 2005 15:13:13 -0700
93 1112911993
94 EOF
96 test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<EOF
97 commit $head2
98 C O Mitter
99 committer@example.com
100 Thu Apr 7 15:13:13 2005 -0700
101 Thu, 7 Apr 2005 15:13:13 -0700
102 1112911993
103 commit $head1
104 C O Mitter
105 committer@example.com
106 Thu Apr 7 15:13:13 2005 -0700
107 Thu, 7 Apr 2005 15:13:13 -0700
108 1112911993
111 test_format encoding %e <<EOF
112 commit $head2
113 commit $head1
116 test_format subject %s <<EOF
117 commit $head2
118 changed foo
119 commit $head1
120 added foo
123 test_format body %b <<EOF
124 commit $head2
125 commit $head1
128 test_format raw-body %B <<EOF
129 commit $head2
130 changed foo
132 commit $head1
133 added foo
137 test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<EOF
138 commit $head2
139 \e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy
140 commit $head1
141 \e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy
144 test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<EOF
145 commit $head2
146 \e[1;31;43mfoo\e[m
147 commit $head1
148 \e[1;31;43mfoo\e[m
151 test_expect_success '%C(auto) does not enable color by default' '
152 git log --format=$AUTO_COLOR -1 >actual &&
153 has_no_color actual
156 test_expect_success '%C(auto) enables colors for color.diff' '
157 git -c color.diff=always log --format=$AUTO_COLOR -1 >actual &&
158 has_color actual
161 test_expect_success '%C(auto) enables colors for color.ui' '
162 git -c color.ui=always log --format=$AUTO_COLOR -1 >actual &&
163 has_color actual
166 test_expect_success '%C(auto) respects --color' '
167 git log --format=$AUTO_COLOR -1 --color >actual &&
168 has_color actual
171 test_expect_success '%C(auto) respects --no-color' '
172 git -c color.ui=always log --format=$AUTO_COLOR -1 --no-color >actual &&
173 has_no_color actual
176 test_expect_success TTY '%C(auto) respects --color=auto (stdout is tty)' '
178 TERM=vt100 && export TERM &&
179 test_terminal \
180 git log --format=$AUTO_COLOR -1 --color=auto >actual &&
181 has_color actual
185 test_expect_success '%C(auto) respects --color=auto (stdout not tty)' '
187 TERM=vt100 && export TERM &&
188 git log --format=$AUTO_COLOR -1 --color=auto >actual &&
189 has_no_color actual
193 cat >commit-msg <<'EOF'
194 Test printing of complex bodies
196 This commit message is much longer than the others,
197 and it will be encoded in iso8859-1. We should therefore
198 include an iso8859 character: ¡bueno!
201 test_expect_success 'setup complex body' '
202 git config i18n.commitencoding iso8859-1 &&
203 echo change2 >foo && git commit -a -F commit-msg &&
204 head3=$(git rev-parse --verify HEAD) &&
205 head3_short=$(git rev-parse --short $head3)
208 test_format complex-encoding %e <<EOF
209 commit $head3
210 iso8859-1
211 commit $head2
212 commit $head1
215 test_format complex-subject %s <<EOF
216 commit $head3
217 Test printing of complex bodies
218 commit $head2
219 changed foo
220 commit $head1
221 added foo
224 test_format complex-body %b <<EOF
225 commit $head3
226 This commit message is much longer than the others,
227 and it will be encoded in iso8859-1. We should therefore
228 include an iso8859 character: ¡bueno!
230 commit $head2
231 commit $head1
234 test_expect_success '%x00 shows NUL' '
235 echo >expect commit $head3 &&
236 echo >>expect fooQbar &&
237 git rev-list -1 --format=foo%x00bar HEAD >actual.nul &&
238 nul_to_q <actual.nul >actual &&
239 test_cmp expect actual
242 test_expect_success '%ad respects --date=' '
243 echo 2005-04-07 >expect.ad-short &&
244 git log -1 --date=short --pretty=tformat:%ad >output.ad-short master &&
245 test_cmp expect.ad-short output.ad-short
248 test_expect_success 'empty email' '
249 test_tick &&
250 C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&
251 A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) &&
252 test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700" || {
253 echo "Eh? $A" >failure
254 false
258 test_expect_success 'del LF before empty (1)' '
259 git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD^^ >actual &&
260 test_line_count = 2 actual
263 test_expect_success 'del LF before empty (2)' '
264 git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD >actual &&
265 test_line_count = 6 actual &&
266 grep "^$" actual
269 test_expect_success 'add LF before non-empty (1)' '
270 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD^^ >actual &&
271 test_line_count = 2 actual
274 test_expect_success 'add LF before non-empty (2)' '
275 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD >actual &&
276 test_line_count = 6 actual &&
277 grep "^$" actual
280 test_expect_success 'add SP before non-empty (1)' '
281 git show -s --pretty=format:"%s% bThanks" HEAD^^ >actual &&
282 test $(wc -w <actual) = 2
285 test_expect_success 'add SP before non-empty (2)' '
286 git show -s --pretty=format:"%s% sThanks" HEAD^^ >actual &&
287 test $(wc -w <actual) = 4
290 test_expect_success '--abbrev' '
291 echo SHORT SHORT SHORT >expect2 &&
292 echo LONG LONG LONG >expect3 &&
293 git log -1 --format="%h %h %h" HEAD >actual1 &&
294 git log -1 --abbrev=5 --format="%h %h %h" HEAD >actual2 &&
295 git log -1 --abbrev=5 --format="%H %H %H" HEAD >actual3 &&
296 sed -e "s/$_x40/LONG/g" -e "s/$_x05/SHORT/g" <actual2 >fuzzy2 &&
297 sed -e "s/$_x40/LONG/g" -e "s/$_x05/SHORT/g" <actual3 >fuzzy3 &&
298 test_cmp expect2 fuzzy2 &&
299 test_cmp expect3 fuzzy3 &&
300 ! test_cmp actual1 actual2
303 test_expect_success '%H is not affected by --abbrev-commit' '
304 git log -1 --format=%H --abbrev-commit --abbrev=20 HEAD >actual &&
305 len=$(wc -c <actual) &&
306 test $len = 41
309 test_expect_success '%h is not affected by --abbrev-commit' '
310 git log -1 --format=%h --abbrev-commit --abbrev=20 HEAD >actual &&
311 len=$(wc -c <actual) &&
312 test $len = 21
315 test_expect_success '"%h %gD: %gs" is same as git-reflog' '
316 git reflog >expect &&
317 git log -g --format="%h %gD: %gs" >actual &&
318 test_cmp expect actual
321 test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' '
322 git reflog --date=raw >expect &&
323 git log -g --format="%h %gD: %gs" --date=raw >actual &&
324 test_cmp expect actual
327 test_expect_success '"%h %gD: %gs" is same as git-reflog (with --abbrev)' '
328 git reflog --abbrev=13 --date=raw >expect &&
329 git log -g --abbrev=13 --format="%h %gD: %gs" --date=raw >actual &&
330 test_cmp expect actual
333 test_expect_success '%gd shortens ref name' '
334 echo "master@{0}" >expect.gd-short &&
335 git log -g -1 --format=%gd refs/heads/master >actual.gd-short &&
336 test_cmp expect.gd-short actual.gd-short
339 test_expect_success 'reflog identity' '
340 echo "C O Mitter:committer@example.com" >expect &&
341 git log -g -1 --format="%gn:%ge" >actual &&
342 test_cmp expect actual
345 test_expect_success 'oneline with empty message' '
346 git commit -m "dummy" --allow-empty &&
347 git commit -m "dummy" --allow-empty &&
348 git filter-branch --msg-filter "sed -e s/dummy//" HEAD^^.. &&
349 git rev-list --oneline HEAD >test.txt &&
350 test_line_count = 5 test.txt &&
351 git rev-list --oneline --graph HEAD >testg.txt &&
352 test_line_count = 5 testg.txt
355 test_expect_success 'single-character name is parsed correctly' '
356 git commit --author="a <a@example.com>" --allow-empty -m foo &&
357 echo "a <a@example.com>" >expect &&
358 git log -1 --format="%an <%ae>" >actual &&
359 test_cmp expect actual
362 test_done