t7400: avoid path mangling issues
[gitweb.git] / t / t7400-submodule-basic.sh
index 695f7afdf31cc589e9c31d764d1e713ad64240c0..c73bec9551eb27dab25aad69c83ae7ce9f9b11a8 100755 (executable)
@@ -79,6 +79,15 @@ test_expect_success 'submodule add' '
                cd addtest &&
                git submodule add -q "$submodurl" submod >actual &&
                test ! -s actual &&
+               echo "gitdir: ../.git/modules/submod" >expect &&
+               test_cmp expect submod/.git &&
+               (
+                       cd submod &&
+                       git config core.worktree >actual &&
+                       echo "../../../submod" >expect &&
+                       test_cmp expect actual &&
+                       rm -f actual expect
+               ) &&
                git submodule init
        ) &&
 
@@ -225,7 +234,7 @@ EOF
 
 test_expect_success 'status should only print one line' '
        git submodule status >lines &&
-       test $(wc -l <lines) = 1
+       test_line_count = 1 lines
 '
 
 test_expect_success 'setup - fetch commit name from submodule' '
@@ -474,21 +483,72 @@ test_expect_success 'set up for relative path tests' '
                git add sub &&
                git config -f .gitmodules submodule.sub.path sub &&
                git config -f .gitmodules submodule.sub.url ../subrepo &&
-               cp .git/config pristine-.git-config
+               cp .git/config pristine-.git-config &&
+               cp .gitmodules pristine-.gitmodules
        )
 '
 
-test_expect_success 'relative path works with URL' '
+test_expect_success '../subrepo works with URL - ssh://hostname/repo' '
        (
                cd reltest &&
                cp pristine-.git-config .git/config &&
+               cp pristine-.gitmodules .gitmodules &&
                git config remote.origin.url ssh://hostname/repo &&
                git submodule init &&
                test "$(git config submodule.sub.url)" = ssh://hostname/subrepo
        )
 '
 
-test_expect_success 'relative path works with user@host:path' '
+test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' '
+       (
+               cd reltest &&
+               cp pristine-.git-config .git/config &&
+               cp pristine-.gitmodules .gitmodules &&
+               git config remote.origin.url ssh://hostname:22/repo &&
+               git submodule init &&
+               test "$(git config submodule.sub.url)" = ssh://hostname:22/subrepo
+       )
+'
+
+# About the choice of the path in the next test:
+# - double-slash side-steps path mangling issues on Windows
+# - it is still an absolute local path
+# - there cannot be a server with a blank in its name just in case the
+#   path is used erroneously to access a //server/share style path
+test_expect_success '../subrepo path works with local path - //somewhere else/repo' '
+       (
+               cd reltest &&
+               cp pristine-.git-config .git/config &&
+               cp pristine-.gitmodules .gitmodules &&
+               git config remote.origin.url "//somewhere else/repo" &&
+               git submodule init &&
+               test "$(git config submodule.sub.url)" = "//somewhere else/subrepo"
+       )
+'
+
+test_expect_success '../subrepo works with file URL - file:///tmp/repo' '
+       (
+               cd reltest &&
+               cp pristine-.git-config .git/config &&
+               cp pristine-.gitmodules .gitmodules &&
+               git config remote.origin.url file:///tmp/repo &&
+               git submodule init &&
+               test "$(git config submodule.sub.url)" = file:///tmp/subrepo
+       )
+'
+
+test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' '
+       (
+               cd reltest &&
+               cp pristine-.git-config .git/config &&
+               cp pristine-.gitmodules .gitmodules &&
+               git config remote.origin.url helper:://hostname/repo &&
+               git submodule init &&
+               test "$(git config submodule.sub.url)" = helper:://hostname/subrepo
+       )
+'
+
+test_expect_success '../subrepo works with scp-style URL - user@host:repo' '
        (
                cd reltest &&
                cp pristine-.git-config .git/config &&
@@ -498,4 +558,109 @@ test_expect_success 'relative path works with user@host:path' '
        )
 '
 
+test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' '
+       (
+               cd reltest &&
+               cp pristine-.git-config .git/config &&
+               cp pristine-.gitmodules .gitmodules &&
+               git config remote.origin.url user@host:path/to/repo &&
+               git submodule init &&
+               test "$(git config submodule.sub.url)" = user@host:path/to/subrepo
+       )
+'
+
+test_expect_success '../subrepo works with relative local path - foo' '
+       (
+               cd reltest &&
+               cp pristine-.git-config .git/config &&
+               cp pristine-.gitmodules .gitmodules &&
+               git config remote.origin.url foo &&
+               # actual: fails with an error
+               git submodule init &&
+               test "$(git config submodule.sub.url)" = subrepo
+       )
+'
+
+test_expect_success '../subrepo works with relative local path - foo/bar' '
+       (
+               cd reltest &&
+               cp pristine-.git-config .git/config &&
+               cp pristine-.gitmodules .gitmodules &&
+               git config remote.origin.url foo/bar &&
+               git submodule init &&
+               test "$(git config submodule.sub.url)" = foo/subrepo
+       )
+'
+
+test_expect_success '../subrepo works with relative local path - ./foo' '
+       (
+               cd reltest &&
+               cp pristine-.git-config .git/config &&
+               cp pristine-.gitmodules .gitmodules &&
+               git config remote.origin.url ./foo &&
+               git submodule init &&
+               test "$(git config submodule.sub.url)" = subrepo
+       )
+'
+
+test_expect_success '../subrepo works with relative local path - ./foo/bar' '
+       (
+               cd reltest &&
+               cp pristine-.git-config .git/config &&
+               cp pristine-.gitmodules .gitmodules &&
+               git config remote.origin.url ./foo/bar &&
+               git submodule init &&
+               test "$(git config submodule.sub.url)" = foo/subrepo
+       )
+'
+
+test_expect_success '../subrepo works with relative local path - ../foo' '
+       (
+               cd reltest &&
+               cp pristine-.git-config .git/config &&
+               cp pristine-.gitmodules .gitmodules &&
+               git config remote.origin.url ../foo &&
+               git submodule init &&
+               test "$(git config submodule.sub.url)" = ../subrepo
+       )
+'
+
+test_expect_success '../subrepo works with relative local path - ../foo/bar' '
+       (
+               cd reltest &&
+               cp pristine-.git-config .git/config &&
+               cp pristine-.gitmodules .gitmodules &&
+               git config remote.origin.url ../foo/bar &&
+               git submodule init &&
+               test "$(git config submodule.sub.url)" = ../foo/subrepo
+       )
+'
+
+test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' '
+       (
+               cd reltest &&
+               cp pristine-.git-config .git/config &&
+               cp pristine-.gitmodules .gitmodules &&
+               mkdir -p a/b/c &&
+               (cd a/b/c; git init) &&
+               git config remote.origin.url ../foo/bar.git &&
+               git submodule add ../bar/a/b/c ./a/b/c &&
+               git submodule init &&
+               test "$(git config submodule.a/b/c.url)" = ../foo/bar/a/b/c
+       )
+'
+
+test_expect_success 'moving the superproject does not break submodules' '
+       (
+               cd addtest &&
+               git submodule status >expect
+       )
+       mv addtest addtest2 &&
+       (
+               cd addtest2 &&
+               git submodule status >actual &&
+               test_cmp expect actual
+       )
+'
+
 test_done