Skip to content

Commit 91c5a5e

Browse files
pks-tgitster
authored andcommitted
t1300: make tests more robust with non-default ref backends
The t1300 test suite exercises the git-config(1) tool. To do so, the test overwrites ".git/config" to contain custom contents in several places with code like the following: ``` cat > .git/config <<\EOF ... EOF ``` While this is easy enough to do, it may create problems when using a non-default repository format because this causes us to overwrite the repository format version as well as any potential extensions. With the upcoming "reftable" ref backend the result is that Git would try to access refs via the "files" backend even though the repository has been initialized with the "reftable" backend, which will cause failures when trying to access any refs. Ideally, we would rewrite the whole test suite to not depend on state written by previous tests, but that would result in a lot of changes in this test suite. Instead, we only refactor tests which access the refdb to be more robust by using their own separate repositories, which allows us to be more careful and not discard required extensions. Note that we also have to touch up how the CUSTOM_CONFIG_FILE gets accessed. This environment variable contains the relative path to a custom config file which we're setting up. But because we are now using subrepositories, this relative path will not be found anymore because our working directory changes. This issue is addressed by storing the absolute path to the file in CUSTOM_CONFIG_FILE instead. Signed-off-by: Patrick Steinhardt <[email protected]> Reviewed-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a54a84b commit 91c5a5e

File tree

1 file changed

+50
-28
lines changed

1 file changed

+50
-28
lines changed

t/t1300-config.sh

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,15 +1098,20 @@ test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
10981098
test_must_fail git config --file=linktolinktonada --list
10991099
'
11001100

1101-
test_expect_success 'check split_cmdline return' "
1102-
git config alias.split-cmdline-fix 'echo \"' &&
1103-
test_must_fail git split-cmdline-fix &&
1104-
echo foo > foo &&
1105-
git add foo &&
1106-
git commit -m 'initial commit' &&
1107-
git config branch.main.mergeoptions 'echo \"' &&
1108-
test_must_fail git merge main
1109-
"
1101+
test_expect_success 'check split_cmdline return' '
1102+
test_when_finished "rm -rf repo" &&
1103+
git init repo &&
1104+
(
1105+
cd repo &&
1106+
git config alias.split-cmdline-fix "echo \"" &&
1107+
test_must_fail git split-cmdline-fix &&
1108+
echo foo >foo &&
1109+
git add foo &&
1110+
git commit -m "initial commit" &&
1111+
git config branch.main.mergeoptions "echo \"" &&
1112+
test_must_fail git merge main
1113+
)
1114+
'
11101115

11111116
test_expect_success 'git -c "key=value" support' '
11121117
cat >expect <<-\EOF &&
@@ -1157,10 +1162,16 @@ test_expect_success 'git -c works with aliases of builtins' '
11571162
'
11581163

11591164
test_expect_success 'aliases can be CamelCased' '
1160-
test_config alias.CamelCased "rev-parse HEAD" &&
1161-
git CamelCased >out &&
1162-
git rev-parse HEAD >expect &&
1163-
test_cmp expect out
1165+
test_when_finished "rm -rf repo" &&
1166+
git init repo &&
1167+
(
1168+
cd repo &&
1169+
test_commit A &&
1170+
git config alias.CamelCased "rev-parse HEAD" &&
1171+
git CamelCased >out &&
1172+
git rev-parse HEAD >expect &&
1173+
test_cmp expect out
1174+
)
11641175
'
11651176

11661177
test_expect_success 'git -c does not split values on equals' '
@@ -2009,11 +2020,11 @@ test_expect_success '--show-origin getting a single key' '
20092020
'
20102021

20112022
test_expect_success 'set up custom config file' '
2012-
CUSTOM_CONFIG_FILE="custom.conf" &&
2013-
cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
2023+
cat >"custom.conf" <<-\EOF &&
20142024
[user]
20152025
custom = true
20162026
EOF
2027+
CUSTOM_CONFIG_FILE="$(test-tool path-utils real_path custom.conf)"
20172028
'
20182029

20192030
test_expect_success !MINGW 'set up custom config file with special name characters' '
@@ -2052,22 +2063,33 @@ test_expect_success '--show-origin stdin with file include' '
20522063
'
20532064

20542065
test_expect_success '--show-origin blob' '
2055-
blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2056-
cat >expect <<-EOF &&
2057-
blob:$blob user.custom=true
2058-
EOF
2059-
git config --blob=$blob --show-origin --list >output &&
2060-
test_cmp expect output
2066+
test_when_finished "rm -rf repo" &&
2067+
git init repo &&
2068+
(
2069+
cd repo &&
2070+
blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
2071+
cat >expect <<-EOF &&
2072+
blob:$blob user.custom=true
2073+
EOF
2074+
git config --blob=$blob --show-origin --list >output &&
2075+
test_cmp expect output
2076+
)
20612077
'
20622078

20632079
test_expect_success '--show-origin blob ref' '
2064-
cat >expect <<-\EOF &&
2065-
blob:main:custom.conf user.custom=true
2066-
EOF
2067-
git add "$CUSTOM_CONFIG_FILE" &&
2068-
git commit -m "new config file" &&
2069-
git config --blob=main:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
2070-
test_cmp expect output
2080+
test_when_finished "rm -rf repo" &&
2081+
git init repo &&
2082+
(
2083+
cd repo &&
2084+
cat >expect <<-\EOF &&
2085+
blob:main:custom.conf user.custom=true
2086+
EOF
2087+
cp "$CUSTOM_CONFIG_FILE" custom.conf &&
2088+
git add custom.conf &&
2089+
git commit -m "new config file" &&
2090+
git config --blob=main:custom.conf --show-origin --list >output &&
2091+
test_cmp expect output
2092+
)
20712093
'
20722094

20732095
test_expect_success '--show-origin with --default' '

0 commit comments

Comments
 (0)