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
12 .
"$TEST_DIRECTORY"/lib-terminal.sh
16 name
=$name$name$name$name$name$name$name$name$name$name$name$name
17 test_expect_success
'preparation' '
20 git commit -m message &&
22 git commit -m message "$name"
25 cat >expect72
<<-'EOF'
26 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
28 test_expect_success
"format-patch: small change with long name gives more space to the name" '
29 git format-patch -1 --stdout >output &&
30 grep " | " output >actual &&
31 test_cmp expect72 actual
36 cat >expect80
<<-'EOF'
37 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
39 test_expect_success
"$cmd: small change with long name gives more space to the name" '
40 git $cmd $args >output &&
41 grep " | " output >actual &&
42 test_cmp expect80 actual
45 diff HEAD^ HEAD
--stat
50 cat >expect
.60 <<-'EOF'
51 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
53 cat >expect
.6030 <<-'EOF'
54 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
56 cat >expect2.60
<<-'EOF'
57 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
58 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
60 cat >expect2.6030
<<-'EOF'
61 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
62 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
64 while read expect cmd args
66 test_expect_success
"$cmd --stat=width: a long name is given more room when the bar is short" '
67 git $cmd $args --stat=40 >output &&
68 grep " | " output >actual &&
69 test_cmp $expect.60 actual
72 test_expect_success
"$cmd --stat-width=width with long name" '
73 git $cmd $args --stat-width=40 >output &&
74 grep " | " output >actual &&
75 test_cmp $expect.60 actual
78 test_expect_success
"$cmd --stat=...,name-width with long name" '
79 git $cmd $args --stat=60,30 >output &&
80 grep " | " output >actual &&
81 test_cmp $expect.6030 actual
84 test_expect_success
"$cmd --stat-name-width with long name" '
85 git $cmd $args --stat-name-width=30 >output &&
86 grep " | " output >actual &&
87 test_cmp $expect.6030 actual
90 expect2 format-patch
--cover-letter -1 --stdout
91 expect
diff HEAD^ HEAD
--stat
97 test_expect_success
'preparation for big change tests' '
100 git commit -m message &&
102 while test $i -lt 1000
104 echo $i && i=$(($i + 1)) || return 1
106 git commit -m message abcd
109 cat >expect72
<<'EOF'
110 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
111 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
113 test_expect_success
"format-patch --cover-letter ignores COLUMNS (big change)" '
114 COLUMNS=200 git format-patch -1 --stdout --cover-letter >output &&
115 grep " | " output >actual &&
116 test_cmp expect72 actual
119 cat >expect72
<<'EOF'
120 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
122 cat >expect72-graph
<<'EOF'
123 | abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
125 cat >expect200
<<'EOF'
126 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
128 cat >expect200-graph
<<'EOF'
129 | abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
131 while read verb expect cmd args
133 test_expect_success
"$cmd $verb COLUMNS (big change)" '
134 COLUMNS=200 git $cmd $args >output &&
135 grep " | " output >actual &&
136 test_cmp "$expect" actual
139 case "$cmd" in diff|show
) continue;; esac
141 test_expect_success
"$cmd --graph $verb COLUMNS (big change)" '
142 COLUMNS=200 git $cmd $args --graph >output &&
143 grep " | " output >actual &&
144 test_cmp "$expect-graph" actual
147 ignores expect72 format-patch
-1 --stdout
148 respects expect200
diff HEAD^ HEAD
--stat
149 respects expect200 show
--stat
150 respects expect200 log
-1 --stat
153 cat >expect40
<<'EOF'
154 abcd | 1000 ++++++++++++++++++++++++++
156 cat >expect40-graph
<<'EOF'
157 | abcd | 1000 ++++++++++++++++++++++++
159 while read verb expect cmd args
161 test_expect_success
"$cmd $verb not enough COLUMNS (big change)" '
162 COLUMNS=40 git $cmd $args >output &&
163 grep " | " output >actual &&
164 test_cmp "$expect" actual
167 case "$cmd" in diff|show
) continue;; esac
169 test_expect_success
"$cmd --graph $verb not enough COLUMNS (big change)" '
170 COLUMNS=40 git $cmd $args --graph >output &&
171 grep " | " output >actual &&
172 test_cmp "$expect-graph" actual
175 ignores expect72 format-patch
-1 --stdout
176 respects expect40
diff HEAD^ HEAD
--stat
177 respects expect40 show
--stat
178 respects expect40 log
-1 --stat
181 cat >expect40
<<'EOF'
182 abcd | 1000 ++++++++++++++++++++++++++
184 cat >expect40-graph
<<'EOF'
185 | abcd | 1000 ++++++++++++++++++++++++++
187 while read verb expect cmd args
189 test_expect_success
"$cmd $verb statGraphWidth config" '
190 git -c diff.statGraphWidth=26 $cmd $args >output &&
191 grep " | " output >actual &&
192 test_cmp "$expect" actual
195 case "$cmd" in diff|show
) continue;; esac
197 test_expect_success
"$cmd --graph $verb statGraphWidth config" '
198 git -c diff.statGraphWidth=26 $cmd $args --graph >output &&
199 grep " | " output >actual &&
200 test_cmp "$expect-graph" actual
203 ignores expect72 format-patch
-1 --stdout
204 respects expect40
diff HEAD^ HEAD
--stat
205 respects expect40 show
--stat
206 respects expect40 log
-1 --stat
211 abcd | 1000 ++++++++++++++++++++++++++
213 cat >expect-graph
<<'EOF'
214 | abcd | 1000 ++++++++++++++++++++++++++
218 test_expect_success
"$cmd --stat=width with big change" '
219 git $cmd $args --stat=40 >output &&
220 grep " | " output >actual &&
221 test_cmp expect actual
224 test_expect_success
"$cmd --stat-width=width with big change" '
225 git $cmd $args --stat-width=40 >output &&
226 grep " | " output >actual &&
227 test_cmp expect actual
230 test_expect_success
"$cmd --stat-graph-width with big change" '
231 git $cmd $args --stat-graph-width=26 >output &&
232 grep " | " output >actual &&
233 test_cmp expect actual
236 case "$cmd" in diff|show
) continue;; esac
238 test_expect_success
"$cmd --stat-width=width --graph with big change" '
239 git $cmd $args --stat-width=40 --graph >output &&
240 grep " | " output >actual &&
241 test_cmp expect-graph actual
244 test_expect_success
"$cmd --stat-graph-width --graph with big change" '
245 git $cmd $args --stat-graph-width=26 --graph >output &&
246 grep " | " output >actual &&
247 test_cmp expect-graph actual
250 format-patch
-1 --stdout
251 diff HEAD^ HEAD
--stat
256 test_expect_success
'preparation for long filename tests' '
257 cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
258 git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
259 git commit -m message
263 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
265 cat >expect-graph
<<'EOF'
266 | ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
270 test_expect_success
"$cmd --stat=width with big change is more balanced" '
271 git $cmd $args --stat-width=60 >output &&
272 grep " | " output >actual &&
273 test_cmp expect actual
276 case "$cmd" in diff|show
) continue;; esac
278 test_expect_success
"$cmd --stat=width --graph with big change is balanced" '
279 git $cmd $args --stat-width=60 --graph >output &&
280 grep " | " output >actual &&
281 test_cmp expect-graph actual
284 format-patch
-1 --stdout
285 diff HEAD^ HEAD
--stat
290 cat >expect72
<<'EOF'
291 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
293 cat >expect72-graph
<<'EOF'
294 | ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
296 cat >expect200
<<'EOF'
297 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
299 cat >expect200-graph
<<'EOF'
300 | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
302 while read verb expect cmd args
304 test_expect_success
"$cmd $verb COLUMNS (long filename)" '
305 COLUMNS=200 git $cmd $args >output &&
306 grep " | " output >actual &&
307 test_cmp "$expect" actual
310 case "$cmd" in diff|show
) continue;; esac
312 test_expect_success
"$cmd --graph $verb COLUMNS (long filename)" '
313 COLUMNS=200 git $cmd $args --graph >output &&
314 grep " | " output >actual &&
315 test_cmp "$expect-graph" actual
318 ignores expect72 format-patch
-1 --stdout
319 respects expect200
diff HEAD^ HEAD
--stat
320 respects expect200 show
--stat
321 respects expect200 log
-1 --stat
325 ...aaaaaaa | 1000 ++++++
327 cat >expect1-graph
<<'EOF'
328 | ...aaaaaaa | 1000 ++++++
330 while read verb expect cmd args
332 test_expect_success COLUMNS_CAN_BE_1 \
333 "$cmd $verb prefix greater than COLUMNS (big change)" '
334 COLUMNS=1 git $cmd $args >output &&
335 grep " | " output >actual &&
336 test_cmp "$expect" actual
339 case "$cmd" in diff|show
) continue;; esac
341 test_expect_success COLUMNS_CAN_BE_1 \
342 "$cmd --graph $verb prefix greater than COLUMNS (big change)" '
343 COLUMNS=1 git $cmd $args --graph >output &&
344 grep " | " output >actual &&
345 test_cmp "$expect-graph" actual
348 ignores expect72 format-patch
-1 --stdout
349 respects expect1
diff HEAD^ HEAD
--stat
350 respects expect1 show
--stat
351 respects expect1 log
-1 --stat
355 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
357 test_expect_success
'merge --stat respects COLUMNS (big change)' '
358 git checkout -b branch HEAD^^ &&
359 COLUMNS=100 git merge --stat --no-ff main^ >output &&
360 grep " | " output >actual &&
361 test_cmp expect actual
365 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++
367 test_expect_success
'merge --stat respects COLUMNS (long filename)' '
368 COLUMNS=100 git merge --stat --no-ff main >output &&
369 grep " | " output >actual &&
370 test_cmp expect actual