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

Re: git init BUG when gitconfig has includeIf

From
HRHeghedus Razvan <heghedus.razvan@protonmail.com>
Date
May 22, 2024, 08:21 UTC
Message-ID
<D1G108TQBWK4.2XW34J29NCAHG@protonmail.com>
In-Reply-To
<Zk2ndVx4gMTV8ZUf@tanuki>
On Wed May 22, 2024 at 11:06 AM EEST, Patrick Steinhardt wrote:
Show 51 quoted lines
> On Tue, May 21, 2024 at 04:46:23PM +0000, Heghedus Razvan wrote:
> > On Tue May 21, 2024 at 7:36 PM EEST, Junio C Hamano wrote:
> > > Heghedus Razvan <heghedus.razvan@protonmail.com> writes:
> > >
> > > > Yesterday I stumble upon a bug when doing git init. I didn't
> > > > find any references to it, so I don't know if is a known problem
> > > > or not.
> > > >
> > > > Steps to reproduce:
> > > > # git init .
> > > > BUG: refs.c:2123: reference backend is unknown
> > >
> > > Patrick, this looks similar to an earlier one during "git clone"
> > > that was discussed at
> > >
> > > https://lore.kernel.org/git/72771da0-a0ef-4fd9-8071-6467cd7b6a6b@kernel-space.org/
> > >
> > > that was fixed with 199f44cb (builtin/clone: allow remote helpers to
> > > detect repo, 2024-02-27)?  The fix was about "git clone", but the
> > > crux of the fix went to setup.c:initialize_repository_version()
> > > which is also called by setup.c:init_db() that is the workhorse of
> > > "git init", so it may already have been fixed (I didn't try).
> > 
> > I guess I forgot to mention, but I tested the current master 4365c6fcf9
> > and the issue is still present.
>
> I cannot reproduce the issue as-is, neither on Git v2.44 nor on the
> current master branch. So clearly, there must be something special to
> your setup. The following testcase and variants of it do not reproduce:
>
>     test_expect_success 'init with includeIf.onbranch condition' '
>         git config -f ./config foo.bar baz &&
>         include=$(test-tool path-utils absolute_path config) &&
>         test_when_finished "rm -rf repo" &&
>         git -c includeIf.onbranch:main.path="$(<include)" init repo
>     '
>
> Now digging into the code, the condition gets evaluated in
> `include_by_branch()`. The call to `refs_resolve_ref_unsafe()` is
> guarded by `the_repository->gitdir`, which is `NULL` the first time it
> is called by git-init(1). It does get called a second time, but at that
> point we already initialized the refdb and configured the ref storage
> format as expected.
>
> Aha! Seems like this only happens when re-initializing an already
> existent repository, that's what's missing. In that case we do already
> have `the_repository->gitdir` set even though we did not yet set up the
> ref storage format. I'll investigate and send a patch.
>
> Can you confirm that this is what you see, or do you also see this when
> creating an entirely new repository?
Hi Patrick,

Thanks for looking into this. It seems that the issue happens only when the folder for the repo exists.

Eg: $ mkdir new_folder $ cd new_folder $ git init .

or $ mkdir new_folder $ git init new_folder

But directly running `git init new_folder` when there is no `new_folder` works fine.

FYI, I just did these tests on master (4365c6fcf9).

Regards, Razvan

Show 9 quoted lines
>
> > > Even if it is already fixed in the current version by the same
> > > 199f44cb, we may want to follow up 0eab85b9 (t5601: exercise clones
> > > with "includeIf.*.onbranch", 2024-03-12) with an additional test to
> > > cover "git init".
>
> Agreed.
>
> Patrick
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 5 of 14 in “git init BUG when gitconfig has includeIf”
  1. Heghedus RazvanMay 21, 2024
  2. Junio C HamanoMay 21, 2024
  3. Heghedus RazvanMay 21, 2024
  4. Patrick SteinhardtMay 22, 2024
  5. Heghedus RazvanMay 22, 2024
  6. Patrick SteinhardtMay 22, 2024
  7. setup: fix bug with "includeIf.onbranch" when initializing dirPatrick Steinhardt, May 22, 2024
  8. Heghedus RazvanMay 22, 2024
  9. Junio C HamanoMay 22, 2024
  10. Junio C HamanoMay 23, 2024
  11. Patrick SteinhardtMay 23, 2024
  12. setup: fix bug with "includeIf.onbranch" when initializing dirJunio C Hamano, May 23, 2024
  13. [rPATCH v2] setup: fix bug with "includeIf.onbranch" when initializing dirJunio C Hamano, May 23, 2024
  14. Patrick SteinhardtMay 23, 2024

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.