From: Justin Tobler <jltobler@gmail.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 02/13] setup: mark bogus worktree in `apply_repository_format()`
Date: Mon, 6 Jul 2026 16:49:41 -0500 [thread overview]
Message-ID: <akwfAmyeIVJYXj1h@denethor> (raw)
In-Reply-To: <20260630-pks-setup-split-discovery-and-setup-v1-2-13864eb5a032@pks.im>
On 26/06/30 01:47PM, Patrick Steinhardt wrote:
> When a repository is configured to have both "core.worktree" and
> "core.bare" we emit a warning and mark the worktree configuration as
> bogus so that the next call to `setup_work_tree()` will cause us to die.
> This allows us to still use the misconfigured repository, at least as
> long as we don't try to use its worktree.
Ok.
> This condition is handled in `setup_explicit_git_dir()`. In a subsequent
> commit we'll refactor this function so that it doesn't receive a repo as
> input anymore though, and consequently we cannot set the "bogus" bit
> anymore.
Ok IIUC, `setup_explicit_git_dir()` is currently responsible for
checking if both "core.worktree" and "core.bare" are set.
> Move the logic into `apply_repository_format()` instead to prepare for
> this. While at it, fix up formatting a bit.
So `apply_repository_format()` is expected to still have the repository
info which has access to the "bogus" field.
> Note that this change requires us to also explicitly unset the value of
> "core.worktree" in case we have the "GIT_WORK_TREE" environment variable
> set. This is because the environment variable overrides the repository's
> configuration, and we don't want to warn or die in case the work tree
> has been configured explicitly regardless of whether or not "core.bare"
> is set.
Hmmm, does this mean we now just silently ignore the misconfiguration if
done via environment variable?
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> setup.c | 37 +++++++++++++++++++++----------------
> 1 file changed, 21 insertions(+), 16 deletions(-)
>
> diff --git a/setup.c b/setup.c
> index 118416e350..f54eac5e5a 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -1147,24 +1147,24 @@ static const char *setup_explicit_git_dir(struct repository *repo,
> }
>
> /* #3, #7, #11, #15, #19, #23, #27, #31 (see t1510) */
> - if (work_tree_env)
> + if (work_tree_env) {
> + /*
> + * The environment variable overrides "core.worktree". This
> + * also has the consequence that we don't want to flag cases as
> + * bogus where we have both "core.worktree" and "core.bare", so
> + * we have to exlicitly unset the configuration.
> + */
> + FREE_AND_NULL(repo_fmt->work_tree);
Ok, this confused me a bit a first, but IIUC we have to unset the
environment variable because we now defer setting the bogus flag to a
later point when `apply_repository_format()` is executed.
> set_git_work_tree(repo, work_tree_env);
> - else if (repo_fmt->is_bare > 0) {
> - if (repo_fmt->work_tree) {
> - /* #22.2, #30 */
> - warning("core.bare and core.worktree do not make sense");
> - repo->worktree_config_is_bogus = true;
> - }
> -
> + } else if (repo_fmt->is_bare > 0) {
> /* #18, #26 */
> set_git_dir(repo, gitdirenv, 0);
> free(gitfile);
> return NULL;
> - }
> - else if (repo_fmt->work_tree) { /* #6, #14 */
> - if (is_absolute_path(repo_fmt->work_tree))
> + } else if (repo_fmt->work_tree) { /* #6, #14 */
> + if (is_absolute_path(repo_fmt->work_tree)) {
> set_git_work_tree(repo, repo_fmt->work_tree);
> - else {
> + } else {
> char *core_worktree;
> if (chdir(gitdirenv))
> die_errno(_("cannot chdir to '%s'"), gitdirenv);
> @@ -1176,15 +1176,14 @@ static const char *setup_explicit_git_dir(struct repository *repo,
> set_git_work_tree(repo, core_worktree);
> free(core_worktree);
> }
> - }
> - else if (!git_env_bool(GIT_IMPLICIT_WORK_TREE_ENVIRONMENT, 1)) {
> + } else if (!git_env_bool(GIT_IMPLICIT_WORK_TREE_ENVIRONMENT, 1)) {
> /* #16d */
> set_git_dir(repo, gitdirenv, 0);
> free(gitfile);
> return NULL;
> - }
> - else /* #2, #10 */
> + } else { /* #2, #10 */
> set_git_work_tree(repo, ".");
> + }
Some random curly brace cleanup above.
>
> /* set_git_work_tree() must have been called by now */
> worktree = repo_get_work_tree(repo);
> @@ -1768,6 +1767,12 @@ int apply_repository_format(struct repository *repo,
> if (verify_repository_format(format, err) < 0)
> return -1;
>
> + if (format->is_bare > 0 && format->work_tree) {
> + /* #22.2, #30 */
> + warning("core.bare and core.worktree do not make sense");
> + repo->worktree_config_is_bogus = true;
> + }
We now perform this validation in `apply_repository_format()`. Does
deferring this check have any meaningful impact? Or is
`apply_repository_format()` always called after
`setup_explicit_git_dir()`?
-Justin
next prev parent reply other threads:[~2026-07-06 21:49 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 11:47 [PATCH 00/13] setup: split up repository discovery and setup Patrick Steinhardt
2026-06-30 11:47 ` [PATCH 01/13] setup: rename `check_repository_format_gently()` Patrick Steinhardt
2026-07-06 21:27 ` Justin Tobler
2026-06-30 11:47 ` [PATCH 02/13] setup: mark bogus worktree in `apply_repository_format()` Patrick Steinhardt
2026-06-30 18:26 ` Junio C Hamano
2026-07-01 6:23 ` Patrick Steinhardt
2026-07-06 21:49 ` Justin Tobler [this message]
2026-07-07 6:25 ` Patrick Steinhardt
2026-06-30 11:47 ` [PATCH 03/13] setup: unify setup of shallow file Patrick Steinhardt
2026-07-06 22:02 ` Justin Tobler
2026-07-07 6:25 ` Patrick Steinhardt
2026-06-30 11:47 ` [PATCH 04/13] setup: split up concerns of `setup_git_env_internal()` Patrick Steinhardt
2026-06-30 11:47 ` [PATCH 05/13] setup: introduce explicit repository discovery Patrick Steinhardt
2026-07-06 22:19 ` Justin Tobler
2026-07-07 6:25 ` Patrick Steinhardt
2026-06-30 11:47 ` [PATCH 06/13] setup: embed repository format in discovery Patrick Steinhardt
2026-06-30 11:47 ` [PATCH 07/13] setup: move prefix into repository Patrick Steinhardt
2026-07-06 22:33 ` Justin Tobler
2026-06-30 11:47 ` [PATCH 08/13] setup: drop static `cwd` variable Patrick Steinhardt
2026-06-30 11:47 ` [PATCH 09/13] setup: propagate prefix via repository discovery Patrick Steinhardt
2026-06-30 11:47 ` [PATCH 10/13] setup: make repository discovery self-contained Patrick Steinhardt
2026-06-30 11:47 ` [PATCH 11/13] setup: drop redundant configuration of `startup_info->have_repository` Patrick Steinhardt
2026-06-30 11:47 ` [PATCH 12/13] setup: pass worktree to `init_db()` Patrick Steinhardt
2026-06-30 11:47 ` [PATCH 13/13] setup: mark `set_git_work_tree()` as file-local Patrick Steinhardt
2026-07-07 7:21 ` [PATCH v2 00/13] setup: split up repository discovery and setup Patrick Steinhardt
2026-07-07 7:21 ` [PATCH v2 01/13] setup: rename `check_repository_format_gently()` Patrick Steinhardt
2026-07-07 7:21 ` [PATCH v2 02/13] setup: mark bogus worktree in `apply_repository_format()` Patrick Steinhardt
2026-07-07 7:21 ` [PATCH v2 03/13] setup: unify setup of shallow file Patrick Steinhardt
2026-07-07 7:21 ` [PATCH v2 04/13] setup: split up concerns of `setup_git_env_internal()` Patrick Steinhardt
2026-07-07 7:21 ` [PATCH v2 05/13] setup: introduce explicit repository discovery Patrick Steinhardt
2026-07-07 7:21 ` [PATCH v2 06/13] setup: embed repository format in discovery Patrick Steinhardt
2026-07-07 7:21 ` [PATCH v2 07/13] setup: move prefix into repository Patrick Steinhardt
2026-07-07 7:21 ` [PATCH v2 08/13] setup: drop static `cwd` variable Patrick Steinhardt
2026-07-07 7:21 ` [PATCH v2 09/13] setup: propagate prefix via repository discovery Patrick Steinhardt
2026-07-07 7:21 ` [PATCH v2 10/13] setup: make repository discovery self-contained Patrick Steinhardt
2026-07-07 7:21 ` [PATCH v2 11/13] setup: drop redundant configuration of `startup_info->have_repository` Patrick Steinhardt
2026-07-07 7:21 ` [PATCH v2 12/13] setup: pass worktree to `init_db()` Patrick Steinhardt
2026-07-07 7:21 ` [PATCH v2 13/13] setup: mark `set_git_work_tree()` as file-local Patrick Steinhardt
2026-07-07 15:02 ` [PATCH v2 00/13] setup: split up repository discovery and setup Justin Tobler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=akwfAmyeIVJYXj1h@denethor \
--to=jltobler@gmail.com \
--cc=git@vger.kernel.org \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.