diff mbox series

[10/10] submodule ensure-core-worktree: write to config.worktree

Message ID 20190116103159.9305-11-pclouds@gmail.com (mailing list archive)
State New, archived
Headers show
Series Support using submodules with worktrees | expand

Commit Message

Duy Nguyen Jan. 16, 2019, 10:31 a.m. UTC
Use repo_config_set_worktree_gently() to write core.worktree. If the
submodule has extensions.worktreeConfig on, the key will be in
config.worktree instead of config file and not affect any new
submodule's worktrees.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/submodule--helper.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 8a12d2f0ed..890de5902c 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2063,18 +2063,16 @@  static int ensure_core_worktree(int argc, const char **argv, const char *prefix)
 		die(_("could not get a repository handle for submodule '%s'"), path);
 
 	if (!repo_config_get_string(&subrepo, "core.worktree", &cw)) {
-		char *cfg_file, *abs_path;
+		char *abs_path;
 		const char *rel_path;
 		struct strbuf sb = STRBUF_INIT;
 
-		cfg_file = repo_git_path(&subrepo, "config");
-
 		abs_path = absolute_pathdup(path);
 		rel_path = relative_path(abs_path, subrepo.gitdir, &sb);
 
-		git_config_set_in_file(cfg_file, "core.worktree", rel_path);
+		if (repo_config_set_worktree_gently(&subrepo, "core.worktree", rel_path))
+			die(_("could not set '%s' to '%s'"), "core.worktree", rel_path);
 
-		free(cfg_file);
 		free(abs_path);
 		strbuf_release(&sb);
 	}