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