diff options
author | Jens Lehmann <Jens.Lehmann@web.de> | 2012-01-24 22:49:56 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-01-24 14:18:18 -0800 |
commit | 1017c1abcb6d733e1de83eb5a1cf7e1bf4ad6aca (patch) | |
tree | b73600700d9bbe43f66b40cb6056aba055f3be8f | |
parent | Merge branch 'tc/submodule-clone-name-detection' (diff) | |
download | tgif-1017c1abcb6d733e1de83eb5a1cf7e1bf4ad6aca.tar.xz |
submodule add: fix breakage when re-adding a deep submodule
Since recently a submodule with name <name> has its git directory in the
.git/modules/<name> directory of the superproject while the work tree
contains a gitfile pointing there.
When the same submodule is added on a branch where it wasn't present so
far (it is not found in the .gitmodules file), the name is not initialized
from the path as it should. This leads to a wrong path entered in the
gitfile when the .git/modules/<name> directory is found, as this happily
uses the - now empty - name. It then always points only a single directory
up, even if we have a path deeper in the directory hierarchy.
Fix that by initializing the name of the submodule early in module_clone()
if module_name() returned an empty name and add a test to catch that bug.
Reported-by: Jehan Bing <jehan@orb.com>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rwxr-xr-x | git-submodule.sh | 1 | ||||
-rwxr-xr-x | t/t7406-submodule-update.sh | 8 |
2 files changed, 9 insertions, 0 deletions
diff --git a/git-submodule.sh b/git-submodule.sh index 3adab93635..9bb2e13e92 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -131,6 +131,7 @@ module_clone() gitdir= gitdir_base= name=$(module_name "$path" 2>/dev/null) + test -n "$name" || name="$path" base_path=$(dirname "$path") gitdir=$(git rev-parse --git-dir) diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 33b292b8a8..5b97222c48 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -611,4 +611,12 @@ test_expect_success 'submodule update places git-dir in superprojects git-dir re ) ' +test_expect_success 'submodule add properly re-creates deeper level submodules' ' + (cd super && + git reset --hard master && + rm -rf deeper/ && + git submodule add ../submodule deeper/submodule + ) +' + test_done |