OSDN Git Service

lib-submodule-update.sh: do not use ./. as submodule remote
authorStefan Beller <sbeller@google.com>
Tue, 14 Mar 2017 21:46:27 +0000 (14:46 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Mar 2017 01:15:53 +0000 (18:15 -0700)
Adding the repository itself as a submodule does not make sense in the
real world. In our test suite we used to do that out of convenience in
some tests as the current repository has easiest access for setting up
'just a submodule'.

However this doesn't quite test the real world, so let's do not follow
this pattern any further and actually create an independent repository
that we can use as a submodule.

When using './.' as the remote the superproject and submodule share the
same objects, such that testing if a given sha1 is a valid commit works
in either repository.  As running commands in an unpopulated submodule
fall back to the superproject, this happens in `reset_work_tree_to`
to determine if we need to populate the submodule. Fix this bug by
checking in the actual remote now.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/lib-submodule-update.sh

index 5df528e..c0d6325 100755 (executable)
 #
 
 create_lib_submodule_repo () {
+       git init submodule_update_sub1 &&
+       (
+               cd submodule_update_sub1 &&
+               echo "expect" >>.gitignore &&
+               echo "actual" >>.gitignore &&
+               echo "x" >file1 &&
+               echo "y" >file2 &&
+               git add .gitignore file1 file2 &&
+               git commit -m "Base inside first submodule" &&
+               git branch "no_submodule"
+       ) &&
        git init submodule_update_repo &&
        (
                cd submodule_update_repo &&
@@ -49,7 +60,7 @@ create_lib_submodule_repo () {
                git branch "no_submodule" &&
 
                git checkout -b "add_sub1" &&
-               git submodule add ./. sub1 &&
+               git submodule add ../submodule_update_sub1 sub1 &&
                git config -f .gitmodules submodule.sub1.ignore all &&
                git config submodule.sub1.ignore all &&
                git add .gitmodules &&
@@ -162,7 +173,7 @@ reset_work_tree_to () {
                test_must_be_empty actual &&
                sha1=$(git rev-parse --revs-only HEAD:sub1) &&
                if test -n "$sha1" &&
-                  test $(cd "sub1" && git rev-parse --verify "$sha1^{commit}")
+                  test $(cd "../submodule_update_sub1" && git rev-parse --verify "$sha1^{commit}")
                then
                        git submodule update --init --recursive "sub1"
                fi