Commit b2e21eec authored by Duy Nguyen's avatar Duy Nguyen

worktree.c: add get_worktree_config()

"git config --worktree" can write to the write file whether
extensions.worktreeConfig is enabled or not. In order to do the same
using config API, we need to determine the right file to write to. Add
this function for that purpose. This is the basis for the coming
repo_config_set_worktree()
parent 1d7ccc34
...@@ -650,18 +650,13 @@ int cmd_config(int argc, const char **argv, const char *prefix) ...@@ -650,18 +650,13 @@ int cmd_config(int argc, const char **argv, const char *prefix)
else if (use_local_config) else if (use_local_config)
given_config_source.file = git_pathdup("config"); given_config_source.file = git_pathdup("config");
else if (use_worktree_config) { else if (use_worktree_config) {
struct worktree **worktrees = get_worktrees(0); given_config_source.file = get_worktree_config(the_repository);
if (repository_format_worktree_config) if (!given_config_source.file)
given_config_source.file = git_pathdup("config.worktree");
else if (worktrees[0] && worktrees[1])
die(_("--worktree cannot be used with multiple " die(_("--worktree cannot be used with multiple "
"working trees unless the config\n" "working trees unless the config\n"
"extension worktreeConfig is enabled. " "extension worktreeConfig is enabled. "
"Please read \"CONFIGURATION FILE\"\n" "Please read \"CONFIGURATION FILE\"\n"
"section in \"git help worktree\" for details")); "section in \"git help worktree\" for details"));
else
given_config_source.file = git_pathdup("config");
free_worktrees(worktrees);
} else if (given_config_source.file) { } else if (given_config_source.file) {
if (!is_absolute_path(given_config_source.file) && prefix) if (!is_absolute_path(given_config_source.file) && prefix)
given_config_source.file = given_config_source.file =
......
...@@ -581,3 +581,19 @@ int other_head_refs(each_ref_fn fn, void *cb_data) ...@@ -581,3 +581,19 @@ int other_head_refs(each_ref_fn fn, void *cb_data)
free_worktrees(worktrees); free_worktrees(worktrees);
return ret; return ret;
} }
char *get_worktree_config(struct repository *r)
{
struct worktree **worktrees = get_worktrees(0);
char *path;
if (repository_format_worktree_config)
path = repo_git_path(r, "config.worktree");
else if (worktrees[0] && worktrees[1])
path = NULL;
else
path = repo_git_path(r, "config");
free_worktrees(worktrees);
return path;
}
...@@ -132,4 +132,11 @@ void strbuf_worktree_ref(const struct worktree *wt, ...@@ -132,4 +132,11 @@ void strbuf_worktree_ref(const struct worktree *wt,
const char *worktree_ref(const struct worktree *wt, const char *worktree_ref(const struct worktree *wt,
const char *refname); const char *refname);
/*
* Return the path to config file that can contain worktree-specific
* config (or NULL in unsupported setups). The caller must free the
* return value.
*/
char *get_worktree_config(struct repository *r);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment