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 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
54 cat >expect
.6030 <<-'EOF'
55 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
57 cat >expect2.60
<<-'EOF'
58 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
59 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
61 cat >expect2.6030
<<-'EOF'
62 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
63 ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
65 while read expect cmd args
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
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
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
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
91 expect2 format-patch
--cover-letter -1 --stdout
92 expect
diff HEAD^ HEAD
--stat
98 test_expect_success
'preparation for big change tests' '
101 git commit -m message &&
103 while test $i -lt 1000
105 echo $i && i=$(($i + 1)) || return 1
107 git commit -m message abcd
110 cat >expect72
<<'EOF'
111 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
112 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
120 cat >expect72
<<'EOF'
121 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
123 cat >expect72-graph
<<'EOF'
124 | abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
126 cat >expect200
<<'EOF'
127 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
129 cat >expect200-graph
<<'EOF'
130 | abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
132 while read verb expect cmd args
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
140 case "$cmd" in diff|show
) continue;; esac
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
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
154 cat >expect40
<<'EOF'
155 abcd | 1000 ++++++++++++++++++++++++++
157 cat >expect40-graph
<<'EOF'
158 | abcd | 1000 ++++++++++++++++++++++++
160 while read verb expect cmd args
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
168 case "$cmd" in diff|show
) continue;; esac
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
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
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 statGraphWidth config" '
191 git -c diff.statGraphWidth=26 $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 statGraphWidth config" '
199 git -c diff.statGraphWidth=26 $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
212 abcd | 1000 ++++++++++++++++++++++++++
214 cat >expect-graph
<<'EOF'
215 | abcd | 1000 ++++++++++++++++++++++++++
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
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
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
237 case "$cmd" in diff|show
) continue;; esac
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
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
251 format-patch
-1 --stdout
252 diff HEAD^ HEAD
--stat
257 test_expect_success
'preparation for long filename tests' '
258 cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
259 git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
260 git commit -m message
264 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
266 cat >expect-graph
<<'EOF'
267 | ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
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
277 case "$cmd" in diff|show
) continue;; esac
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
285 format-patch
-1 --stdout
286 diff HEAD^ HEAD
--stat
291 cat >expect72
<<'EOF'
292 ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
294 cat >expect72-graph
<<'EOF'
295 | ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
297 cat >expect200
<<'EOF'
298 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
300 cat >expect200-graph
<<'EOF'
301 | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
303 while read verb expect cmd args
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
311 case "$cmd" in diff|show
) continue;; esac
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
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
326 ...aaaaaaa | 1000 ++++++
328 cat >expect1-graph
<<'EOF'
329 | ...aaaaaaa | 1000 ++++++
331 while read verb expect cmd args
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
340 case "$cmd" in diff|show
) continue;; esac
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
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
356 abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
366 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++
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