t8*: adjust the references to the default branch name "main"
[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-lib.sh
12 . "$TEST_DIRECTORY"/lib-terminal.sh
13
14 # 120 character name
15 name=aaaaaaaaaa
16 name=$name$name$name$name$name$name$name$name$name$name$name$name
17 test_expect_success 'preparation' '
18         >"$name" &&
19         git add "$name" &&
20         git commit -m message &&
21         echo a >"$name" &&
22         git commit -m message "$name"
23 '
24
25 cat >expect72 <<-'EOF'
26  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
27 EOF
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
32 '
33
34 while read cmd args
35 do
36         cat >expect80 <<-'EOF'
37          ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
38         EOF
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
43         '
44 done <<\EOF
45 diff HEAD^ HEAD --stat
46 show --stat
47 log -1 --stat
48 EOF
49
50 cat >expect.60 <<-'EOF'
51  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
52 EOF
53 cat >expect.6030 <<-'EOF'
54  ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
55 EOF
56 cat >expect2.60 <<-'EOF'
57  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
58  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
59 EOF
60 cat >expect2.6030 <<-'EOF'
61  ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
62  ...aaaaaaaaaaaaaaaaaaaaaaaaaaa | 1 +
63 EOF
64 while read expect cmd args
65 do
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
70         '
71
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
76         '
77
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
82         '
83
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
88         '
89 done <<\EOF
90 expect2 format-patch --cover-letter -1 --stdout
91 expect diff HEAD^ HEAD --stat
92 expect show --stat
93 expect log -1 --stat
94 EOF
95
96
97 test_expect_success 'preparation for big change tests' '
98         >abcd &&
99         git add abcd &&
100         git commit -m message &&
101         i=0 &&
102         while test $i -lt 1000
103         do
104                 echo $i && i=$(($i + 1))
105         done >abcd &&
106         git commit -m message abcd
107 '
108
109 cat >expect72 <<'EOF'
110  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
111  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
112 EOF
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
117 '
118
119 cat >expect72 <<'EOF'
120  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
121 EOF
122 cat >expect72-graph <<'EOF'
123 |  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
124 EOF
125 cat >expect200 <<'EOF'
126  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
127 EOF
128 cat >expect200-graph <<'EOF'
129 |  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
130 EOF
131 while read verb expect cmd args
132 do
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
137         '
138
139         case "$cmd" in diff|show) continue;; esac
140
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
145         '
146 done <<\EOF
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
151 EOF
152
153 cat >expect40 <<'EOF'
154  abcd | 1000 ++++++++++++++++++++++++++
155 EOF
156 cat >expect40-graph <<'EOF'
157 |  abcd | 1000 ++++++++++++++++++++++++
158 EOF
159 while read verb expect cmd args
160 do
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
165         '
166
167         case "$cmd" in diff|show) continue;; esac
168
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
173         '
174 done <<\EOF
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
179 EOF
180
181 cat >expect40 <<'EOF'
182  abcd | 1000 ++++++++++++++++++++++++++
183 EOF
184 cat >expect40-graph <<'EOF'
185 |  abcd | 1000 ++++++++++++++++++++++++++
186 EOF
187 while read verb expect cmd args
188 do
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
193         '
194
195         case "$cmd" in diff|show) continue;; esac
196
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
201         '
202 done <<\EOF
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
207 EOF
208
209
210 cat >expect <<'EOF'
211  abcd | 1000 ++++++++++++++++++++++++++
212 EOF
213 cat >expect-graph <<'EOF'
214 |  abcd | 1000 ++++++++++++++++++++++++++
215 EOF
216 while read cmd args
217 do
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
222         '
223
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
228         '
229
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
234         '
235
236         case "$cmd" in diff|show) continue;; esac
237
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
242         '
243
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
248         '
249 done <<\EOF
250 format-patch -1 --stdout
251 diff HEAD^ HEAD --stat
252 show --stat
253 log -1 --stat
254 EOF
255
256 test_expect_success 'preparation for long filename tests' '
257         cp abcd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
258         git add aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
259         git commit -m message
260 '
261
262 cat >expect <<'EOF'
263  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
264 EOF
265 cat >expect-graph <<'EOF'
266 |  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 ++++++++++++
267 EOF
268 while read cmd args
269 do
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
274         '
275
276         case "$cmd" in diff|show) continue;; esac
277
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
282         '
283 done <<\EOF
284 format-patch -1 --stdout
285 diff HEAD^ HEAD --stat
286 show --stat
287 log -1 --stat
288 EOF
289
290 cat >expect72 <<'EOF'
291  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
292 EOF
293 cat >expect72-graph <<'EOF'
294 |  ...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++
295 EOF
296 cat >expect200 <<'EOF'
297  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
298 EOF
299 cat >expect200-graph <<'EOF'
300 |  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
301 EOF
302 while read verb expect cmd args
303 do
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
308         '
309
310         case "$cmd" in diff|show) continue;; esac
311
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
316         '
317 done <<\EOF
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
322 EOF
323
324 cat >expect1 <<'EOF'
325  ...aaaaaaa | 1000 ++++++
326 EOF
327 cat >expect1-graph <<'EOF'
328 |  ...aaaaaaa | 1000 ++++++
329 EOF
330 while read verb expect cmd args
331 do
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
337         '
338
339         case "$cmd" in diff|show) continue;; esac
340
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
346         '
347 done <<\EOF
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
352 EOF
353
354 cat >expect <<'EOF'
355  abcd | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
356 EOF
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
362 '
363
364 cat >expect <<'EOF'
365  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 1000 +++++++++++++++++++++++++++++++++++++++
366 EOF
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
371 '
372
373 test_done