Skip to content

Commit

Permalink
test-lib-functions: support "test_config -C <dir> ..."
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
John Keeping authored and Junio C Hamano committed Sep 8, 2015
1 parent c545bc6 commit 5fafc07
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions t/test-lib-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 () {
Expand Down

0 comments on commit 5fafc07

Please sign in to comment.