Skip to content

Commit c1ab00f

Browse files
stefanbellergitster
authored andcommitted
submodule update --init: correct path handling in recursive submodules
When calling `git submodule init` from a recursive instance of `git submodule update --recursive`, the reported path is wrong as it skips the nested submodules. The new test demonstrates a failure in the code prior to this patch. Instead of getting the expected Submodule 'submodule' (${pwd}/submodule) registered for path '../super/submodule' the `super` directory is omitted and you get Submodule 'submodule' (${pwd}/submodule) registered for path '../submodule' instead. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ea2fa10 commit c1ab00f

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

git-submodule.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ cmd_init()
473473
die_if_unmatched "$mode"
474474
name=$(git submodule--helper name "$sm_path") || exit
475475

476-
displaypath=$(relative_path "$sm_path")
476+
displaypath=$(relative_path "$prefix$sm_path")
477477

478478
# Copy url setting when it is not set yet
479479
if test -z "$(git config "submodule.$name.url")"

t/t7406-submodule-update.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ test_expect_success 'setup a submodule tree' '
6363
git submodule add ../none none &&
6464
test_tick &&
6565
git commit -m "none"
66+
) &&
67+
git clone . recursivesuper &&
68+
( cd recursivesuper
69+
git submodule add ../super super
6670
)
6771
'
6872

@@ -95,6 +99,35 @@ test_expect_success 'submodule update from subdirectory' '
9599
)
96100
'
97101

102+
supersha1=$(git -C super rev-parse HEAD)
103+
mergingsha1=$(git -C super/merging rev-parse HEAD)
104+
nonesha1=$(git -C super/none rev-parse HEAD)
105+
rebasingsha1=$(git -C super/rebasing rev-parse HEAD)
106+
submodulesha1=$(git -C super/submodule rev-parse HEAD)
107+
pwd=$(pwd)
108+
109+
cat <<EOF >expect
110+
Submodule path '../super': checked out '$supersha1'
111+
Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
112+
Submodule 'none' ($pwd/none) registered for path '../super/none'
113+
Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
114+
Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
115+
Submodule path '../super/merging': checked out '$mergingsha1'
116+
Submodule path '../super/none': checked out '$nonesha1'
117+
Submodule path '../super/rebasing': checked out '$rebasingsha1'
118+
Submodule path '../super/submodule': checked out '$submodulesha1'
119+
EOF
120+
121+
test_expect_success 'submodule update --init --recursive from subdirectory' '
122+
git -C recursivesuper/super reset --hard HEAD^ &&
123+
(cd recursivesuper &&
124+
mkdir tmp &&
125+
cd tmp &&
126+
git submodule update --init --recursive ../super >../../actual
127+
) &&
128+
test_cmp expect actual
129+
'
130+
98131
apos="'";
99132
test_expect_success 'submodule update does not fetch already present commits' '
100133
(cd submodule &&

0 commit comments

Comments
 (0)