3 # Copyright (c) 2012 Zbigniew Jędrzejewski-Szmek
6 test_description
='test --stat output of various commands'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 TEST_PASSES_SANITIZE_LEAK
=true
13 .
"$TEST_DIRECTORY"/lib-terminal.sh
17 name
=$name$name$name$name$name$name$name$name$name$name$name$name
18 test_expect_success
'preparation' '
21 git commit -m message &&
23 git commit -m message "$name"
26 cat >expect72
<<-'EOF'
27 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
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
37 cat >expect80
<<-'EOF'
38 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
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
46 diff HEAD^ HEAD
--stat
51 cat >expect
.60 <<-'EOF'
52 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
54 cat >expect
.6030 <<-'EOF'
55 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
57 while read verb expect cmd args
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
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
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
83 cat >expect
.40 <<-'EOF'
84 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
86 cat >expect2.40
<<-'EOF'
87 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
88 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
90 cat >expect2.6030
<<-'EOF'
91 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
92 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
94 while read expect cmd args
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
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
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
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
120 expect2 format-patch
--cover-letter -1 --stdout
121 expect
diff HEAD^ HEAD
--stat
126 test_expect_success
'preparation for big-change tests' '
129 git commit -m message &&
131 while test $i -lt 1000
133 echo $i && i=$(($i + 1)) || return 1
135 git commit -m message abcd
138 cat >expect72
<<'EOF'
139 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
140 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
148 cat >expect72
<<'EOF'
149 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
151 cat >expect72-graph
<<'EOF'
152 | abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
154 cat >expect200
<<'EOF'
155 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
157 cat >expect200-graph
<<'EOF'
158 | abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
160 while read verb expect cmd args
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
168 case "$cmd" in diff|show
) continue;; esac
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
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
182 cat >expect40
<<'EOF'
183 abcd | 1000 ++++++++++++++++++++++++++
185 cat >expect40-graph
<<'EOF'
186 | abcd | 1000 ++++++++++++++++++++++++
188 while read verb expect cmd args
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
196 case "$cmd" in diff|show
) continue;; esac
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
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
210 cat >expect40
<<'EOF'
211 abcd | 1000 ++++++++++++++++++++++++++
213 cat >expect40-graph
<<'EOF'
214 | abcd | 1000 ++++++++++++++++++++++++++
216 while read verb expect cmd args
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
224 case "$cmd" in diff|show
) continue;; esac
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
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
239 abcd | 1000 ++++++++++++++++++++++++++
241 cat >expect-graph
<<'EOF'
242 | abcd | 1000 ++++++++++++++++++++++++++
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
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
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
264 case "$cmd" in diff|show
) continue;; esac
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
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
278 format-patch
-1 --stdout
279 diff HEAD^ HEAD
--stat
284 test_expect_success
'preparation for long-name tests' '
285 cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
286 git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
287 git commit -m message
291 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
293 cat >expect-graph
<<'EOF'
294 | ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
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
304 case "$cmd" in diff|show
) continue;; esac
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
312 format-patch
-1 --stdout
313 diff HEAD^ HEAD
--stat
318 cat >expect72
<<'EOF'
319 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
321 cat >expect72-graph
<<'EOF'
322 | ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
324 cat >expect200
<<'EOF'
325 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
327 cat >expect200-graph
<<'EOF'
328 | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
330 while read verb expect cmd args
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
338 case "$cmd" in diff|show
) continue;; esac
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
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
353 ...aaaaaaa | 1000 ++++++
355 cat >expect1-graph
<<'EOF'
356 | ...aaaaaaa | 1000 ++++++
358 while read verb expect cmd args
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
367 case "$cmd" in diff|show
) continue;; esac
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
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
383 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
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
399 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++
401 cat >expect
.30 <<'EOF'
402 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++++++++++++++++++++++++++++++
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
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