From 8962ba86d4e24d7e3a4af218921c580c87b9b5b5 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 1 Dec 2012 12:11:45 -0500 Subject: [PATCH] submodule sync: add --local and --no-local These control whether or not the submodule..url setting is set in the superproject config. With --local, the setting is always set. With --no-local, it is only set if another value is already set. Use $ git submodule sync --local to forcibly populate the local config, and $ git submodule sync --no-local to only update the existing local configuration. Default to --local for compatibility with earlier versions of Git. Signed-off-by: W. Trevor King --- git-submodule.sh | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index d48b4ea35..e9c96a036 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -11,7 +11,7 @@ USAGE="[--quiet] add [-b branch] [-f|--force] [--reference ] [--] ] [--merge] [--recursive] [--] [...] or: $dashless [--quiet] summary [--cached|--files] [--summary-limit ] [commit] [--] [...] or: $dashless [--quiet] foreach [--recursive] - or: $dashless [--quiet] sync [--] [...]" + or: $dashless [--quiet] sync [--local] [--no-local] [--] [...]" OPTIONS_SPEC= . git-sh-setup . git-sh-i18n @@ -27,6 +27,7 @@ recursive= files= nofetch= update= +local= prefix= # @@ -1140,6 +1141,7 @@ cmd_status() # cmd_sync() { + local=1 while test $# -ne 0 do case "$1" in @@ -1147,6 +1149,14 @@ cmd_sync() GIT_QUIET=1 shift ;; + --local) + local=1 + shift + ;; + --no-local) + local= + shift + ;; --) shift break @@ -1165,26 +1175,26 @@ cmd_sync() do die_if_unmatched "$mode" name=$(module_name "$sm_path") - # .gitmodules-style (unresolved) url for the submodule origin repo - super_config_url=$(get_submodule_config "$name" url) - # path from submodule work tree to submodule origin repo - sub_origin_url=$(get_submodule_url "$name" "$sm_path") - if git config "submodule.$name.url" >/dev/null 2>/dev/null + if test -n "$local" || git config "submodule.$name.url" >/dev/null 2>/dev/null then + # path from supermodule work tree to submodule origin repo + super_config_url=$(get_submodule_url_from_gitmodules "$name") say "$(eval_gettext "Synchronizing submodule url for '\$name' (superproject config)")" git config submodule."$name".url "$super_config_url" fi if test -e "$sm_path"/.git then - say "$(eval_gettext "Synchronizing submodule url for '\$name' (subproject config)")" - ( - clear_local_git_env - cd "$sm_path" - remote=$(get_default_remote) - git config remote."$remote".url "$sub_origin_url" - ) + # path from submodule work tree to submodule origin repo + sub_origin_url=$(get_submodule_url "$name" "$sm_path") + say "$(eval_gettext "Synchronizing submodule url for '\$name' (subproject config)")" + ( + clear_local_git_env + cd "$sm_path" + remote=$(get_default_remote) + git config remote."$remote".url "$sub_origin_url" + ) fi done } -- 2.26.2