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