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

Re: [PATCH v3] worktree: detect from secondary worktree if main worktree is bare

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 31, 2025, 19:19 UTC
Message-ID
<xmqqcyg294ft.fsf@gitster.g>
In-Reply-To
<pull.1829.v3.git.1738346881907.gitgitgadget@gmail.com>
"Olga Pilipenco via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 21 quoted lines
> +/*
> +* When in a secondary worktree, and when extensions.worktreeConfig
> +* is true, only $commondir/config and $commondir/worktrees/<id>/
> +* config.worktree are consulted, hence any core.bare=true setting in
> +* $commondir/config.worktree gets overlooked. Thus, check it manually
> +* to determine if the repository is bare.
> +*/
> +static int is_main_worktree_bare(struct repository *repo)
> +{
> +	int bare = 0;
> +	struct config_set cs = {0};
> +	char *worktree_config = xstrfmt("%s/config.worktree", repo_get_common_dir(repo));
> +
> +	git_configset_init(&cs);
> +	git_configset_add_file(&cs, worktree_config);
> +	git_configset_get_bool(&cs, "core.bare", &bare);
> +
> +	git_configset_clear(&cs);
> +	free(worktree_config);
> +	return bare;
> +}
That is nicely described.
Show 20 quoted lines
>  /**
>   * get the main worktree
>   */
> @@ -79,16 +101,11 @@ static struct worktree *get_main_worktree(int skip_reading_head)
>  	CALLOC_ARRAY(worktree, 1);
>  	worktree->repo = the_repository;
>  	worktree->path = strbuf_detach(&worktree_path, NULL);
> -	/*
> -	 * NEEDSWORK: If this function is called from a secondary worktree and
> -	 * config.worktree is present, is_bare_repository_cfg will reflect the
> -	 * contents of config.worktree, not the contents of the main worktree.
> -	 * This means that worktree->is_bare may be set to 0 even if the main
> -	 * worktree is configured to be bare.
> -	 */
> -	worktree->is_bare = (is_bare_repository_cfg == 1) ||
> -		is_bare_repository();
>  	worktree->is_current = is_current_worktree(worktree);
> +	worktree->is_bare = (is_bare_repository_cfg == 1) ||
> +		is_bare_repository() ||
> +		(!worktree->is_current && is_main_worktree_bare(the_repository));

Is "this worktree does not have is_current bit set" equivalent to "this worktree is the main one, so is_main_worktree_bare() needs to be consulted"? That linkage between "the is_current bit unset" and "is the main worktree" is not obvious to me.

Thanks.
Previous: Olga Pilipenco via GitGitGadgetNext: Junio C Hamano
Message 8 of 19 in “worktree: detect from secondary worktree if main worktree is bare”
  1. worktree: detect from secondary worktree if main worktree is bareOlga Pilipenco via GitGitGadget, Nov 15, 2024
  2. worktree: detect from secondary worktree if main worktree is bareOlga Pilipenco via GitGitGadget, Jan 16, 2025
  3. Eric SunshineJan 19, 2025
  4. Olga PilipencoJan 28, 2025
  5. Eric SunshineJan 29, 2025
  6. Junio C HamanoJan 29, 2025
  7. worktree: detect from secondary worktree if main worktree is bareOlga Pilipenco via GitGitGadget, Jan 31, 2025
  8. Junio C HamanoJan 31, 2025
  9. Junio C HamanoJan 31, 2025
  10. Olga PilipencoJan 31, 2025
  11. Junio C HamanoJan 31, 2025
  12. Olga PilipencoFeb 4, 2025
  13. Junio C HamanoFeb 4, 2025
  14. Olga PilipencoFeb 4, 2025
  15. worktree: detect from secondary worktree if main worktree is bareOlga Pilipenco via GitGitGadget, Feb 5, 2025
  16. Eric SunshineJan 30, 2025
  17. Eric SunshineJan 30, 2025
  18. Olga PilipencoJan 31, 2025
  19. Eric SunshineJan 31, 2025

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.