git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] config: use gitdir to get worktree config

From
Glen Choo <chooglen@google.com>
Date
May 25, 2023, 01:05 UTC
Message-ID
<kl6ly1ldxlsv.fsf@chooglen-macbookpro.roam.corp.google.com>
In-Reply-To
<aead2fe1ce162949fb313a92fe960e5a64512f60.1684883872.git.gitgitgadget@gmail.com>
"Victoria Dye via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 5 quoted lines
> From: Victoria Dye <vdye@github.com>
>
> Update 'do_git_config_sequence()' to read the worktree config from
> 'config.worktree' in 'opts->git_dir' rather than the gitdir of
> 'the_repository'.

Thanks for the patches! This makes sense. do_git_config_sequence() is eventually called by repo_config(), which is supposed to read config into a "struct repository", so any reliance on the_repository's settings is wrong.

>                                        Note that behavior still isn't ideal
> because 'extensions.worktreeConfig' in the super project[...]
Nit: We typically use "superproject" without the space.
Show 30 quoted lines
> diff --git a/config.c b/config.c
> index b79baf83e35..a93f7bfa3aa 100644
> --- a/config.c
> +++ b/config.c
> @@ -2200,14 +2200,24 @@ static int do_git_config_sequence(struct config_reader *reader,
>  	char *xdg_config = NULL;
>  	char *user_config = NULL;
>  	char *repo_config;
> +	char *worktree_config;
>  	enum config_scope prev_parsing_scope = reader->parsing_scope;
>  
> -	if (opts->commondir)
> +	/*
> +	 * Ensure that either:
> +	 * - the git_dir and commondir are both set, or
> +	 * - the git_dir and commondir are both NULL
> +	 */
> +	if (!opts->git_dir != !opts->commondir)
> +		BUG("only one of commondir and git_dir is non-NULL");
> +
> +	if (opts->commondir) {
>  		repo_config = mkpathdup("%s/config", opts->commondir);
> -	else if (opts->git_dir)
> -		BUG("git_dir without commondir");
> -	else
> +		worktree_config = mkpathdup("%s/config.worktree", opts->git_dir);
> +	} else {
>  		repo_config = NULL;
> +		worktree_config = NULL;
> +	}

Makes sense to me. I don't see why we would ever want to set one without the other.

I looked into whether we could get replace opts->commondir and opts->git_dir with a "struct repository" arg, but unfortunately read_early_config() needs to pass these values without touching "the_repository".

Show 14 quoted lines
> diff --git a/t/t3007-ls-files-recurse-submodules.sh b/t/t3007-ls-files-recurse-submodules.sh
> index dd7770e85de..e35c203241f 100755
> --- a/t/t3007-ls-files-recurse-submodules.sh
> +++ b/t/t3007-ls-files-recurse-submodules.sh
> @@ -299,6 +299,29 @@ test_expect_success '--recurse-submodules does not support --error-unmatch' '
>  	test_i18ngrep "does not support --error-unmatch" actual
>  '
>  
> +test_expect_success '--recurse-submodules parses submodule repo config' '
> +	test_when_finished "git -C submodule config --unset feature.experimental" &&
> +	git -C submodule config feature.experimental "invalid non-boolean value" &&
> +	test_must_fail git ls-files --recurse-submodules 2>err &&
> +	grep "bad boolean config value" err
> +'

This test has a few bits that are important but non-obvious. It would be useful to capture them in either the commit message or a comment.

Firstly, we can't test this using "git config" because that only uses the_repository, and we specifically need to read config in-core into a "struct repository" that is a submodule, so we need a command that recurses into a submodule without using subprocesses. IIRC the only choices are "git grep" and "git ls-files".

Secondly, when we test that config is read from the submodule the choice of "feature.experimental" is quite important. The config is read quite indirectly: "git ls-files" reads from the submodule's index, which will call prepare_repo_settings() on the submodule, and eventually calls repo_config_get_bool() on "feature.experimental". Any of the configs in prepare_repo_settings() should do, though. A tiny suggestion would be to use "index.sparse" instead of "feature.experimental", since (I presume) we'll have to add sparse index + submodule tests for "git ls-files" eventually.

> +test_expect_success '--recurse-submodules parses submodule worktree config' '
> +	test_when_finished "git -C submodule config --unset extensions.worktreeConfig" &&
I believe "test_config -C" will achieve the desired effect.
Previous: Victoria Dye via GitGitGadgetNext: Derrick Stolee
Message 3 of 29 in “Fix behavior of worktree config in submodules”
  1. 0/2 Fix behavior of worktree config in submodulesVictoria Dye via GitGitGadget, May 23, 2023
  2. 1/2 config: use gitdir to get worktree configVictoria Dye via GitGitGadget, May 23, 2023
  3. Glen ChooMay 25, 2023
  4. Derrick StoleeMay 25, 2023
  5. 2/2 repository: move 'repository_format_worktree_config' to repo scopeVictoria Dye via GitGitGadget, May 23, 2023
  6. Glen ChooMay 25, 2023
  7. Glen ChooMay 25, 2023
  8. Victoria DyeMay 25, 2023
  9. Derrick StoleeMay 25, 2023
  10. Junio C HamanoMay 24, 2023
  11. Glen ChooMay 25, 2023
  12. 0/3 Fix behavior of worktree config in submodulesVictoria Dye via GitGitGadget, May 26, 2023
  13. 1/3 config: use gitdir to get worktree configVictoria Dye via GitGitGadget, May 26, 2023
  14. 2/3 config: pass 'repo' directly to 'config_with_options()'Victoria Dye via GitGitGadget, May 26, 2023
  15. 3/3 repository: move 'repository_format_worktree_config' to repo scopeVictoria Dye via GitGitGadget, May 26, 2023
  16. Glen ChooMay 31, 2023
  17. Junio C HamanoJun 1, 2023
  18. Glen ChooJun 12, 2023
  19. Victoria DyeJun 7, 2023
  20. Glen ChooJun 12, 2023
  21. Victoria DyeJun 12, 2023
  22. Glen ChooJun 12, 2023
  23. setup: copy repository_format using helperGlen Choo, Jun 12, 2023
  24. Victoria DyeJun 13, 2023
  25. Glen ChooJun 13, 2023
  26. Junio C HamanoJun 13, 2023
  27. Derrick StoleeMay 26, 2023
  28. Glen ChooJun 13, 2023
  29. Victoria DyeJun 13, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.