Skip to content

Commit 0cd2c74

Browse files
committed
test_config, test_unconfig: add a --git-dir option
In the spirit of 8d1a744 (setup.c: create `safe.bareRepository`, 2022-07-14), Git's test suite should be prepared for a potential default change of that setting from `all` to `explicit`. The `test_config` and `test_unconfig` helpers use `git -C <dir> config` under the hood, and that triggers implicit bare repository discovery when <dir> is a bare repository. Add a `--git-dir` option alongside the existing `-C` option. When specified, the helpers pass `--git-dir=<dir>` instead of `-C <dir>` to the underlying `git config` call, and the `test_when_finished` cleanup registered by `test_config` uses `test_unconfig --git-dir` accordingly. This ensures that both the set and the unset paths bypass discovery. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent f5ec623 commit 0cd2c74

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

t/test-lib-functions.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,13 +579,20 @@ test_modebits () {
579579
# Unset a configuration variable, but don't fail if it doesn't exist.
580580
test_unconfig () {
581581
config_dir=
582+
config_git_dir=
582583
if test "$1" = -C
583584
then
584585
shift
585586
config_dir=$1
586587
shift
588+
elif test "$1" = --git-dir
589+
then
590+
shift
591+
config_git_dir=$1
592+
shift
587593
fi
588-
git ${config_dir:+-C "$config_dir"} config --unset-all "$@"
594+
git ${config_git_dir:+--git-dir="$config_git_dir"} \
595+
${config_dir:+-C "$config_dir"} config --unset-all "$@"
589596
config_status=$?
590597
case "$config_status" in
591598
5) # ok, nothing to unset
@@ -598,11 +605,17 @@ test_unconfig () {
598605
# Set git config, automatically unsetting it after the test is over.
599606
test_config () {
600607
config_dir=
608+
config_git_dir=
601609
if test "$1" = -C
602610
then
603611
shift
604612
config_dir=$1
605613
shift
614+
elif test "$1" = --git-dir
615+
then
616+
shift
617+
config_git_dir=$1
618+
shift
606619
fi
607620

608621
# If --worktree is provided, use it to configure/unconfigure
@@ -613,8 +626,10 @@ test_config () {
613626
shift
614627
fi
615628

616-
test_when_finished "test_unconfig ${config_dir:+-C '$config_dir'} ${is_worktree:+--worktree} '$1'" &&
617-
git ${config_dir:+-C "$config_dir"} config ${is_worktree:+--worktree} "$@"
629+
test_when_finished "test_unconfig ${config_git_dir:+--git-dir '$config_git_dir'} \
630+
${config_dir:+-C '$config_dir'} ${is_worktree:+--worktree} '$1'" &&
631+
git ${config_git_dir:+--git-dir="$config_git_dir"} \
632+
${config_dir:+-C "$config_dir"} config ${is_worktree:+--worktree} "$@"
618633
}
619634

620635
test_config_global () {

0 commit comments

Comments
 (0)