]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6006-rev-list-format.sh
git-instaweb: pass through invoking user's path to gitweb CGI scripts
[thirdparty/git.git] / t / t6006-rev-list-format.sh
CommitLineData
fa21b602
JK
1#!/bin/sh
2
5be60078 3test_description='git rev-list --pretty=format test'
fa21b602
JK
4
5. ./test-lib.sh
6
7test_tick
8test_expect_success 'setup' '
3604e7c5
NS
9touch foo && git add foo && git commit -m "added foo" &&
10 echo changed >foo && git commit -a -m "changed foo"
fa21b602
JK
11'
12
13# usage: test_format name format_string <expected_output
14test_format() {
15 cat >expect.$1
16 test_expect_success "format $1" "
c002922a 17git rev-list --pretty=format:'$2' master >output.$1 &&
3af82863 18test_cmp expect.$1 output.$1
fa21b602
JK
19"
20}
21
0a0416a3
JK
22test_format percent %%h <<'EOF'
23commit 131a310eb913d107dd3c09a65d1651175898735d
24%h
25commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
26%h
27EOF
28
fa21b602
JK
29test_format hash %H%n%h <<'EOF'
30commit 131a310eb913d107dd3c09a65d1651175898735d
31131a310eb913d107dd3c09a65d1651175898735d
32131a310
33commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
3486c75cfd708a0e5868dc876ed5b8bb66c80b4873
3586c75cf
36EOF
37
38test_format tree %T%n%t <<'EOF'
39commit 131a310eb913d107dd3c09a65d1651175898735d
40fe722612f26da5064c32ca3843aa154bdb0b08a0
41fe72261
42commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
434d5fcadc293a348e88f777dc0920f11e7d71441c
444d5fcad
45EOF
46
47test_format parents %P%n%p <<'EOF'
48commit 131a310eb913d107dd3c09a65d1651175898735d
542e165c
JH
4986c75cfd708a0e5868dc876ed5b8bb66c80b4873
5086c75cf
fa21b602 51commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
542e165c
JH
52
53
fa21b602
JK
54EOF
55
56# we don't test relative here
57test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF'
58commit 131a310eb913d107dd3c09a65d1651175898735d
59A U Thor
60author@example.com
61Thu Apr 7 15:13:13 2005 -0700
62Thu, 7 Apr 2005 15:13:13 -0700
631112911993
64commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
65A U Thor
66author@example.com
67Thu Apr 7 15:13:13 2005 -0700
68Thu, 7 Apr 2005 15:13:13 -0700
691112911993
70EOF
71
72test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF'
73commit 131a310eb913d107dd3c09a65d1651175898735d
74C O Mitter
75committer@example.com
76Thu Apr 7 15:13:13 2005 -0700
77Thu, 7 Apr 2005 15:13:13 -0700
781112911993
79commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
80C O Mitter
81committer@example.com
82Thu Apr 7 15:13:13 2005 -0700
83Thu, 7 Apr 2005 15:13:13 -0700
841112911993
85EOF
86
87test_format encoding %e <<'EOF'
88commit 131a310eb913d107dd3c09a65d1651175898735d
fa21b602 89commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
fa21b602
JK
90EOF
91
92test_format subject %s <<'EOF'
93commit 131a310eb913d107dd3c09a65d1651175898735d
94changed foo
95commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
96added foo
97EOF
98
99test_format body %b <<'EOF'
100commit 131a310eb913d107dd3c09a65d1651175898735d
fa21b602 101commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
fa21b602
JK
102EOF
103
104test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
105commit 131a310eb913d107dd3c09a65d1651175898735d
106\e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy
107commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
108\e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy
109EOF
110
c002922a
JK
111test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<'EOF'
112commit 131a310eb913d107dd3c09a65d1651175898735d
113\e[1;31;43mfoo\e[m
114commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
115\e[1;31;43mfoo\e[m
116EOF
117
03bcaaca
JK
118cat >commit-msg <<'EOF'
119Test printing of complex bodies
120
121This commit message is much longer than the others,
122and it will be encoded in iso8859-1. We should therefore
123include an iso8859 character: ¡bueno!
124EOF
125test_expect_success 'setup complex body' '
5be60078 126git config i18n.commitencoding iso8859-1 &&
3604e7c5 127 echo change2 >foo && git commit -a -F commit-msg
03bcaaca
JK
128'
129
130test_format complex-encoding %e <<'EOF'
131commit f58db70b055c5718631e5c61528b28b12090cdea
132iso8859-1
133commit 131a310eb913d107dd3c09a65d1651175898735d
03bcaaca 134commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
03bcaaca
JK
135EOF
136
137test_format complex-subject %s <<'EOF'
138commit f58db70b055c5718631e5c61528b28b12090cdea
139Test printing of complex bodies
140commit 131a310eb913d107dd3c09a65d1651175898735d
141changed foo
142commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
143added foo
144EOF
145
146test_format complex-body %b <<'EOF'
147commit f58db70b055c5718631e5c61528b28b12090cdea
148This commit message is much longer than the others,
149and it will be encoded in iso8859-1. We should therefore
150include an iso8859 character: ¡bueno!
151
152commit 131a310eb913d107dd3c09a65d1651175898735d
03bcaaca 153commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
03bcaaca
JK
154EOF
155
d36f8679
JK
156test_expect_success '%ad respects --date=' '
157 echo 2005-04-07 >expect.ad-short &&
158 git log -1 --date=short --pretty=tformat:%ad >output.ad-short master &&
159 test_cmp expect.ad-short output.ad-short
160'
161
f7ab5c79
JH
162test_expect_success 'empty email' '
163 test_tick &&
164 C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&
165 A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) &&
166 test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700" || {
167 echo "Eh? $A" >failure
168 false
169 }
170'
171
9fa708da
JH
172test_expect_success 'del LF before empty (1)' '
173 git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD^^ >actual &&
174 test $(wc -l <actual) = 2
175'
176
177test_expect_success 'del LF before empty (2)' '
178 git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD >actual &&
179 test $(wc -l <actual) = 6 &&
180 grep "^$" actual
181'
182
183test_expect_success 'add LF before non-empty (1)' '
184 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD^^ >actual &&
185 test $(wc -l <actual) = 2
186'
187
188test_expect_success 'add LF before non-empty (2)' '
189 git show -s --pretty=format:"%s%+b%nThanks%n" HEAD >actual &&
190 test $(wc -l <actual) = 6 &&
191 grep "^$" actual
192'
193
8f8f5476
TR
194test_expect_success '"%h %gD: %gs" is same as git-reflog' '
195 git reflog >expect &&
196 git log -g --format="%h %gD: %gs" >actual &&
197 test_cmp expect actual
198'
199
200test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' '
201 git reflog --date=raw >expect &&
202 git log -g --format="%h %gD: %gs" --date=raw >actual &&
203 test_cmp expect actual
204'
205
206test_expect_success '%gd shortens ref name' '
207 echo "master@{0}" >expect.gd-short &&
208 git log -g -1 --format=%gd refs/heads/master >actual.gd-short &&
209 test_cmp expect.gd-short actual.gd-short
210'
211
1fb5fdd2
EFL
212test_expect_success 'oneline with empty message' '
213 git commit -m "dummy" --allow-empty &&
214 git commit -m "dummy" --allow-empty &&
215 git filter-branch --msg-filter "sed -e s/dummy//" HEAD^^.. &&
216 git rev-list --oneline HEAD > /tmp/test.txt &&
217 test $(git rev-list --oneline HEAD | wc -l) -eq 5 &&
218 test $(git rev-list --oneline --graph HEAD | wc -l) -eq 5
219'
220
fa21b602 221test_done