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 <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Mar 29, 2016 at 18:27 UTC c1ab00fb267fb0166376ff2c81083ef2cada6d9d
2 files changed +34 -1
git-submodule.sh
+1 -1
@@ -473,7 +473,7 @@ cmd_init()
473 die_if_unmatched "$mode"
474 name=$(git submodule--helper name "$sm_path") || exit
475
476 - displaypath=$(relative_path "$sm_path")
476 + displaypath=$(relative_path "$prefix$sm_path")
477
478 # Copy url setting when it is not set yet
479 if test -z "$(git config "submodule.$name.url")"
t/t7406-submodule-update.sh
+33
@@ -63,6 +63,10 @@ test_expect_success 'setup a submodule tree' '
63 git submodule add ../none none &&
64 test_tick &&
65 git commit -m "none"
66 + ) &&
67 + git clone . recursivesuper &&
68 + ( cd recursivesuper
69 + git submodule add ../super super
70 )
71 '
72
@@ -95,6 +99,35 @@ test_expect_success 'submodule update from subdirectory' '
99 )
100 '
101
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 +
131 apos="'";
132 test_expect_success 'submodule update does not fetch already present commits' '
133 (cd submodule &&