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 <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jens Lehmann committed Jun 26, 2011 at 01:26 UTC 2cd9de3e18183422cd7ec3cd81cebc656068ea42
1 file changed +18 -17
git-submodule.sh
+18 -17
@@ -231,7 +231,6 @@ cmd_add()
231 url="$repo"
232 ;;
233 esac
234 - git config submodule."$path".url "$url"
234 else
235
236 module_clone "$path" "$realrepo" "$reference" || exit
@@ -245,6 +244,7 @@ cmd_add()
244 esac
245 ) || die "Unable to checkout submodule '$path'"
246 fi
247 + git config submodule."$path".url "$url"
248
249 git add $force "$path" ||
250 die "Failed to add submodule '$path'"
@@ -340,25 +340,26 @@ cmd_init()
340 do
341 # Skip already registered paths
342 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
358
359 + # Copy "update" setting when it is not set yet
360 upd="$(git config -f .gitmodules submodule."$name".update)"
361 test -z "$upd" ||
362 + test -n "$(git config submodule."$name".update)" ||
363 git config submodule."$name".update "$upd" ||
364 die "Failed to register update mode for submodule path '$path'"
365