Re: [PATCH 1/2] config: use gitdir to get worktree config
From: Derrick Stolee <hidden>
Date: 2023-05-25 20:05:38
On 5/24/2023 9:05 PM, Glen Choo wrote:
"Victoria Dye via GitGitGadget" [off-list ref] writes:quoted
From: Victoria Dye <redacted> Update 'do_git_config_sequence()' to read the worktree config from 'config.worktree' in 'opts->git_dir' rather than the gitdir of 'the_repository'.Thanks for the patches! This makes sense. do_git_config_sequence() is eventually called by repo_config(), which is supposed to read config into a "struct repository", so any reliance on the_repository's settings is wrong.
quoted
+test_expect_success '--recurse-submodules parses submodule repo config' ' + test_when_finished "git -C submodule config --unset feature.experimental" && + git -C submodule config feature.experimental "invalid non-boolean value" && + test_must_fail git ls-files --recurse-submodules 2>err && + grep "bad boolean config value" err +'This test has a few bits that are important but non-obvious. It would be useful to capture them in either the commit message or a comment. Firstly, we can't test this using "git config" because that only uses the_repository, and we specifically need to read config in-core into a "struct repository" that is a submodule, so we need a command that recurses into a submodule without using subprocesses. IIRC the only choices are "git grep" and "git ls-files". Secondly, when we test that config is read from the submodule the choice of "feature.experimental" is quite important. The config is read quite indirectly: "git ls-files" reads from the submodule's index, which will call prepare_repo_settings() on the submodule, and eventually calls repo_config_get_bool() on "feature.experimental". Any of the configs in prepare_repo_settings() should do, though. A tiny suggestion would be to use "index.sparse" instead of "feature.experimental", since (I presume) we'll have to add sparse index + submodule tests for "git ls-files" eventually.
Some of the points you bring up are definitely subtle, like the choice of config variable. I appreciate that there are two tests here: one to verify the test checks have a similar effect without using the worktree config, and then a second test to show the same behavior with worktree config. If I understand correctly, the first test would pass without this code change, but it is a helpful one to help add confidence in the second test.
+test_expect_success '--recurse-submodules parses submodule worktree config' 'quoted
+ test_when_finished "git -C submodule config --unset extensions.worktreeConfig" &&I believe "test_config -C" will achieve the desired effect.
This should work, though it requires acting a bit strangely, at least if we want to replace the 'git config --worktree' command. test_config treats the positions of the arguments as special, so we would need to write it as: test_config -C submodule feature.experimental --worktree "non boolean value" and that's assuming that 'git -C submodule config feature.experimental --worktree "non boolean value"' is parsed correctly to use the --worktree argument. (I haven't tried it.) By using this order, that allows the test_config helper to run the appropriate 'test_when_finished git config --unset feature.experimental' command. Thanks, -Stolee