]>
Commit | Line | Data |
---|---|---|
8028184e WP |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2010, Will Palmer | |
4 | # | |
5 | ||
6 | test_description='Test pretty formats' | |
7 | . ./test-lib.sh | |
8 | ||
9 | test_expect_success 'set up basic repos' ' | |
10 | >foo && | |
11 | >bar && | |
12 | git add foo && | |
13 | test_tick && | |
14 | git commit -m initial && | |
15 | git add bar && | |
16 | test_tick && | |
17 | git commit -m "add bar" | |
18 | ' | |
19 | ||
20 | test_expect_success 'alias builtin format' ' | |
21 | git log --pretty=oneline >expected && | |
22 | git config pretty.test-alias oneline && | |
23 | git log --pretty=test-alias >actual && | |
24 | test_cmp expected actual | |
25 | ' | |
26 | ||
27 | test_expect_success 'alias masking builtin format' ' | |
28 | git log --pretty=oneline >expected && | |
29 | git config pretty.oneline "%H" && | |
30 | git log --pretty=oneline >actual && | |
31 | test_cmp expected actual | |
32 | ' | |
33 | ||
34 | test_expect_success 'alias user-defined format' ' | |
35 | git log --pretty="format:%h" >expected && | |
36 | git config pretty.test-alias "format:%h" && | |
37 | git log --pretty=test-alias >actual && | |
38 | test_cmp expected actual | |
39 | ' | |
40 | ||
41 | test_expect_success 'alias user-defined tformat' ' | |
42 | git log --pretty="tformat:%h" >expected && | |
43 | git config pretty.test-alias "tformat:%h" && | |
44 | git log --pretty=test-alias >actual && | |
45 | test_cmp expected actual | |
46 | ' | |
47 | ||
7be8b3ba | 48 | test_expect_success 'alias non-existent format' ' |
8028184e WP |
49 | git config pretty.test-alias format-that-will-never-exist && |
50 | test_must_fail git log --pretty=test-alias | |
51 | ' | |
52 | ||
53 | test_expect_success 'alias of an alias' ' | |
54 | git log --pretty="tformat:%h" >expected && | |
55 | git config pretty.test-foo "tformat:%h" && | |
56 | git config pretty.test-bar test-foo && | |
57 | git log --pretty=test-bar >actual && test_cmp expected actual | |
58 | ' | |
59 | ||
60 | test_expect_success 'alias masking an alias' ' | |
61 | git log --pretty=format:"Two %H" >expected && | |
62 | git config pretty.duplicate "format:One %H" && | |
63 | git config --add pretty.duplicate "format:Two %H" && | |
64 | git log --pretty=duplicate >actual && | |
65 | test_cmp expected actual | |
66 | ' | |
67 | ||
68 | test_expect_success 'alias loop' ' | |
69 | git config pretty.test-foo test-bar && | |
70 | git config pretty.test-bar test-foo && | |
71 | test_must_fail git log --pretty=test-foo | |
72 | ' | |
73 | ||
3e065308 JK |
74 | test_expect_success 'NUL separation' ' |
75 | printf "add bar\0initial" >expected && | |
76 | git log -z --pretty="format:%s" >actual && | |
77 | test_cmp expected actual | |
78 | ' | |
79 | ||
80 | test_expect_success 'NUL termination' ' | |
81 | printf "add bar\0initial\0" >expected && | |
82 | git log -z --pretty="tformat:%s" >actual && | |
83 | test_cmp expected actual | |
84 | ' | |
85 | ||
fafd3829 JH |
86 | test_expect_success 'NUL separation with --stat' ' |
87 | stat0_part=$(git diff --stat HEAD^ HEAD) && | |
74faaa16 | 88 | stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) && |
fafd3829 JH |
89 | printf "add bar\n$stat0_part\n\0initial\n$stat1_part\n" >expected && |
90 | git log -z --stat --pretty="format:%s" >actual && | |
b354f11b | 91 | test_i18ncmp expected actual |
fafd3829 JH |
92 | ' |
93 | ||
94 | test_expect_failure 'NUL termination with --stat' ' | |
95 | stat0_part=$(git diff --stat HEAD^ HEAD) && | |
74faaa16 | 96 | stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) && |
fafd3829 JH |
97 | printf "add bar\n$stat0_part\n\0initial\n$stat1_part\n\0" >expected && |
98 | git log -z --stat --pretty="tformat:%s" >actual && | |
b354f11b | 99 | test_i18ncmp expected actual |
fafd3829 JH |
100 | ' |
101 | ||
a5752342 NTND |
102 | test_expect_success 'setup more commits' ' |
103 | test_commit "message one" one one message-one && | |
a742f2a0 AS |
104 | test_commit "message two" two two message-two && |
105 | head1=$(git rev-parse --verify --short HEAD~0) && | |
106 | head2=$(git rev-parse --verify --short HEAD~1) && | |
107 | head3=$(git rev-parse --verify --short HEAD~2) && | |
108 | head4=$(git rev-parse --verify --short HEAD~3) | |
a5752342 NTND |
109 | ' |
110 | ||
111 | test_expect_success 'left alignment formatting' ' | |
112 | git log --pretty="format:%<(40)%s" >actual && | |
113 | # complete the incomplete line at the end | |
114 | echo >>actual && | |
115 | qz_to_tab_space <<\EOF >expected && | |
116 | message two Z | |
117 | message one Z | |
118 | add bar Z | |
119 | initial Z | |
120 | EOF | |
121 | test_cmp expected actual | |
122 | ' | |
123 | ||
a742f2a0 AS |
124 | test_expect_success 'left alignment formatting at the nth column' " |
125 | git log --pretty='format:%h %<|(40)%s' >actual && | |
a5752342 NTND |
126 | # complete the incomplete line at the end |
127 | echo >>actual && | |
128 | qz_to_tab_space <<\EOF >expected && | |
a742f2a0 AS |
129 | $head1 message two Z |
130 | $head2 message one Z | |
131 | $head3 add bar Z | |
132 | $head4 initial Z | |
a5752342 NTND |
133 | EOF |
134 | test_cmp expected actual | |
a742f2a0 | 135 | " |
a5752342 NTND |
136 | |
137 | test_expect_success 'left alignment formatting with no padding' ' | |
138 | git log --pretty="format:%<(1)%s" >actual && | |
139 | # complete the incomplete line at the end | |
140 | echo >>actual && | |
141 | cat <<\EOF >expected && | |
142 | message two | |
143 | message one | |
144 | add bar | |
145 | initial | |
146 | EOF | |
147 | test_cmp expected actual | |
148 | ' | |
149 | ||
a7f01c6b NTND |
150 | test_expect_success 'left alignment formatting with trunc' ' |
151 | git log --pretty="format:%<(10,trunc)%s" >actual && | |
152 | # complete the incomplete line at the end | |
153 | echo >>actual && | |
154 | qz_to_tab_space <<\EOF >expected && | |
155 | message .. | |
156 | message .. | |
157 | add bar Z | |
158 | initial Z | |
159 | EOF | |
160 | test_cmp expected actual | |
161 | ' | |
162 | ||
163 | test_expect_success 'left alignment formatting with ltrunc' ' | |
164 | git log --pretty="format:%<(10,ltrunc)%s" >actual && | |
165 | # complete the incomplete line at the end | |
166 | echo >>actual && | |
167 | qz_to_tab_space <<\EOF >expected && | |
168 | ..sage two | |
169 | ..sage one | |
170 | add bar Z | |
171 | initial Z | |
172 | EOF | |
173 | test_cmp expected actual | |
174 | ' | |
175 | ||
176 | test_expect_success 'left alignment formatting with mtrunc' ' | |
177 | git log --pretty="format:%<(10,mtrunc)%s" >actual && | |
178 | # complete the incomplete line at the end | |
179 | echo >>actual && | |
180 | qz_to_tab_space <<\EOF >expected && | |
181 | mess.. two | |
182 | mess.. one | |
183 | add bar Z | |
184 | initial Z | |
185 | EOF | |
186 | test_cmp expected actual | |
187 | ' | |
188 | ||
a5752342 NTND |
189 | test_expect_success 'right alignment formatting' ' |
190 | git log --pretty="format:%>(40)%s" >actual && | |
191 | # complete the incomplete line at the end | |
192 | echo >>actual && | |
193 | qz_to_tab_space <<\EOF >expected && | |
194 | Z message two | |
195 | Z message one | |
196 | Z add bar | |
197 | Z initial | |
198 | EOF | |
199 | test_cmp expected actual | |
200 | ' | |
201 | ||
a742f2a0 AS |
202 | test_expect_success 'right alignment formatting at the nth column' " |
203 | git log --pretty='format:%h %>|(40)%s' >actual && | |
a5752342 NTND |
204 | # complete the incomplete line at the end |
205 | echo >>actual && | |
206 | qz_to_tab_space <<\EOF >expected && | |
a742f2a0 AS |
207 | $head1 message two |
208 | $head2 message one | |
209 | $head3 add bar | |
210 | $head4 initial | |
a5752342 NTND |
211 | EOF |
212 | test_cmp expected actual | |
a742f2a0 | 213 | " |
a5752342 NTND |
214 | |
215 | test_expect_success 'right alignment formatting with no padding' ' | |
216 | git log --pretty="format:%>(1)%s" >actual && | |
217 | # complete the incomplete line at the end | |
218 | echo >>actual && | |
219 | cat <<\EOF >expected && | |
220 | message two | |
221 | message one | |
222 | add bar | |
223 | initial | |
224 | EOF | |
225 | test_cmp expected actual | |
226 | ' | |
227 | ||
228 | test_expect_success 'center alignment formatting' ' | |
229 | git log --pretty="format:%><(40)%s" >actual && | |
230 | # complete the incomplete line at the end | |
231 | echo >>actual && | |
232 | qz_to_tab_space <<\EOF >expected && | |
233 | Z message two Z | |
234 | Z message one Z | |
235 | Z add bar Z | |
236 | Z initial Z | |
237 | EOF | |
238 | test_cmp expected actual | |
239 | ' | |
240 | ||
a742f2a0 AS |
241 | test_expect_success 'center alignment formatting at the nth column' " |
242 | git log --pretty='format:%h %><|(40)%s' >actual && | |
a5752342 NTND |
243 | # complete the incomplete line at the end |
244 | echo >>actual && | |
245 | qz_to_tab_space <<\EOF >expected && | |
a742f2a0 AS |
246 | $head1 message two Z |
247 | $head2 message one Z | |
248 | $head3 add bar Z | |
249 | $head4 initial Z | |
a5752342 NTND |
250 | EOF |
251 | test_cmp expected actual | |
a742f2a0 | 252 | " |
a5752342 NTND |
253 | |
254 | test_expect_success 'center alignment formatting with no padding' ' | |
255 | git log --pretty="format:%><(1)%s" >actual && | |
256 | # complete the incomplete line at the end | |
257 | echo >>actual && | |
258 | cat <<\EOF >expected && | |
259 | message two | |
260 | message one | |
261 | add bar | |
262 | initial | |
263 | EOF | |
264 | test_cmp expected actual | |
265 | ' | |
266 | ||
1640632b NTND |
267 | test_expect_success 'left/right alignment formatting with stealing' ' |
268 | git commit --amend -m short --author "long long long <long@me.com>" && | |
269 | git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && | |
270 | # complete the incomplete line at the end | |
271 | echo >>actual && | |
272 | cat <<\EOF >expected && | |
273 | short long long long | |
274 | message .. A U Thor | |
275 | add bar A U Thor | |
276 | initial A U Thor | |
277 | EOF | |
278 | test_cmp expected actual | |
279 | ' | |
280 | ||
8028184e | 281 | test_done |