Thread (87 messages) flat view 87 messages, 5 authors, 2021-02-09
STALE2052d

Revision v2 of 6 in this series.

Revisions (6)
  1. rfc [diff vs current]
  2. v2 current
  3. v3 [diff vs current]
  4. v4 [diff vs current]
  5. v5 [diff vs current]
  6. v6 [diff vs current]

[RFC PATCH v2 2/4] config: load the correct config.worktree file

From: Matheus Tavares <hidden>
Date: 2020-05-10 00:42:04
Subsystem: the rest · Maintainer: Linus Torvalds

One of the steps in do_git_config_sequence() is to load the
worktree-specific config file. Although the function receives a git_dir
string, it relies on git_pathdup(), which uses the_repository->git_dir,
to make the path to the file. Thus, when a submodule has a worktree
setting, a command executed in the superproject that recurses into the
submodule won't find the said setting. Such a scenario might not be
needed now, but it will be in the following patch. git-grep will learn
to honor sparse checkouts and, when running with --recurse-submodules,
the submodule's sparse checkout settings must be loaded. As these
settings are stored in the config.worktree file, they would be ignored
without this patch.

The fix is simple, we replace git_pathdup() with mkpathdup(), to format
the path with the given git_dir. This is the same idea used to make the
config.worktree path in setup.c:check_repository_format_gently().

Signed-off-by: Matheus Tavares <redacted>
---
 config.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/config.c b/config.c
index 8db9c77098..a3d0a0d266 100644
--- a/config.c
+++ b/config.c
@@ -1747,8 +1747,9 @@ static int do_git_config_sequence(const struct config_options *opts,
 		ret += git_config_from_file(fn, repo_config, data);
 
 	current_parsing_scope = CONFIG_SCOPE_WORKTREE;
-	if (!opts->ignore_worktree && repository_format_worktree_config) {
-		char *path = git_pathdup("config.worktree");
+	if (!opts->ignore_worktree && repository_format_worktree_config &&
+	    opts->git_dir) {
+		char *path = mkpathdup("%s/config.worktree", opts->git_dir);
 		if (!access_or_die(path, R_OK, 0))
 			ret += git_config_from_file(fn, path, data);
 		free(path);
-- 
2.26.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help