All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Heghedus Razvan <heghedus.razvan@protonmail.com>
To: Patrick Steinhardt <ps@pks.im>, git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] setup: fix bug with "includeIf.onbranch" when initializing dir
Date: Wed, 22 May 2024 10:58:08 +0000	[thread overview]
Message-ID: <D1G4BWOMJD3E.2CNXHMRZQ12FW@protonmail.com> (raw)
In-Reply-To: <cf182bb9ee7d4a7eb46e5dbf4f3ef5deb198d823.1716374321.git.ps@pks.im>

On Wed May 22, 2024 at 1:38 PM EEST, Patrick Steinhardt wrote:
> It was reported that git-init(1) can fail when initializing an existing
> directory in case the config contains an "includeIf.onbranch:"
> condition:
>
> ```shell
> $ mkdir repo
> $ git -c includeIf.onbranch:main.path=nonexistent init repo
> BUG: refs.c:2056: reference backend is unknown
> ```
>
> The same error can also be triggered when re-initializing an already
> existing repository.
>
> The bug has been introduced in 173761e21b (setup: start tracking ref
> storage format, 2023-12-29), which wired up the ref storage format. The
> root cause is in `init_db()`, which tries to read the config before we
> have initialized `the_repository` and most importantly its ref storage
> format. We eventually end up calling `include_by_branch()` and execute
> `refs_resolve_ref_unsafe()`, but because we have not initialized the ref
> storage format yet this will trigger the above bug.
>
> Interestingly, `include_by_branch()` has a mechanism that will only
> cause us to resolve the ref when `the_repository->gitdir` is set. This
> is also the reason why this only happens when we initialize an already
> existing directory or repository: `gitdir` is set in those cases, but
> not when creating a new directory.
>
> Now there are two ways to address the issue:
>
>   - We can adapt `include_by_branch()` to also make the code conditional
>     on whether `the_repository->ref_storage_format` is set.
>
>   - We can shift around code such that we initialize the repository
>     format before we read the config.
>
> While the first approach would be safe, it may also cause us to paper
> over issues where a ref store should have been set up. In our case for
> example, it may be reasonable to expect that re-initializing the repo
> will cause the "onbranch:" condition to trigger, but we would not do
> that if the ref storage format was not set up yet. This also used to
> work before the above commit that introduced this bug.
>
> Rearrange the code such that we set up the repository format before
> reading the config. This fixes the bug and ensures that "onbranch:"
> conditions can trigger.
>
> Reported-by: Heghedus Razvan <heghedus.razvan@protonmail.com>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>

I can confirm it's fixing the issue. Feel free to add:

Tested-by: Heghedus Razvan <heghedus.razvan@protonmail.com>


  reply	other threads:[~2024-05-22 10:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-21  7:54 git init BUG when gitconfig has includeIf Heghedus Razvan
2024-05-21 16:36 ` Junio C Hamano
2024-05-21 16:46   ` Heghedus Razvan
2024-05-22  8:06     ` Patrick Steinhardt
2024-05-22  8:21       ` Heghedus Razvan
2024-05-22  8:27         ` Patrick Steinhardt
2024-05-22 10:38 ` [PATCH] setup: fix bug with "includeIf.onbranch" when initializing dir Patrick Steinhardt
2024-05-22 10:58   ` Heghedus Razvan [this message]
2024-05-22 19:06     ` Junio C Hamano
2024-05-23  0:41   ` Junio C Hamano
2024-05-23  5:26     ` Patrick Steinhardt
2024-05-23  0:43   ` [PATCH v2] " Junio C Hamano
2024-05-23  0:56     ` [rPATCH " Junio C Hamano
2024-05-23  5:26     ` [PATCH " Patrick Steinhardt

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=D1G4BWOMJD3E.2CNXHMRZQ12FW@protonmail.com \
    --to=heghedus.razvan@protonmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --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.