Skip to content

Commit 5fafc07

Browse files
johnkeepinggitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c545bc6 commit 5fafc07

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

t/test-lib-functions.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,14 @@ test_chmod () {
201201

202202
# Unset a configuration variable, but don't fail if it doesn't exist.
203203
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 "$@"
205212
config_status=$?
206213
case "$config_status" in
207214
5) # ok, nothing to unset
@@ -213,8 +220,15 @@ test_unconfig () {
213220

214221
# Set git config, automatically unsetting it after the test is over.
215222
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 "$@"
218232
}
219233

220234
test_config_global () {

0 commit comments

Comments
 (0)