Re: [RFC PATCH v2 2/4] config: load the correct config.worktree file
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 11, 2020, 19:10 UTC
- Message-ID
- <xmqqlflyqocl.fsf@gitster.c.googlers.com>
- In-Reply-To
- <882310b69fd3df0acc6823a2c73bbe1801d9f6c4.1589058209.git.matheus.bernardino@usp.br>
Matheus Tavares <matheus.bernardino@usp.br> writes:
Show 6 quoted lines
> 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.
This has far wider ramifications than just "git grep" and it may be an important fix. Anything that wants to read from a per-worktree configuration is not working as expected when run from a secondary worktree, right?
Can we add a test or two to protect this fix from future breakages?
Show 9 quoted lines
> 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);