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 <ps@pks.im> Reviewed-by: Christian Couder <christian.couder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jan 29, 2024 at 12:07 UTC 91c5a5e000f765d8da351a094e8952317fe4e5dc
1 file changed +50 -28
t/t1300-config.sh
+50 -28
@@ -1098,15 +1098,20 @@ test_expect_success SYMLINKS 'symlink to nonexistent configuration' '
1098 test_must_fail git config --file=linktolinktonada --list
1099 '
1100
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 +'
1115
1116 test_expect_success 'git -c "key=value" support' '
1117 cat >expect <<-\EOF &&
@@ -1157,10 +1162,16 @@ test_expect_success 'git -c works with aliases of builtins' '
1162 '
1163
1164 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 + )
1175 '
1176
1177 test_expect_success 'git -c does not split values on equals' '
@@ -2009,11 +2020,11 @@ test_expect_success '--show-origin getting a single key' '
2020 '
2021
2022 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 &&
2024 [user]
2025 custom = true
2026 EOF
2027 + CUSTOM_CONFIG_FILE="$(test-tool path-utils real_path custom.conf)"
2028 '
2029
2030 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' '
2063 '
2064
2065 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 + )
2077 '
2078
2079 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 + )
2093 '
2094
2095 test_expect_success '--show-origin with --default' '