config: introduce GIT_CONFIG_LEVEL_WORKTREE

Introduce the logical concept of a worktree-level config.  The new
value sits between _LOCAL and _APP to allow `git_config_get_*` to
'just work'.

The assumption of how `git_config_get_*` works was tested
experimentally by setting _WORKTREE to some nonsense value (like -3)
and watching the new test fail.
This commit is contained in:
Sean Allred
2022-02-06 07:22:59 -06:00
parent e62cdc9bcb
commit aa31120f7c
2 changed files with 23 additions and 1 deletions

View File

@@ -48,9 +48,13 @@ typedef enum {
*/
GIT_CONFIG_LEVEL_LOCAL = 5,
/** Worktree specific configuration file; $GIT_DIR/config.worktree
*/
GIT_CONFIG_LEVEL_WORKTREE = 6,
/** Application specific configuration file; freely defined by applications
*/
GIT_CONFIG_LEVEL_APP = 6,
GIT_CONFIG_LEVEL_APP = 7,
/** Represents the highest level available config file (i.e. the most
* specific config file available that actually is loaded)

View File

@@ -71,3 +71,21 @@ void test_config_configlevel__fetching_a_level_from_an_empty_compound_config_ret
git_config_free(cfg);
}
void test_config_configlevel__can_override_local_with_worktree(void)
{
git_config *cfg;
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_config_new(&cfg));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"),
GIT_CONFIG_LEVEL_WORKTREE, NULL, 1));
cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
GIT_CONFIG_LEVEL_LOCAL, NULL, 1));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.stringglobal"));
cl_assert_equal_s("don't find me!", buf.ptr);
git_buf_dispose(&buf);
git_config_free(cfg);
}