Subject: Re: fatal: Not a valid object name HEAD

From: "Bence Ferdinandy" <[email-masked]>
Date: Sun, 12 Jan 2025 15:17:36 +0100

On Sat Jan 11, 2025 at 20:26, Christian Hesse <[email-masked]> wrote:
> Hello everybody,
>
> starting with Git 2.48.0 I see some trouble with some mirrored bare
> repositories. Try this:
>
> box ~ % git clone --mirror https://github.com/codership/galera.git
> Cloning into bare repository 'galera.git'...
> remote: Enumerating objects: 49768, done.
> remote: Counting objects: 100% (2251/2251), done.
> remote: Compressing objects: 100% (553/553), done.
> remote: Total 49768 (delta 1986), reused 1716 (delta 1698), pack-reused 47517 (from 3)
> Receiving objects: 100% (49768/49768), 25.20 MiB | 4.92 MiB/s, done.
> Resolving deltas: 100% (37386/37386), done.
> box ~ % cd galera.git 
> box ~/galera.git (git)-[4.x] % git describe 
> release_26.4.5-345-gd811a577
> box ~/galera.git (git)-[4.x] % git remote add mariadb https://github.com/MariaDB/galera.git
> box ~/galera.git (git)-[4.x] % git fetch --all
> Fetching origin
> Fetching mariadb
> remote: Enumerating objects: 638, done.
> remote: Counting objects: 100% (517/517), done.
> remote: Compressing objects: 100% (125/125), done.
> remote: Total 638 (delta 415), reused 454 (delta 392), pack-reused 121 (from 3)
> Receiving objects: 100% (638/638), 386.30 KiB | 5.08 MiB/s, done.
> Resolving deltas: 100% (440/440), completed with 105 local objects.
> From https://github.com/MariaDB/galera
>  * [new branch]        0.6 -> mariadb/0.6
> [ snipped some more branches and tags ]
> box ~/galera.git (git)-[mariadb-4.x] % git describe                                                
> fatal: Not a valid object name HEAD
>
> Guess that's not expected... Why does that happen?
>
> Possibly fallout caused by https://github.com/git/git/commit/5f212684abb66c9604e745a2296af8c4bb99961c

More specifically: https://github.com/git/git/commit/b1b713f722894d7f66e9ec64bc934ca32004d3d1

So what happened before the series is that HEAD was set on cloning to 

	ref: refs/heads/4.x 

and the adding the new remote did not change this. After the series fetching
the new remote will overwrite HEAD to 

	ref: refs/heads/mariadb-4.x 

which does not exist in the repository. Note that the older version does not
set up `refs/remotes/mariadb/HEAD` which is interesting?

I think the correct way to handle this would be to check if the remote has
`mirror=true` set, and if we're running in a bare repository we should overwrite
HEAD and if it's not a mirror we should instead set up
`refs/remotes/nonmirrorremote/HEAD`. (I think a remote can be a mirror without
the repository being bare, I'm not sure.)

I can probably send a patch late next week to fix this.

Best,
Bence