t7400: clarify submodule update tests
In particular, add a missing && to the update --init test. The goal is to make it clearer what happened when one of these tests fails. The update --init test is currently (consistently) failing on a few unusual machines. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Apr 10, 2010 at 00:39 UTC
ce8b54d67678249128b33733ad154dbcd90e6660
1 file changed
+91
-95
t/t7400-submodule-basic.sh
+91
-95
@@ -28,9 +28,6 @@ test_expect_success 'setup - repository in init subdirectory' '
28
git commit -m "submodule commit 1" &&
29
git tag -a -m "rev-1" rev-1
30
)
31
- rev1=$(cd init && git rev-parse HEAD) &&
32
- printf "rev1: %s\n" "$rev1" &&
33
- test -n "$rev1"
31
'
32
33
test_expect_success 'setup - commit with gitlink' '
@@ -44,11 +41,6 @@ test_expect_success 'setup - hide init subdirectory' '
41
mv init .subrepo
42
'
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
-
44
test_expect_success 'setup - repository to add submodules to' '
45
git init addtest
46
'
@@ -69,6 +61,7 @@ inspect() {
61
cd "$dir" &&
62
listbranches >"$dotdot/heads" &&
63
{ git symbolic-ref HEAD || :; } >"$dotdot/head" &&
64
+ git rev-parse HEAD >"$dotdot/head-sha1" &&
65
git update-index --refresh &&
66
git diff-files --exit-code &&
67
git clean -n -d -x >"$dotdot/untracked"
@@ -181,131 +174,129 @@ test_expect_success 'submodule add with ./, /.. and // in path' '
174
test_cmp empty untracked
175
'
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
+
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
196
'
197
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"
207
'
208
209
test_expect_success 'status should initially be "missing"' '
202
- git submodule status | grep "^-$rev1"
210
+ git submodule status >lines &&
211
+ grep "^-$rev1" lines
212
'
213
214
test_expect_success 'init should register submodule url in .git/config' '
215
+ echo git://example.com/init.git >expect &&
216
+
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
222
'
223
224
test_expect_success 'update should fail when path is used by a file' '
225
+ echo hello >expect &&
226
+
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
231
'
232
233
test_expect_success 'update should fail when path is used by a nonempty directory' '
234
+ echo hello >expect &&
235
+
236
+ rm -fr init &&
237
mkdir init &&
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
243
'
244
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
+
250
mkdir init &&
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
255
'
256
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
260
'
261
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
275
'
276
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
280
'
281
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
285
'
286
287
test_expect_success 'update should checkout rev1' '
288
+ rm -f head-sha1 &&
289
+ echo "$rev1" >expect &&
290
+
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
295
'
296
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
300
'
301
302
test_expect_success 'checkout superproject with subproject already present' '
@@ -314,6 +305,8 @@ test_expect_success 'checkout superproject with subproject already present' '
305
'
306
307
test_expect_success 'apply submodule diff' '
308
+ >empty &&
309
+
310
git branch second &&
311
(
312
cd init &&
@@ -326,21 +319,24 @@ test_expect_success 'apply submodule diff' '
319
git format-patch -1 --stdout >P.diff &&
320
git checkout second &&
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
325
'
326
327
test_expect_success 'update --init' '
334
-
328
mv init init2 &&
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
+
333
git submodule update init > update.out &&
334
+ cat update.out &&
335
grep "not initialized" update.out &&
340
- test ! -d init/.git &&
336
+ ! test -d init/.git &&
337
+
338
git submodule update --init init &&
339
test -d init/.git
343
-
340
'
341
342
test_expect_success 'do not add files from a submodule' '