]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4052-stat-output.sh
Sync with Git 2.45.1
[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 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
53 EOF
54 cat >expect.6030 <<-'EOF'
55 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
56 EOF
57 while read verb expect cmd args
58 do
59 # No width limit applied when statNameWidth is ignored
60 case "$expect" in expect72|expect.6030)
61 test_expect_success "$cmd $verb diff.statNameWidth with long name" '
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)
69 test_expect_success "$cmd --stat=width $verb diff.statNameWidth with long name" '
70 git -c diff.statNameWidth=30 $cmd $args --stat=60 >output &&
71 grep " | " output >actual &&
72 test_cmp $expect actual
73 ';;
74 esac
75 done <<\EOF
76 ignores expect72 format-patch -1 --stdout
77 ignores expect.60 format-patch -1 --stdout
78 respects expect.6030 diff HEAD^ HEAD --stat
79 respects expect.6030 show --stat
80 respects expect.6030 log -1 --stat
81 EOF
82
83 cat >expect.40 <<-'EOF'
84 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
85 EOF
86 cat >expect2.40 <<-'EOF'
87 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
88 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
89 EOF
90 cat >expect2.6030 <<-'EOF'
91 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
92 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
93 EOF
94 while read expect cmd args
95 do
96 test_expect_success "$cmd --stat=width: a long name is given more room when the bar is short" '
97 git $cmd $args --stat=40 >output &&
98 grep " | " output >actual &&
99 test_cmp $expect.40 actual
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 &&
105 test_cmp $expect.40 actual
106 '
107
108 test_expect_success "$cmd --stat=width,name-width with long name" '
109 git $cmd $args --stat=60,30 >output &&
110 grep " | " output >actual &&
111 test_cmp $expect.6030 actual
112 '
113
114 test_expect_success "$cmd --stat-name-width=width with long name" '
115 git $cmd $args --stat-name-width=30 >output &&
116 grep " | " output >actual &&
117 test_cmp $expect.6030 actual
118 '
119 done <<\EOF
120 expect2 format-patch --cover-letter -1 --stdout
121 expect diff HEAD^ HEAD --stat
122 expect show --stat
123 expect log -1 --stat
124 EOF
125
126 test_expect_success 'preparation for big-change tests' '
127 >abcd &&
128 git add abcd &&
129 git commit -m message &&
130 i=0 &&
131 while test $i -lt 1000
132 do
133 echo $i && i=$(($i + 1)) || return 1
134 done >abcd &&
135 git commit -m message abcd
136 '
137
138 cat >expect72 <<'EOF'
139 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
140 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
141 EOF
142 test_expect_success "format-patch --cover-letter ignores COLUMNS with big change" '
143 COLUMNS=200 git format-patch -1 --stdout --cover-letter >output &&
144 grep " | " output >actual &&
145 test_cmp expect72 actual
146 '
147
148 cat >expect72 <<'EOF'
149 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
150 EOF
151 cat >expect72-graph <<'EOF'
152 | abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
153 EOF
154 cat >expect200 <<'EOF'
155 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
156 EOF
157 cat >expect200-graph <<'EOF'
158 | abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
159 EOF
160 while read verb expect cmd args
161 do
162 test_expect_success "$cmd $verb COLUMNS with big change" '
163 COLUMNS=200 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 COLUMNS with big change" '
171 COLUMNS=200 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 expect200 diff HEAD^ HEAD --stat
178 respects expect200 show --stat
179 respects expect200 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 not enough COLUMNS with big change" '
191 COLUMNS=40 git $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 not enough COLUMNS with big change" '
199 COLUMNS=40 git $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 cat >expect40 <<'EOF'
211 abcd | 1000 ++++++++++++++++++++++++++
212 EOF
213 cat >expect40-graph <<'EOF'
214 | abcd | 1000 ++++++++++++++++++++++++++
215 EOF
216 while read verb expect cmd args
217 do
218 test_expect_success "$cmd $verb diff.statGraphWidth" '
219 git -c diff.statGraphWidth=26 $cmd $args >output &&
220 grep " | " output >actual &&
221 test_cmp "$expect" actual
222 '
223
224 case "$cmd" in diff|show) continue;; esac
225
226 test_expect_success "$cmd --graph $verb diff.statGraphWidth" '
227 git -c diff.statGraphWidth=26 $cmd $args --graph >output &&
228 grep " | " output >actual &&
229 test_cmp "$expect-graph" actual
230 '
231 done <<\EOF
232 ignores expect72 format-patch -1 --stdout
233 respects expect40 diff HEAD^ HEAD --stat
234 respects expect40 show --stat
235 respects expect40 log -1 --stat
236 EOF
237
238 cat >expect <<'EOF'
239 abcd | 1000 ++++++++++++++++++++++++++
240 EOF
241 cat >expect-graph <<'EOF'
242 | abcd | 1000 ++++++++++++++++++++++++++
243 EOF
244 while read cmd args
245 do
246 test_expect_success "$cmd --stat=width with big change" '
247 git $cmd $args --stat=40 >output &&
248 grep " | " output >actual &&
249 test_cmp expect actual
250 '
251
252 test_expect_success "$cmd --stat-width=width with big change" '
253 git $cmd $args --stat-width=40 >output &&
254 grep " | " output >actual &&
255 test_cmp expect actual
256 '
257
258 test_expect_success "$cmd --stat-graph-width=width with big change" '
259 git $cmd $args --stat-graph-width=26 >output &&
260 grep " | " output >actual &&
261 test_cmp expect actual
262 '
263
264 case "$cmd" in diff|show) continue;; esac
265
266 test_expect_success "$cmd --stat-width=width --graph with big change" '
267 git $cmd $args --stat-width=40 --graph >output &&
268 grep " | " output >actual &&
269 test_cmp expect-graph actual
270 '
271
272 test_expect_success "$cmd --stat-graph-width=width --graph with big change" '
273 git $cmd $args --stat-graph-width=26 --graph >output &&
274 grep " | " output >actual &&
275 test_cmp expect-graph actual
276 '
277 done <<\EOF
278 format-patch -1 --stdout
279 diff HEAD^ HEAD --stat
280 show --stat
281 log -1 --stat
282 EOF
283
284 test_expect_success 'preparation for long-name tests' '
285 cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
286 git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
287 git commit -m message
288 '
289
290 cat >expect <<'EOF'
291 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
292 EOF
293 cat >expect-graph <<'EOF'
294 | ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
295 EOF
296 while read cmd args
297 do
298 test_expect_success "$cmd --stat=width with big change is more balanced" '
299 git $cmd $args --stat-width=60 >output &&
300 grep " | " output >actual &&
301 test_cmp expect actual
302 '
303
304 case "$cmd" in diff|show) continue;; esac
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 '
311 done <<\EOF
312 format-patch -1 --stdout
313 diff HEAD^ HEAD --stat
314 show --stat
315 log -1 --stat
316 EOF
317
318 cat >expect72 <<'EOF'
319 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
320 EOF
321 cat >expect72-graph <<'EOF'
322 | ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
323 EOF
324 cat >expect200 <<'EOF'
325 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
326 EOF
327 cat >expect200-graph <<'EOF'
328 | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
329 EOF
330 while read verb expect cmd args
331 do
332 test_expect_success "$cmd $verb COLUMNS with long name" '
333 COLUMNS=200 git $cmd $args >output &&
334 grep " | " output >actual &&
335 test_cmp "$expect" actual
336 '
337
338 case "$cmd" in diff|show) continue;; esac
339
340 test_expect_success "$cmd --graph $verb COLUMNS with long name" '
341 COLUMNS=200 git $cmd $args --graph >output &&
342 grep " | " output >actual &&
343 test_cmp "$expect-graph" actual
344 '
345 done <<\EOF
346 ignores expect72 format-patch -1 --stdout
347 respects expect200 diff HEAD^ HEAD --stat
348 respects expect200 show --stat
349 respects expect200 log -1 --stat
350 EOF
351
352 cat >expect1 <<'EOF'
353 ...aaaaaaa | 1000 ++++++
354 EOF
355 cat >expect1-graph <<'EOF'
356 | ...aaaaaaa | 1000 ++++++
357 EOF
358 while read verb expect cmd args
359 do
360 test_expect_success COLUMNS_CAN_BE_1 \
361 "$cmd $verb prefix greater than COLUMNS with big change" '
362 COLUMNS=1 git $cmd $args >output &&
363 grep " | " output >actual &&
364 test_cmp "$expect" actual
365 '
366
367 case "$cmd" in diff|show) continue;; esac
368
369 test_expect_success COLUMNS_CAN_BE_1 \
370 "$cmd --graph $verb prefix greater than COLUMNS with big change" '
371 COLUMNS=1 git $cmd $args --graph >output &&
372 grep " | " output >actual &&
373 test_cmp "$expect-graph" actual
374 '
375 done <<\EOF
376 ignores expect72 format-patch -1 --stdout
377 respects expect1 diff HEAD^ HEAD --stat
378 respects expect1 show --stat
379 respects expect1 log -1 --stat
380 EOF
381
382 cat >expect <<'EOF'
383 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
384 EOF
385 test_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 '
391 test_expect_success 'merge --stat respects COLUMNS with big change' '
392 git checkout -b branch2 HEAD^^ &&
393 COLUMNS=100 git merge --stat --no-ff main^ >output &&
394 grep " | " output >actual &&
395 test_cmp expect actual
396 '
397
398 cat >expect <<'EOF'
399 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++
400 EOF
401 cat >expect.30 <<'EOF'
402 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++++++++++++++++++++++
403 EOF
404 test_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 '
410 test_expect_success 'merge --stat respects COLUMNS with long name' '
411 git switch branch2 &&
412 COLUMNS=100 git merge --stat --no-ff main >output &&
413 grep " | " output >actual &&
414 test_cmp expect actual
415 '
416
417 test_done