diff options
-rwxr-xr-x | git-submodule.sh | 18 | ||||
-rwxr-xr-x | t/t7400-submodule-basic.sh | 20 |
2 files changed, 38 insertions, 0 deletions
diff --git a/git-submodule.sh b/git-submodule.sh index 2a93c611e..c405caaa0 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -169,6 +169,24 @@ module_clone() fi echo "gitdir: $rel_gitdir" >"$path/.git" + + a=$(cd "$gitdir" && pwd)/ + b=$(cd "$path" && pwd)/ + # Remove all common leading directories after a sanity check + if test "${a#$b}" != "$a" || test "${b#$a}" != "$b"; then + die "$(eval_gettext "Gitdir '\$a' is part of the submodule path '\$b' or vice versa")" + fi + while test "${a%%/*}" = "${b%%/*}" + do + a=${a#*/} + b=${b#*/} + done + # Now chop off the trailing '/'s that were added in the beginning + a=${a%/} + b=${b%/} + + rel=$(echo $a | sed -e 's|[^/]*|..|g') + (clear_local_git_env; cd "$path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b") } # diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 2b70b2298..b377a7af2 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -81,6 +81,13 @@ test_expect_success 'submodule add' ' 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 ) && @@ -500,4 +507,17 @@ test_expect_success 'relative path works with user@host:path' ' ) ' +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 |