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