summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keeping <john@keeping.me.uk>2015-09-05 14:12:47 +0100
committerJunio C Hamano <gitster@pobox.com>2015-09-08 10:35:01 -0700
commit5fafc07fca933be10c82ba97a6fd3b28d6b3a02e (patch)
tree28f4fdadf956efa8543b89ecb3356971b2a342c8
parentc545bc6266e36fdb798cf79fd1f7ef9f39791a94 (diff)
downloadgit-5fafc07fca933be10c82ba97a6fd3b28d6b3a02e.tar.gz
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>
-rw-r--r--t/test-lib-functions.sh20
1 files changed, 17 insertions, 3 deletions
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index e8d3c0fdbc..0e80f377ce 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -201,7 +201,14 @@ test_chmod () {
# Unset a configuration variable, but don't fail if it doesn't exist.
test_unconfig () {
- git config --unset-all "$@"
+ config_dir=
+ if test "$1" = -C
+ then
+ shift
+ config_dir=$1
+ shift
+ fi
+ git ${config_dir:+-C "$config_dir"} config --unset-all "$@"
config_status=$?
case "$config_status" in
5) # ok, nothing to unset
@@ -213,8 +220,15 @@ test_unconfig () {
# Set git config, automatically unsetting it after the test is over.
test_config () {
- test_when_finished "test_unconfig '$1'" &&
- git config "$@"
+ config_dir=
+ if test "$1" = -C
+ then
+ shift
+ config_dir=$1
+ shift
+ fi
+ test_when_finished "test_unconfig ${config_dir:+-C '$config_dir'} '$1'" &&
+ git ${config_dir:+-C "$config_dir"} config "$@"
}
test_config_global () {