@@ -28,9 +28,6 @@ test_expect_success 'setup - repository in init subdirectory' '
28
28
git commit -m "submodule commit 1" &&
29
29
git tag -a -m "rev-1" rev-1
30
30
)
31
- rev1=$(cd init && git rev-parse HEAD) &&
32
- printf "rev1: %s\n" "$rev1" &&
33
- test -n "$rev1"
34
31
'
35
32
36
33
test_expect_success ' setup - commit with gitlink' '
@@ -44,11 +41,6 @@ test_expect_success 'setup - hide init subdirectory' '
44
41
mv init .subrepo
45
42
'
46
43
47
- test_expect_success ' setup - add an example entry to .gitmodules' '
48
- GIT_CONFIG=.gitmodules \
49
- git config submodule.example.url git://example.com/init.git
50
- '
51
-
52
44
test_expect_success ' setup - repository to add submodules to' '
53
45
git init addtest
54
46
'
@@ -69,6 +61,7 @@ inspect() {
69
61
cd " $dir " &&
70
62
listbranches > " $dotdot /heads" &&
71
63
{ git symbolic-ref HEAD || : ; } > " $dotdot /head" &&
64
+ git rev-parse HEAD > " $dotdot /head-sha1" &&
72
65
git update-index --refresh &&
73
66
git diff-files --exit-code &&
74
67
git clean -n -d -x > " $dotdot /untracked"
@@ -181,131 +174,129 @@ test_expect_success 'submodule add with ./, /.. and // in path' '
181
174
test_cmp empty untracked
182
175
'
183
176
177
+ test_expect_success ' setup - add an example entry to .gitmodules' '
178
+ GIT_CONFIG=.gitmodules \
179
+ git config submodule.example.url git://example.com/init.git
180
+ '
181
+
184
182
test_expect_success ' status should fail for unmapped paths' '
185
- if git submodule status
186
- then
187
- echo "[OOPS] submodule status succeeded"
188
- false
189
- elif ! GIT_CONFIG=.gitmodules git config submodule.example.path init
190
- then
191
- echo "[OOPS] git config failed to update .gitmodules"
192
- false
193
- fi
183
+ test_must_fail git submodule status
184
+ '
185
+
186
+ test_expect_success ' setup - map path in .gitmodules' '
187
+ cat <<\EOF >expect &&
188
+ [submodule "example"]
189
+ url = git://example.com/init.git
190
+ path = init
191
+ EOF
192
+
193
+ GIT_CONFIG=.gitmodules git config submodule.example.path init &&
194
+
195
+ test_cmp expect .gitmodules
194
196
'
195
197
196
198
test_expect_success ' status should only print one line' '
197
- lines=$(git submodule status | wc -l) &&
198
- test $lines = 1
199
+ git submodule status >lines &&
200
+ test $(wc -l <lines) = 1
201
+ '
202
+
203
+ test_expect_success ' setup - fetch commit name from submodule' '
204
+ rev1=$(cd .subrepo && git rev-parse HEAD) &&
205
+ printf "rev1: %s\n" "$rev1" &&
206
+ test -n "$rev1"
199
207
'
200
208
201
209
test_expect_success ' status should initially be "missing"' '
202
- git submodule status | grep "^-$rev1"
210
+ git submodule status >lines &&
211
+ grep "^-$rev1" lines
203
212
'
204
213
205
214
test_expect_success ' init should register submodule url in .git/config' '
215
+ echo git://example.com/init.git >expect &&
216
+
206
217
git submodule init &&
207
- url=$(git config submodule.example.url) &&
208
- if test "$url" != "git://example.com/init.git"
209
- then
210
- echo "[OOPS] init succeeded but submodule url is wrong"
211
- false
212
- elif test_must_fail git config submodule.example.url ./.subrepo
213
- then
214
- echo "[OOPS] init succeeded but update of url failed"
215
- false
216
- fi
218
+ git config submodule.example.url >url &&
219
+ git config submodule.example.url ./.subrepo &&
220
+
221
+ test_cmp expect url
217
222
'
218
223
219
224
test_expect_success ' update should fail when path is used by a file' '
225
+ echo hello >expect &&
226
+
220
227
echo "hello" >init &&
221
- if git submodule update
222
- then
223
- echo "[OOPS] update should have failed"
224
- false
225
- elif test "$(cat init)" != "hello"
226
- then
227
- echo "[OOPS] update failed but init file was molested"
228
- false
229
- else
230
- rm init
231
- fi
228
+ test_must_fail git submodule update &&
229
+
230
+ test_cmp expect init
232
231
'
233
232
234
233
test_expect_success ' update should fail when path is used by a nonempty directory' '
234
+ echo hello >expect &&
235
+
236
+ rm -fr init &&
235
237
mkdir init &&
236
238
echo "hello" >init/a &&
237
- if git submodule update
238
- then
239
- echo "[OOPS] update should have failed"
240
- false
241
- elif test "$(cat init/a)" != "hello"
242
- then
243
- echo "[OOPS] update failed but init/a was molested"
244
- false
245
- else
246
- rm init/a
247
- fi
239
+
240
+ test_must_fail git submodule update &&
241
+
242
+ test_cmp expect init/a
248
243
'
249
244
250
245
test_expect_success ' update should work when path is an empty dir' '
251
- rm -rf init &&
246
+ rm -fr init &&
247
+ rm -f head-sha1 &&
248
+ echo "$rev1" >expect &&
249
+
252
250
mkdir init &&
253
251
git submodule update &&
254
- head=$(cd init && git rev-parse HEAD) &&
255
- if test -z "$head"
256
- then
257
- echo "[OOPS] Failed to obtain submodule head"
258
- false
259
- elif test "$head" != "$rev1"
260
- then
261
- echo "[OOPS] Submodule head is $head but should have been $rev1"
262
- false
263
- fi
252
+
253
+ inspect init &&
254
+ test_cmp expect head-sha1
264
255
'
265
256
266
257
test_expect_success ' status should be "up-to-date" after update' '
267
- git submodule status | grep "^ $rev1"
258
+ git submodule status >list &&
259
+ grep "^ $rev1" list
268
260
'
269
261
270
262
test_expect_success ' status should be "modified" after submodule commit' '
271
- cd init &&
272
- echo b >b &&
273
- git add b &&
274
- git commit -m "submodule commit 2" &&
275
- rev2=$( git rev-parse HEAD) &&
276
- cd .. &&
277
- if test -z "$rev2"
278
- then
279
- echo "[OOPS] submodule git rev-parse returned nothing"
280
- false
281
- fi &&
282
- git submodule status | grep "^+$rev2"
263
+ (
264
+ cd init &&
265
+ echo b > b &&
266
+ git add b &&
267
+ git commit -m "submodule commit 2"
268
+ ) &&
269
+
270
+ rev2=$(cd init && git rev-parse HEAD) &&
271
+ test -n "$rev2" &&
272
+ git submodule status >list &&
273
+
274
+ grep "^+$rev2" list
283
275
'
284
276
285
277
test_expect_success ' the --cached sha1 should be rev1' '
286
- git submodule --cached status | grep "^+$rev1"
278
+ git submodule --cached status >list &&
279
+ grep "^+$rev1" list
287
280
'
288
281
289
282
test_expect_success ' git diff should report the SHA1 of the new submodule commit' '
290
- git diff | grep "^+Subproject commit $rev2"
283
+ git diff >diff &&
284
+ grep "^+Subproject commit $rev2" diff
291
285
'
292
286
293
287
test_expect_success ' update should checkout rev1' '
288
+ rm -f head-sha1 &&
289
+ echo "$rev1" >expect &&
290
+
294
291
git submodule update init &&
295
- head=$(cd init && git rev-parse HEAD) &&
296
- if test -z "$head"
297
- then
298
- echo "[OOPS] submodule git rev-parse returned nothing"
299
- false
300
- elif test "$head" != "$rev1"
301
- then
302
- echo "[OOPS] init did not checkout correct head"
303
- false
304
- fi
292
+ inspect init &&
293
+
294
+ test_cmp expect head-sha1
305
295
'
306
296
307
297
test_expect_success ' status should be "up-to-date" after update' '
308
- git submodule status | grep "^ $rev1"
298
+ git submodule status >list &&
299
+ grep "^ $rev1" list
309
300
'
310
301
311
302
test_expect_success ' checkout superproject with subproject already present' '
@@ -314,6 +305,8 @@ test_expect_success 'checkout superproject with subproject already present' '
314
305
'
315
306
316
307
test_expect_success ' apply submodule diff' '
308
+ >empty &&
309
+
317
310
git branch second &&
318
311
(
319
312
cd init &&
@@ -326,21 +319,24 @@ test_expect_success 'apply submodule diff' '
326
319
git format-patch -1 --stdout >P.diff &&
327
320
git checkout second &&
328
321
git apply --index P.diff &&
329
- D=$(git diff --cached master) &&
330
- test -z "$D"
322
+
323
+ git diff --cached master >staged &&
324
+ test_cmp empty staged
331
325
'
332
326
333
327
test_expect_success ' update --init' '
334
-
335
328
mv init init2 &&
336
329
git config -f .gitmodules submodule.example.url "$(pwd)/init2" &&
337
- git config --remove-section submodule.example
330
+ git config --remove-section submodule.example &&
331
+ test_must_fail git config submodule.example.url &&
332
+
338
333
git submodule update init > update.out &&
334
+ cat update.out &&
339
335
grep "not initialized" update.out &&
340
- test ! -d init/.git &&
336
+ ! test -d init/.git &&
337
+
341
338
git submodule update --init init &&
342
339
test -d init/.git
343
-
344
340
'
345
341
346
342
test_expect_success ' do not add files from a submodule' '
0 commit comments