@matheusbsbs / matheus-bagliano / commits / 5fafc07fca
Fork 0

test-lib-functions: support "test_config -C <dir> ..."

If used in a subshell, test_config cannot unset variables at the end of a test. This is a problem when testing submodules because we do not want to "cd" at to top level of a test script in order to run the command inside the submodule. Add a "-C" option to test_config (and test_unconfig) so that test_config can be kept outside subshells and still affect subrepositories. Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

John Keeping committed Sep 5, 2015 at 14:12 UTC 5fafc07fca933be10c82ba97a6fd3b28d6b3a02e
1 file changed +17 -3
t/test-lib-functions.sh
+17 -3
@@ -201,7 +201,14 @@ test_chmod () {
201
202 # Unset a configuration variable, but don't fail if it doesn't exist.
203 test_unconfig () {
204 - git config --unset-all "$@"
204 + config_dir=
205 + if test "$1" = -C
206 + then
207 + shift
208 + config_dir=$1
209 + shift
210 + fi
211 + git ${config_dir:+-C "$config_dir"} config --unset-all "$@"
212 config_status=$?
213 case "$config_status" in
214 5) # ok, nothing to unset
@@ -213,8 +220,15 @@ test_unconfig () {
220
221 # Set git config, automatically unsetting it after the test is over.
222 test_config () {
216 - test_when_finished "test_unconfig '$1'" &&
217 - git config "$@"
223 + config_dir=
224 + if test "$1" = -C
225 + then
226 + shift
227 + config_dir=$1
228 + shift
229 + fi
230 + test_when_finished "test_unconfig ${config_dir:+-C '$config_dir'} '$1'" &&
231 + git ${config_dir:+-C "$config_dir"} config "$@"
232 }
233
234 test_config_global () {