Skip to content

Commit ce8b54d

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a76c944 commit ce8b54d

File tree

1 file changed

+91
-95
lines changed

1 file changed

+91
-95
lines changed

t/t7400-submodule-basic.sh

Lines changed: 91 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ test_expect_success 'setup - repository in init subdirectory' '
2828
git commit -m "submodule commit 1" &&
2929
git tag -a -m "rev-1" rev-1
3030
)
31-
rev1=$(cd init && git rev-parse HEAD) &&
32-
printf "rev1: %s\n" "$rev1" &&
33-
test -n "$rev1"
3431
'
3532

3633
test_expect_success 'setup - commit with gitlink' '
@@ -44,11 +41,6 @@ test_expect_success 'setup - hide init subdirectory' '
4441
mv init .subrepo
4542
'
4643

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-
5244
test_expect_success 'setup - repository to add submodules to' '
5345
git init addtest
5446
'
@@ -69,6 +61,7 @@ inspect() {
6961
cd "$dir" &&
7062
listbranches >"$dotdot/heads" &&
7163
{ git symbolic-ref HEAD || :; } >"$dotdot/head" &&
64+
git rev-parse HEAD >"$dotdot/head-sha1" &&
7265
git update-index --refresh &&
7366
git diff-files --exit-code &&
7467
git clean -n -d -x >"$dotdot/untracked"
@@ -181,131 +174,129 @@ test_expect_success 'submodule add with ./, /.. and // in path' '
181174
test_cmp empty untracked
182175
'
183176

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+
184182
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
194196
'
195197

196198
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"
199207
'
200208

201209
test_expect_success 'status should initially be "missing"' '
202-
git submodule status | grep "^-$rev1"
210+
git submodule status >lines &&
211+
grep "^-$rev1" lines
203212
'
204213

205214
test_expect_success 'init should register submodule url in .git/config' '
215+
echo git://example.com/init.git >expect &&
216+
206217
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
217222
'
218223

219224
test_expect_success 'update should fail when path is used by a file' '
225+
echo hello >expect &&
226+
220227
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
232231
'
233232

234233
test_expect_success 'update should fail when path is used by a nonempty directory' '
234+
echo hello >expect &&
235+
236+
rm -fr init &&
235237
mkdir init &&
236238
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
248243
'
249244

250245
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+
252250
mkdir init &&
253251
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
264255
'
265256

266257
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
268260
'
269261

270262
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
283275
'
284276

285277
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
287280
'
288281

289282
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
291285
'
292286

293287
test_expect_success 'update should checkout rev1' '
288+
rm -f head-sha1 &&
289+
echo "$rev1" >expect &&
290+
294291
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
305295
'
306296

307297
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
309300
'
310301

311302
test_expect_success 'checkout superproject with subproject already present' '
@@ -314,6 +305,8 @@ test_expect_success 'checkout superproject with subproject already present' '
314305
'
315306

316307
test_expect_success 'apply submodule diff' '
308+
>empty &&
309+
317310
git branch second &&
318311
(
319312
cd init &&
@@ -326,21 +319,24 @@ test_expect_success 'apply submodule diff' '
326319
git format-patch -1 --stdout >P.diff &&
327320
git checkout second &&
328321
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
331325
'
332326

333327
test_expect_success 'update --init' '
334-
335328
mv init init2 &&
336329
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+
338333
git submodule update init > update.out &&
334+
cat update.out &&
339335
grep "not initialized" update.out &&
340-
test ! -d init/.git &&
336+
! test -d init/.git &&
337+
341338
git submodule update --init init &&
342339
test -d init/.git
343-
344340
'
345341

346342
test_expect_success 'do not add files from a submodule' '

0 commit comments

Comments
 (0)