]>
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 | |
6 | ||
7 | test_tick | |
8 | test_expect_success 'setup' ' | |
3604e7c5 NS |
9 | touch 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 | |
14 | test_format() { | |
15 | cat >expect.$1 | |
16 | test_expect_success "format $1" " | |
c002922a | 17 | git rev-list --pretty=format:'$2' master >output.$1 && |
3af82863 | 18 | test_cmp expect.$1 output.$1 |
fa21b602 JK |
19 | " |
20 | } | |
21 | ||
0a0416a3 JK |
22 | test_format percent %%h <<'EOF' |
23 | commit 131a310eb913d107dd3c09a65d1651175898735d | |
24 | %h | |
25 | commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 | |
26 | %h | |
27 | EOF | |
28 | ||
fa21b602 JK |
29 | test_format hash %H%n%h <<'EOF' |
30 | commit 131a310eb913d107dd3c09a65d1651175898735d | |
31 | 131a310eb913d107dd3c09a65d1651175898735d | |
32 | 131a310 | |
33 | commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 | |
34 | 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 | |
35 | 86c75cf | |
36 | EOF | |
37 | ||
38 | test_format tree %T%n%t <<'EOF' | |
39 | commit 131a310eb913d107dd3c09a65d1651175898735d | |
40 | fe722612f26da5064c32ca3843aa154bdb0b08a0 | |
41 | fe72261 | |
42 | commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 | |
43 | 4d5fcadc293a348e88f777dc0920f11e7d71441c | |
44 | 4d5fcad | |
45 | EOF | |
46 | ||
47 | test_format parents %P%n%p <<'EOF' | |
48 | commit 131a310eb913d107dd3c09a65d1651175898735d | |
542e165c JH |
49 | 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 |
50 | 86c75cf | |
fa21b602 | 51 | commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 |
542e165c JH |
52 | |
53 | ||
fa21b602 JK |
54 | EOF |
55 | ||
56 | # we don't test relative here | |
57 | test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF' | |
58 | commit 131a310eb913d107dd3c09a65d1651175898735d | |
59 | A U Thor | |
60 | author@example.com | |
61 | Thu Apr 7 15:13:13 2005 -0700 | |
62 | Thu, 7 Apr 2005 15:13:13 -0700 | |
63 | 1112911993 | |
64 | commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 | |
65 | A U Thor | |
66 | author@example.com | |
67 | Thu Apr 7 15:13:13 2005 -0700 | |
68 | Thu, 7 Apr 2005 15:13:13 -0700 | |
69 | 1112911993 | |
70 | EOF | |
71 | ||
72 | test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF' | |
73 | commit 131a310eb913d107dd3c09a65d1651175898735d | |
74 | C O Mitter | |
75 | committer@example.com | |
76 | Thu Apr 7 15:13:13 2005 -0700 | |
77 | Thu, 7 Apr 2005 15:13:13 -0700 | |
78 | 1112911993 | |
79 | commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 | |
80 | C O Mitter | |
81 | committer@example.com | |
82 | Thu Apr 7 15:13:13 2005 -0700 | |
83 | Thu, 7 Apr 2005 15:13:13 -0700 | |
84 | 1112911993 | |
85 | EOF | |
86 | ||
87 | test_format encoding %e <<'EOF' | |
88 | commit 131a310eb913d107dd3c09a65d1651175898735d | |
fa21b602 | 89 | commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 |
fa21b602 JK |
90 | EOF |
91 | ||
92 | test_format subject %s <<'EOF' | |
93 | commit 131a310eb913d107dd3c09a65d1651175898735d | |
94 | changed foo | |
95 | commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 | |
96 | added foo | |
97 | EOF | |
98 | ||
99 | test_format body %b <<'EOF' | |
100 | commit 131a310eb913d107dd3c09a65d1651175898735d | |
fa21b602 | 101 | commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 |
fa21b602 JK |
102 | EOF |
103 | ||
1367b12a EB |
104 | test_format raw-body %B <<'EOF' |
105 | commit 131a310eb913d107dd3c09a65d1651175898735d | |
106 | changed foo | |
107 | ||
108 | commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 | |
109 | added foo | |
110 | ||
111 | EOF | |
112 | ||
fa21b602 JK |
113 | test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF' |
114 | commit 131a310eb913d107dd3c09a65d1651175898735d | |
115 | \e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy | |
116 | commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 | |
117 | \e[31mfoo\e[32mbar\e[34mbaz\e[mxyzzy | |
118 | EOF | |
119 | ||
c002922a JK |
120 | test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<'EOF' |
121 | commit 131a310eb913d107dd3c09a65d1651175898735d | |
122 | \e[1;31;43mfoo\e[m | |
123 | commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 | |
124 | \e[1;31;43mfoo\e[m | |
125 | EOF | |
126 | ||
03bcaaca JK |
127 | cat >commit-msg <<'EOF' |
128 | Test printing of complex bodies | |
129 | ||
130 | This commit message is much longer than the others, | |
131 | and it will be encoded in iso8859-1. We should therefore | |
132 | include an iso8859 character: ¡bueno! | |
133 | EOF | |
134 | test_expect_success 'setup complex body' ' | |
5be60078 | 135 | git config i18n.commitencoding iso8859-1 && |
3604e7c5 | 136 | echo change2 >foo && git commit -a -F commit-msg |
03bcaaca JK |
137 | ' |
138 | ||
139 | test_format complex-encoding %e <<'EOF' | |
140 | commit f58db70b055c5718631e5c61528b28b12090cdea | |
141 | iso8859-1 | |
142 | commit 131a310eb913d107dd3c09a65d1651175898735d | |
03bcaaca | 143 | commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 |
03bcaaca JK |
144 | EOF |
145 | ||
146 | test_format complex-subject %s <<'EOF' | |
147 | commit f58db70b055c5718631e5c61528b28b12090cdea | |
148 | Test printing of complex bodies | |
149 | commit 131a310eb913d107dd3c09a65d1651175898735d | |
150 | changed foo | |
151 | commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 | |
152 | added foo | |
153 | EOF | |
154 | ||
155 | test_format complex-body %b <<'EOF' | |
156 | commit f58db70b055c5718631e5c61528b28b12090cdea | |
157 | This commit message is much longer than the others, | |
158 | and it will be encoded in iso8859-1. We should therefore | |
159 | include an iso8859 character: ¡bueno! | |
160 | ||
161 | commit 131a310eb913d107dd3c09a65d1651175898735d | |
03bcaaca | 162 | commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 |
03bcaaca JK |
163 | EOF |
164 | ||
d36f8679 JK |
165 | test_expect_success '%ad respects --date=' ' |
166 | echo 2005-04-07 >expect.ad-short && | |
167 | git log -1 --date=short --pretty=tformat:%ad >output.ad-short master && | |
168 | test_cmp expect.ad-short output.ad-short | |
169 | ' | |
170 | ||
f7ab5c79 JH |
171 | test_expect_success 'empty email' ' |
172 | test_tick && | |
173 | C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) && | |
174 | A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) && | |
175 | test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700" || { | |
176 | echo "Eh? $A" >failure | |
177 | false | |
178 | } | |
179 | ' | |
180 | ||
9fa708da JH |
181 | test_expect_success 'del LF before empty (1)' ' |
182 | git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD^^ >actual && | |
183 | test $(wc -l <actual) = 2 | |
184 | ' | |
185 | ||
186 | test_expect_success 'del LF before empty (2)' ' | |
187 | git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD >actual && | |
188 | test $(wc -l <actual) = 6 && | |
189 | grep "^$" actual | |
190 | ' | |
191 | ||
192 | test_expect_success 'add LF before non-empty (1)' ' | |
193 | git show -s --pretty=format:"%s%+b%nThanks%n" HEAD^^ >actual && | |
194 | test $(wc -l <actual) = 2 | |
195 | ' | |
196 | ||
197 | test_expect_success 'add LF before non-empty (2)' ' | |
198 | git show -s --pretty=format:"%s%+b%nThanks%n" HEAD >actual && | |
199 | test $(wc -l <actual) = 6 && | |
200 | grep "^$" actual | |
201 | ' | |
202 | ||
7b88176e MG |
203 | test_expect_success 'add SP before non-empty (1)' ' |
204 | git show -s --pretty=format:"%s% bThanks" HEAD^^ >actual && | |
205 | test $(wc -w <actual) = 2 | |
206 | ' | |
207 | ||
208 | test_expect_success 'add SP before non-empty (2)' ' | |
209 | git show -s --pretty=format:"%s% sThanks" HEAD^^ >actual && | |
210 | test $(wc -w <actual) = 4 | |
211 | ' | |
212 | ||
c1977021 WP |
213 | test_expect_success '--abbrev' ' |
214 | echo SHORT SHORT SHORT >expect2 && | |
215 | echo LONG LONG LONG >expect3 && | |
216 | git log -1 --format="%h %h %h" HEAD >actual1 && | |
217 | git log -1 --abbrev=5 --format="%h %h %h" HEAD >actual2 && | |
218 | git log -1 --abbrev=5 --format="%H %H %H" HEAD >actual3 && | |
219 | sed -e "s/$_x40/LONG/g" -e "s/$_x05/SHORT/g" <actual2 >fuzzy2 && | |
220 | sed -e "s/$_x40/LONG/g" -e "s/$_x05/SHORT/g" <actual3 >fuzzy3 && | |
221 | test_cmp expect2 fuzzy2 && | |
222 | test_cmp expect3 fuzzy3 && | |
223 | ! test_cmp actual1 actual2 | |
224 | ' | |
225 | ||
226 | test_expect_success '%H is not affected by --abbrev-commit' ' | |
227 | git log -1 --format=%H --abbrev-commit --abbrev=20 HEAD >actual && | |
228 | len=$(wc -c <actual) && | |
229 | test $len = 41 | |
230 | ' | |
231 | ||
232 | test_expect_success '%h is not affected by --abbrev-commit' ' | |
233 | git log -1 --format=%h --abbrev-commit --abbrev=20 HEAD >actual && | |
234 | len=$(wc -c <actual) && | |
235 | test $len = 21 | |
236 | ' | |
237 | ||
8f8f5476 TR |
238 | test_expect_success '"%h %gD: %gs" is same as git-reflog' ' |
239 | git reflog >expect && | |
240 | git log -g --format="%h %gD: %gs" >actual && | |
241 | test_cmp expect actual | |
242 | ' | |
243 | ||
244 | test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' ' | |
245 | git reflog --date=raw >expect && | |
246 | git log -g --format="%h %gD: %gs" --date=raw >actual && | |
247 | test_cmp expect actual | |
248 | ' | |
249 | ||
c1977021 WP |
250 | test_expect_success '"%h %gD: %gs" is same as git-reflog (with --abbrev)' ' |
251 | git reflog --abbrev=13 --date=raw >expect && | |
252 | git log -g --abbrev=13 --format="%h %gD: %gs" --date=raw >actual && | |
253 | test_cmp expect actual | |
254 | ' | |
255 | ||
8f8f5476 TR |
256 | test_expect_success '%gd shortens ref name' ' |
257 | echo "master@{0}" >expect.gd-short && | |
258 | git log -g -1 --format=%gd refs/heads/master >actual.gd-short && | |
259 | test_cmp expect.gd-short actual.gd-short | |
260 | ' | |
261 | ||
1fb5fdd2 EFL |
262 | test_expect_success 'oneline with empty message' ' |
263 | git commit -m "dummy" --allow-empty && | |
264 | git commit -m "dummy" --allow-empty && | |
265 | git filter-branch --msg-filter "sed -e s/dummy//" HEAD^^.. && | |
f02dd06e | 266 | git rev-list --oneline HEAD >test.txt && |
1fb5fdd2 EFL |
267 | test $(git rev-list --oneline HEAD | wc -l) -eq 5 && |
268 | test $(git rev-list --oneline --graph HEAD | wc -l) -eq 5 | |
269 | ' | |
270 | ||
fa21b602 | 271 | test_done |