Skip to content

Commit 2cd9de3

Browse files
jlehmanngitster
authored andcommitted
submodule add: always initialize .git/config entry
When "git submodule add $path" is run to add a subdirectory $path to the superproject, and $path is already the top of the working tree of the submodule repository, the command created submodule.$path.url entry in the configuration file in the superproject. However, when adding a repository $URL that is outside the respository of the superproject to $path that does not exist (yet) with "git submodule add $URL $path", the command forgot to set it up. The user is expressing the interest in the submodule and wants to keep a checkout, the "submodule add" command should consistently set up the submodule.$path.url entry in either case. As a result "git submodule init" can't simply skip the initialization of those submodules for which it finds an url entry in the git./config anymore. That lead to problems when adding a submodule (which now sets the url), add the "update" setting to .gitmodules and expect init to copy that into .git/config like it is done in t7406. So change init to only then copy the "url" and "update" entries when they don't exist yet in the .git/config and do nothing otherwise. Signed-off-by: Jens Lehmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ccee608 commit 2cd9de3

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

git-submodule.sh

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ cmd_add()
231231
url="$repo"
232232
;;
233233
esac
234-
git config submodule."$path".url "$url"
235234
else
236235

237236
module_clone "$path" "$realrepo" "$reference" || exit
@@ -245,6 +244,7 @@ cmd_add()
245244
esac
246245
) || die "Unable to checkout submodule '$path'"
247246
fi
247+
git config submodule."$path".url "$url"
248248

249249
git add $force "$path" ||
250250
die "Failed to add submodule '$path'"
@@ -340,25 +340,26 @@ cmd_init()
340340
do
341341
# Skip already registered paths
342342
name=$(module_name "$path") || exit
343-
url=$(git config submodule."$name".url)
344-
test -z "$url" || continue
345-
346-
url=$(git config -f .gitmodules submodule."$name".url)
347-
test -z "$url" &&
348-
die "No url found for submodule path '$path' in .gitmodules"
349-
350-
# Possibly a url relative to parent
351-
case "$url" in
352-
./*|../*)
353-
url=$(resolve_relative_url "$url") || exit
354-
;;
355-
esac
356-
357-
git config submodule."$name".url "$url" ||
358-
die "Failed to register url for submodule path '$path'"
343+
if test -z "$(git config "submodule.$name.url")"
344+
then
345+
url=$(git config -f .gitmodules submodule."$name".url)
346+
test -z "$url" &&
347+
die "No url found for submodule path '$path' in .gitmodules"
348+
349+
# Possibly a url relative to parent
350+
case "$url" in
351+
./*|../*)
352+
url=$(resolve_relative_url "$url") || exit
353+
;;
354+
esac
355+
git config submodule."$name".url "$url" ||
356+
die "Failed to register url for submodule path '$path'"
357+
fi
359358

359+
# Copy "update" setting when it is not set yet
360360
upd="$(git config -f .gitmodules submodule."$name".update)"
361361
test -z "$upd" ||
362+
test -n "$(git config submodule."$name".update)" ||
362363
git config submodule."$name".update "$upd" ||
363364
die "Failed to register update mode for submodule path '$path'"
364365

0 commit comments

Comments
 (0)