submodule sync: add --local and --no-local
authorW. Trevor King <wking@tremily.us>
Sat, 1 Dec 2012 17:11:45 +0000 (12:11 -0500)
committerW. Trevor King <wking@tremily.us>
Mon, 3 Dec 2012 14:37:00 +0000 (09:37 -0500)
These control whether or not the submodule.<name>.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 <wking@tremily.us>
git-submodule.sh

index 7a467c49b4f93cc2baa078c4661eeb9eb81b5259..dd00adb0824a94fb8daab383ee97af9eaa9fdc61 100755 (executable)
@@ -11,7 +11,7 @@ USAGE="[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <r
    or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
    or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
    or: $dashless [--quiet] foreach [--recursive] <command>
-   or: $dashless [--quiet] sync [--] [<path>...]"
+   or: $dashless [--quiet] sync [--local] [--no-local] [--] [<path>...]"
 OPTIONS_SPEC=
 . git-sh-setup
 . git-sh-i18n
@@ -28,6 +28,7 @@ init=
 files=
 nofetch=
 update=
+local=
 prefix=
 
 #
@@ -1147,6 +1148,7 @@ cmd_status()
 #
 cmd_sync()
 {
+       local=1
        while test $# -ne 0
        do
                case "$1" in
@@ -1154,6 +1156,14 @@ cmd_sync()
                        GIT_QUIET=1
                        shift
                        ;;
+               --local)
+                       local=1
+                       shift
+                       ;;
+               --no-local)
+                       local=
+                       shift
+                       ;;
                --)
                        shift
                        break
@@ -1172,26 +1182,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
 }