Skip to content

Commit 1017c1a

Browse files
jlehmanngitster
authored andcommitted
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>
1 parent 0b26d1e commit 1017c1a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

git-submodule.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ module_clone()
131131
gitdir=
132132
gitdir_base=
133133
name=$(module_name "$path" 2>/dev/null)
134+
test -n "$name" || name="$path"
134135
base_path=$(dirname "$path")
135136

136137
gitdir=$(git rev-parse --git-dir)

t/t7406-submodule-update.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,4 +611,12 @@ test_expect_success 'submodule update places git-dir in superprojects git-dir re
611611
)
612612
'
613613

614+
test_expect_success 'submodule add properly re-creates deeper level submodules' '
615+
(cd super &&
616+
git reset --hard master &&
617+
rm -rf deeper/ &&
618+
git submodule add ../submodule deeper/submodule
619+
)
620+
'
621+
614622
test_done

0 commit comments

Comments
 (0)