]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7401-submodule-summary.sh
t: use test_expect_code instead of hand-rolled comparison
[thirdparty/git.git] / t / t7401-submodule-summary.sh
CommitLineData
2da2ddc6
PY
1#!/bin/sh
2#
3# Copyright (c) 2008 Ping Yin
4#
5
6test_description='Summary support for submodules
7
47a528ad 8This test tries to verify the sanity of summary subcommand of git submodule.
2da2ddc6
PY
9'
10
11. ./test-lib.sh
12
13add_file () {
14 sm=$1
15 shift
16 owd=$(pwd)
17 cd "$sm"
18 for name; do
19 echo "$name" > "$name" &&
20 git add "$name" &&
21 test_tick &&
22 git commit -m "Add $name"
23 done >/dev/null
24 git rev-parse --verify HEAD | cut -c1-7
25 cd "$owd"
26}
27commit_file () {
28 test_tick &&
29 git commit "$@" -m "Commit $*" >/dev/null
30}
31
32test_create_repo sm1 &&
02604e29 33add_file . foo >/dev/null
2da2ddc6
PY
34
35head1=$(add_file sm1 foo1 foo2)
36
37test_expect_success 'added submodule' "
38 git add sm1 &&
39 git submodule summary >actual &&
f8d186bb 40 cat >expected <<-EOF &&
2da2ddc6 41* sm1 0000000...$head1 (2):
091a6eb0
JK
42 > Add foo2
43
44EOF
45 test_cmp expected actual
46"
47
48test_expect_success 'added submodule (subdirectory)' "
49 mkdir sub &&
50 (
51 cd sub &&
52 git submodule summary >../actual
53 ) &&
54 cat >expected <<-EOF &&
55* ../sm1 0000000...$head1 (2):
56 > Add foo2
57
58EOF
59 test_cmp expected actual
60"
61
62test_expect_success 'added submodule (subdirectory only)' "
63 (
64 cd sub &&
65 git submodule summary . >../actual
66 ) &&
67 >expected &&
68 test_cmp expected actual
69"
70
71test_expect_success 'added submodule (subdirectory with explicit path)' "
72 (
73 cd sub &&
74 git submodule summary ../sm1 >../actual
75 ) &&
76 cat >expected <<-EOF &&
77* ../sm1 0000000...$head1 (2):
2da2ddc6
PY
78 > Add foo2
79
80EOF
f8d186bb 81 test_cmp expected actual
2da2ddc6
PY
82"
83
84commit_file sm1 &&
85head2=$(add_file sm1 foo3)
86
87test_expect_success 'modified submodule(forward)' "
88 git submodule summary >actual &&
f8d186bb 89 cat >expected <<-EOF &&
2da2ddc6
PY
90* sm1 $head1...$head2 (1):
91 > Add foo3
92
93EOF
f8d186bb 94 test_cmp expected actual
2da2ddc6
PY
95"
96
1c244f6e
JL
97test_expect_success 'modified submodule(forward), --files' "
98 git submodule summary --files >actual &&
f8d186bb 99 cat >expected <<-EOF &&
1c244f6e
JL
100* sm1 $head1...$head2 (1):
101 > Add foo3
102
103EOF
f8d186bb 104 test_cmp expected actual
1c244f6e
JL
105"
106
927b26f8 107test_expect_success 'no ignore=all setting has any effect' "
108 git config -f .gitmodules submodule.sm1.path sm1 &&
109 git config -f .gitmodules submodule.sm1.ignore all &&
110 git config submodule.sm1.ignore all &&
111 git config diff.ignoreSubmodules all &&
112 git submodule summary >actual &&
113 cat >expected <<-EOF &&
114* sm1 $head1...$head2 (1):
115 > Add foo3
116
117EOF
118 test_cmp expected actual &&
119 git config --unset diff.ignoreSubmodules &&
120 git config --remove-section submodule.sm1 &&
121 git config -f .gitmodules --remove-section submodule.sm1
122"
123
124
2da2ddc6 125commit_file sm1 &&
18a82692
JN
126head3=$(
127 cd sm1 &&
128 git reset --hard HEAD~2 >/dev/null &&
129 git rev-parse --verify HEAD | cut -c1-7
fd4ec4f2 130)
2da2ddc6
PY
131
132test_expect_success 'modified submodule(backward)' "
8120e421
JK
133 git submodule summary >actual &&
134 cat >expected <<-EOF &&
2da2ddc6
PY
135* sm1 $head2...$head3 (2):
136 < Add foo3
137 < Add foo2
138
139EOF
f8d186bb 140 test_cmp expected actual
2da2ddc6
PY
141"
142
143head4=$(add_file sm1 foo4 foo5) &&
144head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
145test_expect_success 'modified submodule(backward and forward)' "
8120e421
JK
146 git submodule summary >actual &&
147 cat >expected <<-EOF &&
2da2ddc6
PY
148* sm1 $head2...$head4 (4):
149 > Add foo5
150 > Add foo4
151 < Add foo3
152 < Add foo2
153
154EOF
f8d186bb 155 test_cmp expected actual
2da2ddc6
PY
156"
157
158test_expect_success '--summary-limit' "
8120e421
JK
159 git submodule summary -n 3 >actual &&
160 cat >expected <<-EOF &&
2da2ddc6
PY
161* sm1 $head2...$head4 (4):
162 > Add foo5
163 > Add foo4
164 < Add foo3
165
166EOF
8120e421 167 test_cmp expected actual
2da2ddc6
PY
168"
169
170commit_file sm1 &&
171mv sm1 sm1-bak &&
172echo sm1 >sm1 &&
173head5=$(git hash-object sm1 | cut -c1-7) &&
174git add sm1 &&
175rm -f sm1 &&
176mv sm1-bak sm1
177
178test_expect_success 'typechanged submodule(submodule->blob), --cached' "
8120e421
JK
179 git submodule summary --cached >actual &&
180 cat >expected <<-EOF &&
2da2ddc6
PY
181* sm1 $head4(submodule)->$head5(blob) (3):
182 < Add foo5
183
184EOF
b3e73449 185 test_i18ncmp actual expected
2da2ddc6
PY
186"
187
1c244f6e 188test_expect_success 'typechanged submodule(submodule->blob), --files' "
8120e421
JK
189 git submodule summary --files >actual &&
190 cat >expected <<-EOF &&
1c244f6e
JL
191* sm1 $head5(blob)->$head4(submodule) (3):
192 > Add foo5
193
194EOF
8120e421 195 test_i18ncmp actual expected
1c244f6e
JL
196"
197
2da2ddc6
PY
198rm -rf sm1 &&
199git checkout-index sm1
200test_expect_success 'typechanged submodule(submodule->blob)' "
8120e421
JK
201 git submodule summary >actual &&
202 cat >expected <<-EOF &&
2da2ddc6
PY
203* sm1 $head4(submodule)->$head5(blob):
204
205EOF
8120e421 206 test_i18ncmp actual expected
2da2ddc6
PY
207"
208
209rm -f sm1 &&
210test_create_repo sm1 &&
211head6=$(add_file sm1 foo6 foo7)
212test_expect_success 'nonexistent commit' "
8120e421
JK
213 git submodule summary >actual &&
214 cat >expected <<-EOF &&
2da2ddc6
PY
215* sm1 $head4...$head6:
216 Warn: sm1 doesn't contain commit $head4_full
217
218EOF
8120e421 219 test_i18ncmp actual expected
2da2ddc6
PY
220"
221
222commit_file
223test_expect_success 'typechanged submodule(blob->submodule)' "
8120e421
JK
224 git submodule summary >actual &&
225 cat >expected <<-EOF &&
2da2ddc6
PY
226* sm1 $head5(blob)->$head6(submodule) (2):
227 > Add foo7
228
229EOF
8120e421 230 test_i18ncmp expected actual
2da2ddc6
PY
231"
232
233commit_file sm1 &&
234rm -rf sm1
235test_expect_success 'deleted submodule' "
8120e421
JK
236 git submodule summary >actual &&
237 cat >expected <<-EOF &&
2da2ddc6
PY
238* sm1 $head6...0000000:
239
240EOF
8120e421 241 test_cmp expected actual
2da2ddc6
PY
242"
243
244test_create_repo sm2 &&
245head7=$(add_file sm2 foo8 foo9) &&
246git add sm2
247
248test_expect_success 'multiple submodules' "
8120e421
JK
249 git submodule summary >actual &&
250 cat >expected <<-EOF &&
2da2ddc6
PY
251* sm1 $head6...0000000:
252
253* sm2 0000000...$head7 (2):
254 > Add foo9
255
256EOF
8120e421 257 test_cmp expected actual
2da2ddc6
PY
258"
259
260test_expect_success 'path filter' "
8120e421
JK
261 git submodule summary sm2 >actual &&
262 cat >expected <<-EOF &&
2da2ddc6
PY
263* sm2 0000000...$head7 (2):
264 > Add foo9
265
266EOF
8120e421 267 test_cmp expected actual
2da2ddc6
PY
268"
269
270commit_file sm2
271test_expect_success 'given commit' "
8120e421
JK
272 git submodule summary HEAD^ >actual &&
273 cat >expected <<-EOF &&
2da2ddc6
PY
274* sm1 $head6...0000000:
275
276* sm2 0000000...$head7 (2):
277 > Add foo9
278
279EOF
8120e421 280 test_cmp expected actual
2da2ddc6
PY
281"
282
d0f64dd4 283test_expect_success '--for-status' "
8120e421
JK
284 git submodule summary --for-status HEAD^ >actual &&
285 test_i18ncmp actual - <<EOF
3ba7407b
MM
286* sm1 $head6...0000000:
287
288* sm2 0000000...$head7 (2):
289 > Add foo9
290
d0f64dd4
PY
291EOF
292"
293
1c244f6e 294test_expect_success 'fail when using --files together with --cached' "
8120e421 295 test_must_fail git submodule summary --files --cached
1c244f6e
JL
296"
297
3deea89c 298test_expect_success 'should not fail in an empty repo' "
8120e421
JK
299 git init xyzzy &&
300 cd xyzzy &&
301 git submodule summary >output 2>&1 &&
302 test_cmp output /dev/null
3deea89c
JH
303"
304
2da2ddc6 305test_done