]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4052-stat-output.sh
git-add.txt: add missing short option -A to synopsis
[thirdparty/git.git] / t / t4052-stat-output.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2012 Zbigniew Jędrzejewski-Szmek
4 #
5
6 test_description='test --stat output of various commands'
7
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11 TEST_PASSES_SANITIZE_LEAK=true
12 . ./test-lib.sh
13 . "$TEST_DIRECTORY"/lib-terminal.sh
14
15 # 120 character name
16 name=aaaaaaaaaa
17 name=$name$name$name$name$name$name$name$name$name$name$name$name
18 test_expect_success 'preparation' '
19 >"$name" &&
20 git add "$name" &&
21 git commit -m message &&
22 echo a >"$name" &&
23 git commit -m message "$name"
24 '
25
26 cat >expect72 <<-'EOF'
27 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
28 EOF
29 test_expect_success "format-patch: small change with long name gives more space to the name" '
30 git format-patch -1 --stdout >output &&
31 grep " | " output >actual &&
32 test_cmp expect72 actual
33 '
34
35 while read cmd args
36 do
37 cat >expect80 <<-'EOF'
38 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
39 EOF
40 test_expect_success "$cmd: small change with long name gives more space to the name" '
41 git $cmd $args >output &&
42 grep " | " output >actual &&
43 test_cmp expect80 actual
44 '
45 done <<\EOF
46 diff HEAD^ HEAD --stat
47 show --stat
48 log -1 --stat
49 EOF
50
51 cat >expect.60 <<-'EOF'
52 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
53 EOF
54 cat >expect.6030 <<-'EOF'
55 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
56 EOF
57 cat >expect2.60 <<-'EOF'
58 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
59 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
60 EOF
61 cat >expect2.6030 <<-'EOF'
62 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
63 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
64 EOF
65 while read expect cmd args
66 do
67 test_expect_success "$cmd --stat=width: a long name is given more room when the bar is short" '
68 git $cmd $args --stat=40 >output &&
69 grep " | " output >actual &&
70 test_cmp $expect.60 actual
71 '
72
73 test_expect_success "$cmd --stat-width=width with long name" '
74 git $cmd $args --stat-width=40 >output &&
75 grep " | " output >actual &&
76 test_cmp $expect.60 actual
77 '
78
79 test_expect_success "$cmd --stat=...,name-width with long name" '
80 git $cmd $args --stat=60,30 >output &&
81 grep " | " output >actual &&
82 test_cmp $expect.6030 actual
83 '
84
85 test_expect_success "$cmd --stat-name-width with long name" '
86 git $cmd $args --stat-name-width=30 >output &&
87 grep " | " output >actual &&
88 test_cmp $expect.6030 actual
89 '
90 done <<\EOF
91 expect2 format-patch --cover-letter -1 --stdout
92 expect diff HEAD^ HEAD --stat
93 expect show --stat
94 expect log -1 --stat
95 EOF
96
97
98 test_expect_success 'preparation for big change tests' '
99 >abcd &&
100 git add abcd &&
101 git commit -m message &&
102 i=0 &&
103 while test $i -lt 1000
104 do
105 echo $i && i=$(($i + 1)) || return 1
106 done >abcd &&
107 git commit -m message abcd
108 '
109
110 cat >expect72 <<'EOF'
111 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
112 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
113 EOF
114 test_expect_success "format-patch --cover-letter ignores COLUMNS (big change)" '
115 COLUMNS=200 git format-patch -1 --stdout --cover-letter >output &&
116 grep " | " output >actual &&
117 test_cmp expect72 actual
118 '
119
120 cat >expect72 <<'EOF'
121 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
122 EOF
123 cat >expect72-graph <<'EOF'
124 | abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
125 EOF
126 cat >expect200 <<'EOF'
127 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
128 EOF
129 cat >expect200-graph <<'EOF'
130 | abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
131 EOF
132 while read verb expect cmd args
133 do
134 test_expect_success "$cmd $verb COLUMNS (big change)" '
135 COLUMNS=200 git $cmd $args >output &&
136 grep " | " output >actual &&
137 test_cmp "$expect" actual
138 '
139
140 case "$cmd" in diff|show) continue;; esac
141
142 test_expect_success "$cmd --graph $verb COLUMNS (big change)" '
143 COLUMNS=200 git $cmd $args --graph >output &&
144 grep " | " output >actual &&
145 test_cmp "$expect-graph" actual
146 '
147 done <<\EOF
148 ignores expect72 format-patch -1 --stdout
149 respects expect200 diff HEAD^ HEAD --stat
150 respects expect200 show --stat
151 respects expect200 log -1 --stat
152 EOF
153
154 cat >expect40 <<'EOF'
155 abcd | 1000 ++++++++++++++++++++++++++
156 EOF
157 cat >expect40-graph <<'EOF'
158 | abcd | 1000 ++++++++++++++++++++++++
159 EOF
160 while read verb expect cmd args
161 do
162 test_expect_success "$cmd $verb not enough COLUMNS (big change)" '
163 COLUMNS=40 git $cmd $args >output &&
164 grep " | " output >actual &&
165 test_cmp "$expect" actual
166 '
167
168 case "$cmd" in diff|show) continue;; esac
169
170 test_expect_success "$cmd --graph $verb not enough COLUMNS (big change)" '
171 COLUMNS=40 git $cmd $args --graph >output &&
172 grep " | " output >actual &&
173 test_cmp "$expect-graph" actual
174 '
175 done <<\EOF
176 ignores expect72 format-patch -1 --stdout
177 respects expect40 diff HEAD^ HEAD --stat
178 respects expect40 show --stat
179 respects expect40 log -1 --stat
180 EOF
181
182 cat >expect40 <<'EOF'
183 abcd | 1000 ++++++++++++++++++++++++++
184 EOF
185 cat >expect40-graph <<'EOF'
186 | abcd | 1000 ++++++++++++++++++++++++++
187 EOF
188 while read verb expect cmd args
189 do
190 test_expect_success "$cmd $verb statGraphWidth config" '
191 git -c diff.statGraphWidth=26 $cmd $args >output &&
192 grep " | " output >actual &&
193 test_cmp "$expect" actual
194 '
195
196 case "$cmd" in diff|show) continue;; esac
197
198 test_expect_success "$cmd --graph $verb statGraphWidth config" '
199 git -c diff.statGraphWidth=26 $cmd $args --graph >output &&
200 grep " | " output >actual &&
201 test_cmp "$expect-graph" actual
202 '
203 done <<\EOF
204 ignores expect72 format-patch -1 --stdout
205 respects expect40 diff HEAD^ HEAD --stat
206 respects expect40 show --stat
207 respects expect40 log -1 --stat
208 EOF
209
210
211 cat >expect <<'EOF'
212 abcd | 1000 ++++++++++++++++++++++++++
213 EOF
214 cat >expect-graph <<'EOF'
215 | abcd | 1000 ++++++++++++++++++++++++++
216 EOF
217 while read cmd args
218 do
219 test_expect_success "$cmd --stat=width with big change" '
220 git $cmd $args --stat=40 >output &&
221 grep " | " output >actual &&
222 test_cmp expect actual
223 '
224
225 test_expect_success "$cmd --stat-width=width with big change" '
226 git $cmd $args --stat-width=40 >output &&
227 grep " | " output >actual &&
228 test_cmp expect actual
229 '
230
231 test_expect_success "$cmd --stat-graph-width with big change" '
232 git $cmd $args --stat-graph-width=26 >output &&
233 grep " | " output >actual &&
234 test_cmp expect actual
235 '
236
237 case "$cmd" in diff|show) continue;; esac
238
239 test_expect_success "$cmd --stat-width=width --graph with big change" '
240 git $cmd $args --stat-width=40 --graph >output &&
241 grep " | " output >actual &&
242 test_cmp expect-graph actual
243 '
244
245 test_expect_success "$cmd --stat-graph-width --graph with big change" '
246 git $cmd $args --stat-graph-width=26 --graph >output &&
247 grep " | " output >actual &&
248 test_cmp expect-graph actual
249 '
250 done <<\EOF
251 format-patch -1 --stdout
252 diff HEAD^ HEAD --stat
253 show --stat
254 log -1 --stat
255 EOF
256
257 test_expect_success 'preparation for long filename tests' '
258 cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
259 git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
260 git commit -m message
261 '
262
263 cat >expect <<'EOF'
264 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
265 EOF
266 cat >expect-graph <<'EOF'
267 | ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
268 EOF
269 while read cmd args
270 do
271 test_expect_success "$cmd --stat=width with big change is more balanced" '
272 git $cmd $args --stat-width=60 >output &&
273 grep " | " output >actual &&
274 test_cmp expect actual
275 '
276
277 case "$cmd" in diff|show) continue;; esac
278
279 test_expect_success "$cmd --stat=width --graph with big change is balanced" '
280 git $cmd $args --stat-width=60 --graph >output &&
281 grep " | " output >actual &&
282 test_cmp expect-graph actual
283 '
284 done <<\EOF
285 format-patch -1 --stdout
286 diff HEAD^ HEAD --stat
287 show --stat
288 log -1 --stat
289 EOF
290
291 cat >expect72 <<'EOF'
292 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
293 EOF
294 cat >expect72-graph <<'EOF'
295 | ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
296 EOF
297 cat >expect200 <<'EOF'
298 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
299 EOF
300 cat >expect200-graph <<'EOF'
301 | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
302 EOF
303 while read verb expect cmd args
304 do
305 test_expect_success "$cmd $verb COLUMNS (long filename)" '
306 COLUMNS=200 git $cmd $args >output &&
307 grep " | " output >actual &&
308 test_cmp "$expect" actual
309 '
310
311 case "$cmd" in diff|show) continue;; esac
312
313 test_expect_success "$cmd --graph $verb COLUMNS (long filename)" '
314 COLUMNS=200 git $cmd $args --graph >output &&
315 grep " | " output >actual &&
316 test_cmp "$expect-graph" actual
317 '
318 done <<\EOF
319 ignores expect72 format-patch -1 --stdout
320 respects expect200 diff HEAD^ HEAD --stat
321 respects expect200 show --stat
322 respects expect200 log -1 --stat
323 EOF
324
325 cat >expect1 <<'EOF'
326 ...aaaaaaa | 1000 ++++++
327 EOF
328 cat >expect1-graph <<'EOF'
329 | ...aaaaaaa | 1000 ++++++
330 EOF
331 while read verb expect cmd args
332 do
333 test_expect_success COLUMNS_CAN_BE_1 \
334 "$cmd $verb prefix greater than COLUMNS (big change)" '
335 COLUMNS=1 git $cmd $args >output &&
336 grep " | " output >actual &&
337 test_cmp "$expect" actual
338 '
339
340 case "$cmd" in diff|show) continue;; esac
341
342 test_expect_success COLUMNS_CAN_BE_1 \
343 "$cmd --graph $verb prefix greater than COLUMNS (big change)" '
344 COLUMNS=1 git $cmd $args --graph >output &&
345 grep " | " output >actual &&
346 test_cmp "$expect-graph" actual
347 '
348 done <<\EOF
349 ignores expect72 format-patch -1 --stdout
350 respects expect1 diff HEAD^ HEAD --stat
351 respects expect1 show --stat
352 respects expect1 log -1 --stat
353 EOF
354
355 cat >expect <<'EOF'
356 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
357 EOF
358 test_expect_success 'merge --stat respects COLUMNS (big change)' '
359 git checkout -b branch HEAD^^ &&
360 COLUMNS=100 git merge --stat --no-ff main^ >output &&
361 grep " | " output >actual &&
362 test_cmp expect actual
363 '
364
365 cat >expect <<'EOF'
366 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++
367 EOF
368 test_expect_success 'merge --stat respects COLUMNS (long filename)' '
369 COLUMNS=100 git merge --stat --no-ff main >output &&
370 grep " | " output >actual &&
371 test_cmp expect actual
372 '
373
374 test_done