submodule: add get_submodule_config helper funtion
authorW. Trevor King <wking@tremily.us>
Fri, 30 Nov 2012 16:52:36 +0000 (11:52 -0500)
committerW. Trevor King <wking@tremily.us>
Sat, 1 Dec 2012 22:05:03 +0000 (17:05 -0500)
Several submodule configuration variables
(e.g. fetchRecurseSubmodules) are read from .gitmodules with local
overrides from the usual git config files.  This shell function mimics
that logic to help initialize configuration variables in
git-submodule.sh.

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

index ab6b1107b6090494f192f361471ed5748ffa7dc1..97ce5e4083845577fe4cb6a24e54e57d257f76d3 100755 (executable)
@@ -151,6 +151,33 @@ die_if_unmatched ()
        fi
 }
 
+#
+# Print a submodule configuration setting
+#
+# $1 = submodule name
+# $2 = option name
+# $3 = default value
+#
+# Checks in the usual git-config places first (for overrides),
+# otherwise it falls back on .gitmodules.  This allows you to
+# distribute project-wide defaults in .gitmodules, while still
+# customizing individual repositories if necessary.  If the option is
+# not in .gitmodules either, print a default value.
+#
+get_submodule_config()
+{
+       name="$1"
+       option="$2"
+       default="$3"
+       value=$(git config submodule."$name"."$option")
+       if test -z "$value"
+       then
+               value=$(git config -f .gitmodules submodule."$name"."$option")
+       fi
+       printf '%s' "${value:-$default}"
+}
+
+
 #
 # Map submodule path to submodule name
 #