submodule add: configure existing submodule url if not set
authorW. Trevor King <wking@tremily.us>
Sun, 2 Dec 2012 15:24:46 +0000 (10:24 -0500)
committerW. Trevor King <wking@tremily.us>
Mon, 3 Dec 2012 14:37:02 +0000 (09:37 -0500)
Note that relative repository arguments passed to

  $ git submodule add <repository> [<path>]

are expanded relative to the superproject's remote URL, not relative
to the current working directory.

Signed-off-by: W. Trevor King <wking@tremily.us>
git-submodule.sh

index dd00adb0824a94fb8daab383ee97af9eaa9fdc61..8b47db6a3c9b4d31009b00248bc1e2b2a84bec0b 100755 (executable)
@@ -496,7 +496,18 @@ Use -f if you really want to add it." >&2
                else
                        die "$(eval_gettext "'\$sm_path' already exists and is not a valid git repo")"
                fi
-
+               # if the submodule's remote URL is not set, set it
+               up_path=$(get_up_path "$sm_path")
+               sub_url=$(join_urls "$up_path" "$realrepo")
+               (
+                       clear_local_git_env
+                       cd "$sm_path" &&
+                       remote=$(get_default_remote) &&
+                       if ! git config remote."$remote".url > /dev/null 2>/dev/null
+                       then
+                               git config remote."$remote".url "$sub_url"
+                       fi
+               ) || die "$(eval_gettext "Unable to configure submodule remote '\$sm_path'")"
        else
 
                module_clone "$sm_path" "$realrepo" "$reference" || exit