From: Derrick Stolee <dstolee@xxxxxxxxxxxxx> The previous change added upgrade_to_worktree_config() to assist creating a worktree-specific config for the first time. However, this requires every config writer to care about that upgrade before writing to the worktree-specific config. In addition, callers need to know how to generate the name of the config.worktree file and pass it to the config API. To assist, create a new repo_config_set_worktree_gently() method in the config API that handles the upgrade_to_worktree_config() method in addition to assigning the value in the worktree-specific config. This will be consumed by an upcoming change. Signed-off-by: Derrick Stolee <dstolee@xxxxxxxxxxxxx> --- config.c | 10 ++++++++++ config.h | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/config.c b/config.c index 9c9eef16018..81f3a689c11 100644 --- a/config.c +++ b/config.c @@ -21,6 +21,7 @@ #include "dir.h" #include "color.h" #include "refs.h" +#include "worktree.h" struct config_source { struct config_source *prev; @@ -2880,6 +2881,15 @@ int git_config_set_gently(const char *key, const char *value) return git_config_set_multivar_gently(key, value, NULL, 0); } +int repo_config_set_worktree_gently(struct repository *r, + const char *key, const char *value) +{ + return upgrade_to_worktree_config(r) || + git_config_set_multivar_in_file_gently( + repo_git_path(r, "config.worktree"), + key, value, NULL, 0); +} + void git_config_set(const char *key, const char *value) { repo_config_set(the_repository, key, value); diff --git a/config.h b/config.h index 5531fc018e3..b05c51b3528 100644 --- a/config.h +++ b/config.h @@ -253,6 +253,13 @@ void git_config_set_in_file(const char *, const char *, const char *); int git_config_set_gently(const char *, const char *); +/** + * Write a config value into the config.worktree file for the current + * worktree. This will initialize extensions.worktreeConfig if necessary, + * which might trigger some changes to the root repository's config file. + */ +int repo_config_set_worktree_gently(struct repository *, const char *, const char *); + /** * write config values to `.git/config`, takes a key/value pair as parameter. */ -- gitgitgadget