submodule: add get_submodule_config helper funtion

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

W. Trevor King committed Dec 11, 2012 at 13:58 UTC 88ce00c378f709937c74a97037aa2692b883d683
1 file changed +26
git-submodule.sh
+26
@@ -152,6 +152,32 @@ die_if_unmatched ()
152 fi
153 }
154
155 +#
156 +# Print a submodule configuration setting
157 +#
158 +# $1 = submodule name
159 +# $2 = option name
160 +# $3 = default value
161 +#
162 +# Checks in the usual git-config places first (for overrides),
163 +# otherwise it falls back on .gitmodules. This allows you to
164 +# distribute project-wide defaults in .gitmodules, while still
165 +# customizing individual repositories if necessary. If the option is
166 +# not in .gitmodules either, print a default value.
167 +#
168 +get_submodule_config () {
169 + name="$1"
170 + option="$2"
171 + default="$3"
172 + value=$(git config submodule."$name"."$option")
173 + if test -z "$value"
174 + then
175 + value=$(git config -f .gitmodules submodule."$name"."$option")
176 + fi
177 + printf '%s' "${value:-$default}"
178 +}
179 +
180 +
181 #
182 # Map submodule path to submodule name
183 #