{"thread":{"id":"62790","subject":"fatal: Not a valid object name HEAD","startedAt":"2025-01-11T19:32:48Z","lastAt":"2025-01-27T20:18:59Z","messageCount":18,"participants":["Christian Hesse","Bence Ferdinandy","Junio C Hamano","Eric Sunshine","Patrick Steinhardt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"510373","messageId":"20250111202628.0e5894e4@leda.eworm.net","threadId":"62790","inReplyTo":null,"subject":"fatal: Not a valid object name HEAD","fromName":"Christian Hesse","fromEmail":"list@eworm.de","sentAt":"2025-01-11T19:26:28Z","receivedAt":"2025-01-11T19:32:48Z","isPatch":false,"sender":{"key":"list@eworm.de","avatar":"https://gravatar.com/avatar/ec9a78d63ae8bf8efdc06867449c0a3e763066c462c2c2f9f103ac4675109e14?d=mp&s=160"},"body":"Hello everybody,\n\nstarting with Git 2.48.0 I see some trouble with some mirrored bare\nrepositories. Try this:\n\nbox ~ % git clone --mirror https://github.com/codership/galera.git\nCloning into bare repository 'galera.git'...\nremote: Enumerating objects: 49768, done.\nremote: Counting objects: 100% (2251/2251), done.\nremote: Compressing objects: 100% (553/553), done.\nremote: Total 49768 (delta 1986), reused 1716 (delta 1698), pack-reused 47517 (from 3)\nReceiving objects: 100% (49768/49768), 25.20 MiB | 4.92 MiB/s, done.\nResolving deltas: 100% (37386/37386), done.\nbox ~ % cd galera.git \nbox ~/galera.git (git)-[4.x] % git describe \nrelease_26.4.5-345-gd811a577\nbox ~/galera.git (git)-[4.x] % git remote add mariadb https://github.com/MariaDB/galera.git\nbox ~/galera.git (git)-[4.x] % git fetch --all\nFetching origin\nFetching mariadb\nremote: Enumerating objects: 638, done.\nremote: Counting objects: 100% (517/517), done.\nremote: Compressing objects: 100% (125/125), done.\nremote: Total 638 (delta 415), reused 454 (delta 392), pack-reused 121 (from 3)\nReceiving objects: 100% (638/638), 386.30 KiB | 5.08 MiB/s, done.\nResolving deltas: 100% (440/440), completed with 105 local objects.\nFrom https://github.com/MariaDB/galera\n * [new branch]        0.6 -> mariadb/0.6\n[ snipped some more branches and tags ]\nbox ~/galera.git (git)-[mariadb-4.x] % git describe                                                \nfatal: Not a valid object name HEAD\n\nGuess that's not expected... Why does that happen?\n\nPossibly fallout caused by https://github.com/git/git/commit/5f212684abb66c9604e745a2296af8c4bb99961c\n-- \nmain(a){char*c=/*    Schoene Gruesse                         */\"B?IJj;MEH\"\n\"CX:;\",b;for(a/*    Best regards             my address:    */=0;b=c[a++];)\nputchar(b-1/(/*    Chris            cc -ox -xc - && ./x    */b/42*2-3)*42);}\n"},{"id":"510382","messageId":"D705QOX6EFH7.14GKFWVVUQWH7@ferdinandy.com","threadId":"62790","inReplyTo":"20250111202628.0e5894e4@leda.eworm.net","subject":"Re: fatal: Not a valid object name HEAD","fromName":"Bence Ferdinandy","fromEmail":"bence@ferdinandy.com","sentAt":"2025-01-12T14:17:36Z","receivedAt":"2025-01-12T14:18:01Z","isPatch":false,"sender":{"key":"bence@ferdinandy.com","avatar":"https://avatars.githubusercontent.com/u/6343487?v=4"},"body":"\nOn Sat Jan 11, 2025 at 20:26, Christian Hesse <list@eworm.de> wrote:\n> Hello everybody,\n>\n> starting with Git 2.48.0 I see some trouble with some mirrored bare\n> repositories. Try this:\n>\n> box ~ % git clone --mirror https://github.com/codership/galera.git\n> Cloning into bare repository 'galera.git'...\n> remote: Enumerating objects: 49768, done.\n> remote: Counting objects: 100% (2251/2251), done.\n> remote: Compressing objects: 100% (553/553), done.\n> remote: Total 49768 (delta 1986), reused 1716 (delta 1698), pack-reused 47517 (from 3)\n> Receiving objects: 100% (49768/49768), 25.20 MiB | 4.92 MiB/s, done.\n> Resolving deltas: 100% (37386/37386), done.\n> box ~ % cd galera.git \n> box ~/galera.git (git)-[4.x] % git describe \n> release_26.4.5-345-gd811a577\n> box ~/galera.git (git)-[4.x] % git remote add mariadb https://github.com/MariaDB/galera.git\n> box ~/galera.git (git)-[4.x] % git fetch --all\n> Fetching origin\n> Fetching mariadb\n> remote: Enumerating objects: 638, done.\n> remote: Counting objects: 100% (517/517), done.\n> remote: Compressing objects: 100% (125/125), done.\n> remote: Total 638 (delta 415), reused 454 (delta 392), pack-reused 121 (from 3)\n> Receiving objects: 100% (638/638), 386.30 KiB | 5.08 MiB/s, done.\n> Resolving deltas: 100% (440/440), completed with 105 local objects.\n> From https://github.com/MariaDB/galera\n>  * [new branch]        0.6 -> mariadb/0.6\n> [ snipped some more branches and tags ]\n> box ~/galera.git (git)-[mariadb-4.x] % git describe                                                \n> fatal: Not a valid object name HEAD\n>\n> Guess that's not expected... Why does that happen?\n>\n> Possibly fallout caused by https://github.com/git/git/commit/5f212684abb66c9604e745a2296af8c4bb99961c\n\nMore specifically: https://github.com/git/git/commit/b1b713f722894d7f66e9ec64bc934ca32004d3d1\n\nSo what happened before the series is that HEAD was set on cloning to \n\n\tref: refs/heads/4.x \n\nand the adding the new remote did not change this. After the series fetching\nthe new remote will overwrite HEAD to \n\n\tref: refs/heads/mariadb-4.x \n\nwhich does not exist in the repository. Note that the older version does not\nset up `refs/remotes/mariadb/HEAD` which is interesting?\n\nI think the correct way to handle this would be to check if the remote has\n`mirror=true` set, and if we're running in a bare repository we should overwrite\nHEAD and if it's not a mirror we should instead set up\n`refs/remotes/nonmirrorremote/HEAD`. (I think a remote can be a mirror without\nthe repository being bare, I'm not sure.)\n\nI can probably send a patch late next week to fix this.\n\nBest,\nBence\n"},{"id":"510383","messageId":"20250112165125.130400-1-bence@ferdinandy.com","threadId":"62790","inReplyTo":"20250111202628.0e5894e4@leda.eworm.net","subject":"[PATCH] fetch set_head: fix non-mirror remotes in bare repositories","fromName":"Bence Ferdinandy","fromEmail":"bence@ferdinandy.com","sentAt":"2025-01-12T16:51:22Z","receivedAt":"2025-01-12T16:51:54Z","isPatch":true,"sender":{"key":"bence@ferdinandy.com","avatar":"https://avatars.githubusercontent.com/u/6343487?v=4"},"body":"In b1b713f722 (fetch set_head: handle mirrored bare repositories,\n2024-11-22) it was implicitly assumed that all remotes will be mirrors\nin a bare repository, thus fetching a non-mirrored remote could lead to\nHEAD pointing to a non-existent reference. Make sure we only overwrite\nHEAD if we are in a bare repository and fetching from a mirror.\nOtherwise, proceed as normally, and create\nrefs/remotes/<nonmirrorremote>/HEAD instead.\n\nSigned-off-by: Bence Ferdinandy <bence@ferdinandy.com>\nReported-by: Christian Hesse <list@eworm.de>\n---\n builtin/fetch.c   | 15 ++++++++-------\n t/t5505-remote.sh | 10 ++++++++++\n t/t5510-fetch.sh  | 13 +++++++++++++\n 3 files changed, 31 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex fe2b26c74a..625d45be8b 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -1618,9 +1618,9 @@ static void report_set_head(const char *remote, const char *head_name,\n }\n \n static int set_head(const struct ref *remote_refs, int follow_remote_head,\n-\t\tconst char *no_warn_branch)\n+\t\tconst char *no_warn_branch, int mirror)\n {\n-\tint result = 0, create_only, is_bare, was_detached;\n+\tint result = 0, create_only, baremirror, was_detached;\n \tstruct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,\n \t\t      b_local_head = STRBUF_INIT;\n \tconst char *remote = gtransport->remote->name;\n@@ -1655,9 +1655,9 @@ static int set_head(const struct ref *remote_refs, int follow_remote_head,\n \n \tif (!head_name)\n \t\tgoto cleanup;\n-\tis_bare = is_bare_repository();\n-\tcreate_only = follow_remote_head == FOLLOW_REMOTE_ALWAYS ? 0 : !is_bare;\n-\tif (is_bare) {\n+\tbaremirror = is_bare_repository() && mirror;\n+\tcreate_only = follow_remote_head == FOLLOW_REMOTE_ALWAYS ? 0 : !baremirror;\n+\tif (baremirror) {\n \t\tstrbuf_addstr(&b_head, \"HEAD\");\n \t\tstrbuf_addf(&b_remote_head, \"refs/heads/%s\", head_name);\n \t} else {\n@@ -1665,7 +1665,7 @@ static int set_head(const struct ref *remote_refs, int follow_remote_head,\n \t\tstrbuf_addf(&b_remote_head, \"refs/remotes/%s/%s\", remote, head_name);\n \t}\n \t\t/* make sure it's valid */\n-\tif (!is_bare && !refs_ref_exists(refs, b_remote_head.buf)) {\n+\tif (!baremirror && !refs_ref_exists(refs, b_remote_head.buf)) {\n \t\tresult = 1;\n \t\tgoto cleanup;\n \t}\n@@ -1925,7 +1925,8 @@ static int do_fetch(struct transport *transport,\n \t\t}\n \t}\n \tif (set_head(remote_refs, transport->remote->follow_remote_head,\n-\t\ttransport->remote->no_warn_branch))\n+\t\ttransport->remote->no_warn_branch,\n+\t\ttransport->remote->mirror))\n \t\t;\n \t\t/*\n \t\t * Way too many cases where this can go wrong\ndiff --git a/t/t5505-remote.sh b/t/t5505-remote.sh\nindex 519f7973e3..c75cfe968f 100755\n--- a/t/t5505-remote.sh\n+++ b/t/t5505-remote.sh\n@@ -589,6 +589,16 @@ test_expect_success 'add --mirror setting HEAD' '\n \t)\n '\n \n+test_expect_success 'non-mirror fetch does not interfere with mirror' '\n+\tmkdir headnotmain &&\n+\t(\n+\t\tcd headnotmain &&\n+\t\tgit init --bare -b notmain &&\n+\t\tgit remote add -f other ../two &&\n+\t\ttest \"$(git symbolic-ref HEAD)\" = \"refs/heads/notmain\"\n+\t)\n+'\n+\n test_expect_success 'add --mirror=fetch' '\n \tmkdir mirror-fetch &&\n \tgit init -b main mirror-fetch/parent &&\ndiff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh\nindex 2d9587059f..cfa63ae086 100755\n--- a/t/t5510-fetch.sh\n+++ b/t/t5510-fetch.sh\n@@ -84,6 +84,19 @@ test_expect_success \"fetch test remote HEAD\" '\n \tbranch=$(git rev-parse refs/remotes/origin/main) &&\n \ttest \"z$head\" = \"z$branch\"'\n \n+test_expect_success \"fetch test remote HEAD in bare repository\" '\n+\tcd \"$D\" &&\n+\tgit init --bare barerepo &&\n+\tcd barerepo &&\n+\tgit remote add upstream ../two &&\n+\tgit fetch upstream &&\n+\tgit rev-parse --verify refs/remotes/upstream/HEAD &&\n+\tgit rev-parse --verify refs/remotes/upstream/main &&\n+\thead=$(git rev-parse refs/remotes/upstream/HEAD) &&\n+\tbranch=$(git rev-parse refs/remotes/upstream/main) &&\n+\ttest \"z$head\" = \"z$branch\"'\n+\n+\n test_expect_success \"fetch test remote HEAD change\" '\n \tcd \"$D\" &&\n \tcd two &&\n\nbase-commit: fbe8d3079d4a96aeb4e4529cc93cc0043b759a05\n-- \n2.48.0.1.g32c193c8ca\n\n"},{"id":"510427","messageId":"xmqq5xmibrs6.fsf@gitster.g","threadId":"62790","inReplyTo":"D705QOX6EFH7.14GKFWVVUQWH7@ferdinandy.com","subject":"Re: fatal: Not a valid object name HEAD","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-01-13T16:30:17Z","receivedAt":"2025-01-13T16:30:20Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Bence Ferdinandy\" <bence@ferdinandy.com> writes:\n\n> I think the correct way to handle this would be to check if the remote has\n> `mirror=true` set, and if we're running in a bare repository we should overwrite\n> HEAD and if it's not a mirror we should instead set up\n> `refs/remotes/nonmirrorremote/HEAD`. (I think a remote can be a mirror without\n> the repository being bare, I'm not sure.)\n\nA non-bare repository can technically be a mirror but such a thing\nis only useful when (1) it never fetches from anywhere afterwards,\n(2) it stays on a branch that never changes by convention, or (3) it\nstays on a detached HEAD.  Otherwise \"git fetch\" in it would almost\nalways fail.\n\nPractically (1) and (2) are not all that useful---such a static\ncheckout does not even have to be a Git repository but a tarball\nextract.  If you overwrite HEAD upon fetch, you will render the last\nremaining useful usage, (3), also useless.\n\nThanks.\n\n"},{"id":"511132","messageId":"xmqqr04tqm86.fsf@gitster.g","threadId":"62790","inReplyTo":"20250112165125.130400-1-bence@ferdinandy.com","subject":"Re: [PATCH] fetch set_head: fix non-mirror remotes in bare repositories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-01-23T21:00:41Z","receivedAt":"2025-01-23T21:00:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Bence Ferdinandy <bence@ferdinandy.com> writes:\n\n> In b1b713f722 (fetch set_head: handle mirrored bare repositories,\n> 2024-11-22) it was implicitly assumed that all remotes will be mirrors\n> in a bare repository, thus fetching a non-mirrored remote could lead to\n> HEAD pointing to a non-existent reference. Make sure we only overwrite\n> HEAD if we are in a bare repository and fetching from a mirror.\n> Otherwise, proceed as normally, and create\n> refs/remotes/<nonmirrorremote>/HEAD instead.\n>\n> Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>\n> Reported-by: Christian Hesse <list@eworm.de>\n\nThese should be chronological; somebody reports an issue, the patch\ngets written, and finally it is sent out with a Sign-off to certify\nthat the patch is not a stolen property.\n\n> ---\n>  builtin/fetch.c   | 15 ++++++++-------\n>  t/t5505-remote.sh | 10 ++++++++++\n>  t/t5510-fetch.sh  | 13 +++++++++++++\n>  3 files changed, 31 insertions(+), 7 deletions(-)\n\nWe haven't heard from Chritian; has this been tested OK?\n\nWhat the patch does does look sensible.  Thanks.\n"},{"id":"511134","messageId":"D79S38LX7NLS.34MN1BWV0HVJ0@ferdinandy.com","threadId":"62790","inReplyTo":"xmqqr04tqm86.fsf@gitster.g","subject":"Re: [PATCH] fetch set_head: fix non-mirror remotes in bare repositories","fromName":"Bence Ferdinandy","fromEmail":"bence@ferdinandy.com","sentAt":"2025-01-23T21:42:23Z","receivedAt":"2025-01-23T21:48:05Z","isPatch":true,"sender":{"key":"bence@ferdinandy.com","avatar":"https://avatars.githubusercontent.com/u/6343487?v=4"},"body":"\nOn Thu Jan 23, 2025 at 22:00, Junio C Hamano <gitster@pobox.com> wrote:\n> Bence Ferdinandy <bence@ferdinandy.com> writes:\n>\n>> In b1b713f722 (fetch set_head: handle mirrored bare repositories,\n>> 2024-11-22) it was implicitly assumed that all remotes will be mirrors\n>> in a bare repository, thus fetching a non-mirrored remote could lead to\n>> HEAD pointing to a non-existent reference. Make sure we only overwrite\n>> HEAD if we are in a bare repository and fetching from a mirror.\n>> Otherwise, proceed as normally, and create\n>> refs/remotes/<nonmirrorremote>/HEAD instead.\n>>\n>> Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>\n>> Reported-by: Christian Hesse <list@eworm.de>\n>\n> These should be chronological; somebody reports an issue, the patch\n> gets written, and finally it is sent out with a Sign-off to certify\n> that the patch is not a stolen property.\n\nMakes sense, I'll send a v2 in that case.\n\n>\n>> ---\n>>  builtin/fetch.c   | 15 ++++++++-------\n>>  t/t5505-remote.sh | 10 ++++++++++\n>>  t/t5510-fetch.sh  | 13 +++++++++++++\n>>  3 files changed, 31 insertions(+), 7 deletions(-)\n>\n> We haven't heard from Chritian; has this been tested OK?\n\nTo the extent of the tests I've added, but I'm not aware of anybody else,\nespecially Christian trying it out.\n\n>\n> What the patch does does look sensible.  Thanks.\n\nThanks,\nBence\n"},{"id":"511135","messageId":"CAPig+cTmtuL1NtFjJLDb-bXDk=h5s88v12ezywr3q35+Zcrqnw@mail.gmail.com","threadId":"62790","inReplyTo":"D79S38LX7NLS.34MN1BWV0HVJ0@ferdinandy.com","subject":"Re: [PATCH] fetch set_head: fix non-mirror remotes in bare repositories","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2025-01-23T22:00:47Z","receivedAt":"2025-01-23T22:00:59Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Jan 23, 2025 at 4:48 PM Bence Ferdinandy <bence@ferdinandy.com> wrote:\n> On Thu Jan 23, 2025 at 22:00, Junio C Hamano <gitster@pobox.com> wrote:\n> > Bence Ferdinandy <bence@ferdinandy.com> writes:\n> >> Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>\n> >> Reported-by: Christian Hesse <list@eworm.de>\n> >\n> > These should be chronological; somebody reports an issue, the patch\n> > gets written, and finally it is sent out with a Sign-off to certify\n> > that the patch is not a stolen property.\n>\n> Makes sense, I'll send a v2 in that case.\n\nIt's a good idea to check whether Junio has himself fixed this sort of\nthing when queuing your patch. (In this case, it appears that he has.)\n"},{"id":"511140","messageId":"Z5Mrk02wMdABtrVZ@pks.im","threadId":"62790","inReplyTo":"20250112165125.130400-1-bence@ferdinandy.com","subject":"Re: [PATCH] fetch set_head: fix non-mirror remotes in bare repositories","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-01-24T05:56:35Z","receivedAt":"2025-01-24T05:56:40Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Sun, Jan 12, 2025 at 05:51:22PM +0100, Bence Ferdinandy wrote:\n> diff --git a/builtin/fetch.c b/builtin/fetch.c\n> index fe2b26c74a..625d45be8b 100644\n> --- a/builtin/fetch.c\n> +++ b/builtin/fetch.c\n> @@ -1925,7 +1925,8 @@ static int do_fetch(struct transport *transport,\n>  \t\t}\n>  \t}\n>  \tif (set_head(remote_refs, transport->remote->follow_remote_head,\n> -\t\ttransport->remote->no_warn_branch))\n> +\t\ttransport->remote->no_warn_branch,\n> +\t\ttransport->remote->mirror))\n>  \t\t;\n>  \t\t/*\n>  \t\t * Way too many cases where this can go wrong\n\nNit: At this point it might be sensible to simply pass in the remote\nitself, which would allow for an easier callsite and less risk of\ngetting the order of parameters wrong.\n\n> diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh\n> index 519f7973e3..c75cfe968f 100755\n> --- a/t/t5505-remote.sh\n> +++ b/t/t5505-remote.sh\n> @@ -589,6 +589,16 @@ test_expect_success 'add --mirror setting HEAD' '\n>  \t)\n>  '\n>  \n> +test_expect_success 'non-mirror fetch does not interfere with mirror' '\n> +\tmkdir headnotmain &&\n\nNit: this can be simplified into `git init --bare -b notmain\nheadnotmain` so that you don't have to create an empty directory first.\nAlso, do we want to `test_when_finished rm -rf headnotmain` to clean up\nafter ourselves?\n\n> +\t(\n> +\t\tcd headnotmain &&\n> +\t\tgit init --bare -b notmain &&\n> +\t\tgit remote add -f other ../two &&\n> +\t\ttest \"$(git symbolic-ref HEAD)\" = \"refs/heads/notmain\"\n> +\t)\n> +'\n> +\n>  test_expect_success 'add --mirror=fetch' '\n>  \tmkdir mirror-fetch &&\n>  \tgit init -b main mirror-fetch/parent &&\n> diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh\n> index 2d9587059f..cfa63ae086 100755\n> --- a/t/t5510-fetch.sh\n> +++ b/t/t5510-fetch.sh\n> @@ -84,6 +84,19 @@ test_expect_success \"fetch test remote HEAD\" '\n>  \tbranch=$(git rev-parse refs/remotes/origin/main) &&\n>  \ttest \"z$head\" = \"z$branch\"'\n>  \n> +test_expect_success \"fetch test remote HEAD in bare repository\" '\n> +\tcd \"$D\" &&\n> +\tgit init --bare barerepo &&\n> +\tcd barerepo &&\n\nThe `cd` needs to happen in a subshell. ALso, the same comment here\nregarding whether we want to have `test_when_finished` to clean up\nstate.\n\n> +\tgit remote add upstream ../two &&\n> +\tgit fetch upstream &&\n> +\tgit rev-parse --verify refs/remotes/upstream/HEAD &&\n> +\tgit rev-parse --verify refs/remotes/upstream/main &&\n> +\thead=$(git rev-parse refs/remotes/upstream/HEAD) &&\n> +\tbranch=$(git rev-parse refs/remotes/upstream/main) &&\n> +\ttest \"z$head\" = \"z$branch\"'\n\nThe closing single-quote should be on its own line.\n\nI see though that you simply follow existing code style, both for the\ncall to cd(1) and for the single-quote, so these are fine. This test\nfile could use a makeover, but that is obviously outside of the scope of\nthis patch series.\n\nPatrick\n"},{"id":"511153","messageId":"CAPig+cTE4ELybkuemQu_FT5BzqaKnVPYYA3dUOA64b7E_v=6PA@mail.gmail.com","threadId":"62790","inReplyTo":"Z5Mrk02wMdABtrVZ@pks.im","subject":"Re: [PATCH] fetch set_head: fix non-mirror remotes in bare repositories","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2025-01-24T10:30:54Z","receivedAt":"2025-01-24T10:31:06Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, Jan 24, 2025 at 12:56 AM Patrick Steinhardt <ps@pks.im> wrote:\n> On Sun, Jan 12, 2025 at 05:51:22PM +0100, Bence Ferdinandy wrote:\n> > +test_expect_success \"fetch test remote HEAD in bare repository\" '\n> > +     cd \"$D\" &&\n> > +     git init --bare barerepo &&\n> > +     cd barerepo &&\n>\n> The `cd` needs to happen in a subshell. ALso, the same comment here\n> regarding whether we want to have `test_when_finished` to clean up\n> state.\n\nBy way of explanation regarding `cd` in a subshell, see [*].\n\n[*]: https://lore.kernel.org/git/CAPig+cRsAPp1APNJ7W337UNtunETr+Lnn-RcGrAXEFUhN1APyA@mail.gmail.com/\n"},{"id":"511165","messageId":"20250124150745.105593ea@leda.eworm.net","threadId":"62790","inReplyTo":"xmqqr04tqm86.fsf@gitster.g","subject":"Re: [PATCH] fetch set_head: fix non-mirror remotes in bare repositories","fromName":"Christian Hesse","fromEmail":"list@eworm.de","sentAt":"2025-01-24T14:07:45Z","receivedAt":"2025-01-24T14:18:01Z","isPatch":true,"sender":{"key":"list@eworm.de","avatar":"https://gravatar.com/avatar/ec9a78d63ae8bf8efdc06867449c0a3e763066c462c2c2f9f103ac4675109e14?d=mp&s=160"},"body":"Junio C Hamano <gitster@pobox.com> on Thu, 2025/01/23 13:00:\n> Bence Ferdinandy <bence@ferdinandy.com> writes:\n> \n> > In b1b713f722 (fetch set_head: handle mirrored bare repositories,\n> > 2024-11-22) it was implicitly assumed that all remotes will be mirrors\n> > in a bare repository, thus fetching a non-mirrored remote could lead to\n> > HEAD pointing to a non-existent reference. Make sure we only overwrite\n> > HEAD if we are in a bare repository and fetching from a mirror.\n> > Otherwise, proceed as normally, and create\n> > refs/remotes/<nonmirrorremote>/HEAD instead.\n> >\n> > Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>\n> > Reported-by: Christian Hesse <list@eworm.de>  \n> \n> These should be chronological; somebody reports an issue, the patch\n> gets written, and finally it is sent out with a Sign-off to certify\n> that the patch is not a stolen property.\n> \n> > ---\n> >  builtin/fetch.c   | 15 ++++++++-------\n> >  t/t5505-remote.sh | 10 ++++++++++\n> >  t/t5510-fetch.sh  | 13 +++++++++++++\n> >  3 files changed, 31 insertions(+), 7 deletions(-)  \n> \n> We haven't heard from Chritian; has this been tested OK?\n\nSorry for the late reply...\n\nYes, with this patch applied git behaves as expected for me.\nThanks a lot!\n\n> What the patch does does look sensible.  Thanks.\n-- \nmain(a){char*c=/*    Schoene Gruesse                         */\"B?IJj;MEH\"\n\"CX:;\",b;for(a/*    Best regards             my address:    */=0;b=c[a++];)\nputchar(b-1/(/*    Chris            cc -ox -xc - && ./x    */b/42*2-3)*42);}\n"},{"id":"511173","messageId":"xmqqldv0p559.fsf@gitster.g","threadId":"62790","inReplyTo":"Z5Mrk02wMdABtrVZ@pks.im","subject":"Re: [PATCH] fetch set_head: fix non-mirror remotes in bare repositories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-01-24T16:07:14Z","receivedAt":"2025-01-24T16:07:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n>> diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh\n>> index 2d9587059f..cfa63ae086 100755\n>> --- a/t/t5510-fetch.sh\n>> +++ b/t/t5510-fetch.sh\n>> @@ -84,6 +84,19 @@ test_expect_success \"fetch test remote HEAD\" '\n>>  \tbranch=$(git rev-parse refs/remotes/origin/main) &&\n>>  \ttest \"z$head\" = \"z$branch\"'\n>>  \n>> +test_expect_success \"fetch test remote HEAD in bare repository\" '\n>> +\tcd \"$D\" &&\n>> +\tgit init --bare barerepo &&\n>> +\tcd barerepo &&\n>\n> The `cd` needs to happen in a subshell. ALso, the same comment here\n> regarding whether we want to have `test_when_finished` to clean up\n> state.\n\nYes, indeed.  The change to another script we saw earlier followed\nthe \"chdir around only in a subshell\" pattern.\n\n> I see though that you simply follow existing code style, both for the\n> call to cd(1) and for the single-quote, so these are fine. This test\n> file could use a makeover, but that is obviously outside of the scope of\n> this patch series.\n\nTerminating quote can stay, but chdir is a correctness issue that\nmay want to be addressed minimally (i.e. not making things worse,\nwhile leaving it for later to clean up the existing ones).\n\nThanks.\n"},{"id":"511179","messageId":"xmqq5xm4168a.fsf@gitster.g","threadId":"62790","inReplyTo":"20250124150745.105593ea@leda.eworm.net","subject":"Re: [PATCH] fetch set_head: fix non-mirror remotes in bare repositories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-01-24T17:17:41Z","receivedAt":"2025-01-24T17:17:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Hesse <list@eworm.de> writes:\n\n>> > ---\n>> >  builtin/fetch.c   | 15 ++++++++-------\n>> >  t/t5505-remote.sh | 10 ++++++++++\n>> >  t/t5510-fetch.sh  | 13 +++++++++++++\n>> >  3 files changed, 31 insertions(+), 7 deletions(-)  \n>> \n>> We haven't heard from Chritian; has this been tested OK?\n>\n> Sorry for the late reply...\n>\n> Yes, with this patch applied git behaves as expected for me.\n> Thanks a lot!\n\nThanks.\n\n"},{"id":"511212","messageId":"D7CCD8S1TP43.3HNQHI22K9WF9@ferdinandy.com","threadId":"62790","inReplyTo":"Z5Mrk02wMdABtrVZ@pks.im","subject":"Re: [PATCH] fetch set_head: fix non-mirror remotes in bare repositories","fromName":"Bence Ferdinandy","fromEmail":"bence@ferdinandy.com","sentAt":"2025-01-26T22:01:09Z","receivedAt":"2025-01-26T22:01:48Z","isPatch":true,"sender":{"key":"bence@ferdinandy.com","avatar":"https://avatars.githubusercontent.com/u/6343487?v=4"},"body":"\nOn Fri Jan 24, 2025 at 06:56, Patrick Steinhardt <ps@pks.im> wrote:\n> On Sun, Jan 12, 2025 at 05:51:22PM +0100, Bence Ferdinandy wrote:\n>> diff --git a/builtin/fetch.c b/builtin/fetch.c\n>> index fe2b26c74a..625d45be8b 100644\n>> --- a/builtin/fetch.c\n>> +++ b/builtin/fetch.c\n>> @@ -1925,7 +1925,8 @@ static int do_fetch(struct transport *transport,\n>>  \t\t}\n>>  \t}\n>>  \tif (set_head(remote_refs, transport->remote->follow_remote_head,\n>> -\t\ttransport->remote->no_warn_branch))\n>> +\t\ttransport->remote->no_warn_branch,\n>> +\t\ttransport->remote->mirror))\n>>  \t\t;\n>>  \t\t/*\n>>  \t\t * Way too many cases where this can go wrong\n>\n> Nit: At this point it might be sensible to simply pass in the remote\n> itself, which would allow for an easier callsite and less risk of\n> getting the order of parameters wrong.\n\nThanks, that's a really good point, not to mention inside set_head gtransport\nis used to also access remote, which seems a bit of an oversight.\n\n>\n>> diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh\n>> index 519f7973e3..c75cfe968f 100755\n>> --- a/t/t5505-remote.sh\n>> +++ b/t/t5505-remote.sh\n>> @@ -589,6 +589,16 @@ test_expect_success 'add --mirror setting HEAD' '\n>>  \t)\n>>  '\n>>  \n>> +test_expect_success 'non-mirror fetch does not interfere with mirror' '\n>> +\tmkdir headnotmain &&\n>\n> Nit: this can be simplified into `git init --bare -b notmain\n> headnotmain` so that you don't have to create an empty directory first.\n> Also, do we want to `test_when_finished rm -rf headnotmain` to clean up\n> after ourselves?\n>\n>> +\t(\n>> +\t\tcd headnotmain &&\n>> +\t\tgit init --bare -b notmain &&\n>> +\t\tgit remote add -f other ../two &&\n>> +\t\ttest \"$(git symbolic-ref HEAD)\" = \"refs/heads/notmain\"\n>> +\t)\n>> +'\n>> +\n>>  test_expect_success 'add --mirror=fetch' '\n>>  \tmkdir mirror-fetch &&\n>>  \tgit init -b main mirror-fetch/parent &&\n>> diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh\n>> index 2d9587059f..cfa63ae086 100755\n>> --- a/t/t5510-fetch.sh\n>> +++ b/t/t5510-fetch.sh\n>> @@ -84,6 +84,19 @@ test_expect_success \"fetch test remote HEAD\" '\n>>  \tbranch=$(git rev-parse refs/remotes/origin/main) &&\n>>  \ttest \"z$head\" = \"z$branch\"'\n>>  \n>> +test_expect_success \"fetch test remote HEAD in bare repository\" '\n>> +\tcd \"$D\" &&\n>> +\tgit init --bare barerepo &&\n>> +\tcd barerepo &&\n>\n> The `cd` needs to happen in a subshell. ALso, the same comment here\n> regarding whether we want to have `test_when_finished` to clean up\n> state.\n>\n>> +\tgit remote add upstream ../two &&\n>> +\tgit fetch upstream &&\n>> +\tgit rev-parse --verify refs/remotes/upstream/HEAD &&\n>> +\tgit rev-parse --verify refs/remotes/upstream/main &&\n>> +\thead=$(git rev-parse refs/remotes/upstream/HEAD) &&\n>> +\tbranch=$(git rev-parse refs/remotes/upstream/main) &&\n>> +\ttest \"z$head\" = \"z$branch\"'\n>\n> The closing single-quote should be on its own line.\n>\n> I see though that you simply follow existing code style, both for the\n> call to cd(1) and for the single-quote, so these are fine. This test\n> file could use a makeover, but that is obviously outside of the scope of\n> this patch series.\n>\n> Patrick\n\n\n\n\n-- \nbence.ferdinandy.com\n\n"},{"id":"511213","messageId":"20250126220403.289742-2-bence@ferdinandy.com","threadId":"62790","inReplyTo":"20250126220403.289742-1-bence@ferdinandy.com","subject":"[PATCH v2 2/2] fetch set_head: fix non-mirror remotes in bare repositories","fromName":"Bence Ferdinandy","fromEmail":"bence@ferdinandy.com","sentAt":"2025-01-26T22:02:11Z","receivedAt":"2025-01-26T22:04:34Z","isPatch":true,"sender":{"key":"bence@ferdinandy.com","avatar":"https://avatars.githubusercontent.com/u/6343487?v=4"},"body":"In b1b713f722 (fetch set_head: handle mirrored bare repositories,\n2024-11-22) it was implicitly assumed that all remotes will be mirrors\nin a bare repository, thus fetching a non-mirrored remote could lead to\nHEAD pointing to a non-existent reference. Make sure we only overwrite\nHEAD if we are in a bare repository and fetching from a mirror.\nOtherwise, proceed as normally, and create\nrefs/remotes/<nonmirrorremote>/HEAD instead.\n\nReported-by: Christian Hesse <list@eworm.de>\nSigned-off-by: Bence Ferdinandy <bence@ferdinandy.com>\n---\n\nNotes:\n    v2: - fixed too many parameters to set_head\n        - cleaned up the style of tests\n\n builtin/fetch.c   | 10 +++++-----\n t/t5505-remote.sh | 10 ++++++++++\n t/t5510-fetch.sh  | 17 +++++++++++++++++\n 3 files changed, 32 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 3167b055d1..1c740d5aac 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -1619,7 +1619,7 @@ static void report_set_head(const char *remote, const char *head_name,\n \n static int set_head(const struct ref *remote_refs, struct remote *remote)\n {\n-\tint result = 0, create_only, is_bare, was_detached;\n+\tint result = 0, create_only, baremirror, was_detached;\n \tstruct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,\n \t\t      b_local_head = STRBUF_INIT;\n \tint follow_remote_head = remote->follow_remote_head;\n@@ -1655,9 +1655,9 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)\n \n \tif (!head_name)\n \t\tgoto cleanup;\n-\tis_bare = is_bare_repository();\n-\tcreate_only = follow_remote_head == FOLLOW_REMOTE_ALWAYS ? 0 : !is_bare;\n-\tif (is_bare) {\n+\tbaremirror = is_bare_repository() && remote->mirror;\n+\tcreate_only = follow_remote_head == FOLLOW_REMOTE_ALWAYS ? 0 : !baremirror;\n+\tif (baremirror) {\n \t\tstrbuf_addstr(&b_head, \"HEAD\");\n \t\tstrbuf_addf(&b_remote_head, \"refs/heads/%s\", head_name);\n \t} else {\n@@ -1665,7 +1665,7 @@ static int set_head(const struct ref *remote_refs, struct remote *remote)\n \t\tstrbuf_addf(&b_remote_head, \"refs/remotes/%s/%s\", remote->name, head_name);\n \t}\n \t\t/* make sure it's valid */\n-\tif (!is_bare && !refs_ref_exists(refs, b_remote_head.buf)) {\n+\tif (!baremirror && !refs_ref_exists(refs, b_remote_head.buf)) {\n \t\tresult = 1;\n \t\tgoto cleanup;\n \t}\ndiff --git a/t/t5505-remote.sh b/t/t5505-remote.sh\nindex 519f7973e3..66e373f71d 100755\n--- a/t/t5505-remote.sh\n+++ b/t/t5505-remote.sh\n@@ -589,6 +589,16 @@ test_expect_success 'add --mirror setting HEAD' '\n \t)\n '\n \n+test_expect_success 'non-mirror fetch does not interfere with mirror' '\n+\ttest_when_finished rm -rf headnotmain &&\n+\t(\n+\t\tgit init --bare -b notmain headnotmain &&\n+\t\tcd headnotmain &&\n+\t\tgit remote add -f other ../two &&\n+\t\ttest \"$(git symbolic-ref HEAD)\" = \"refs/heads/notmain\"\n+\t)\n+'\n+\n test_expect_success 'add --mirror=fetch' '\n \tmkdir mirror-fetch &&\n \tgit init -b main mirror-fetch/parent &&\ndiff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh\nindex 2d9587059f..c9d7b46c87 100755\n--- a/t/t5510-fetch.sh\n+++ b/t/t5510-fetch.sh\n@@ -84,6 +84,23 @@ test_expect_success \"fetch test remote HEAD\" '\n \tbranch=$(git rev-parse refs/remotes/origin/main) &&\n \ttest \"z$head\" = \"z$branch\"'\n \n+test_expect_success \"fetch test remote HEAD in bare repository\" '\n+\ttest_when_finished rm -rf barerepo &&\n+\t(\n+\t\tcd \"$D\" &&\n+\t\tgit init --bare barerepo &&\n+\t\tcd barerepo &&\n+\t\tgit remote add upstream ../two &&\n+\t\tgit fetch upstream &&\n+\t\tgit rev-parse --verify refs/remotes/upstream/HEAD &&\n+\t\tgit rev-parse --verify refs/remotes/upstream/main &&\n+\t\thead=$(git rev-parse refs/remotes/upstream/HEAD) &&\n+\t\tbranch=$(git rev-parse refs/remotes/upstream/main) &&\n+\t\ttest \"z$head\" = \"z$branch\"\n+\t)\n+'\n+\n+\n test_expect_success \"fetch test remote HEAD change\" '\n \tcd \"$D\" &&\n \tcd two &&\n-- \n2.48.1.93.g276f59c085\n\n"},{"id":"511214","messageId":"D7CCDAZ9CWQ9.28LRY70X1JBAZ@ferdinandy.com","threadId":"62790","inReplyTo":"xmqqldv0p559.fsf@gitster.g","subject":"Re: [PATCH] fetch set_head: fix non-mirror remotes in bare repositories","fromName":"Bence Ferdinandy","fromEmail":"bence@ferdinandy.com","sentAt":"2025-01-26T22:01:14Z","receivedAt":"2025-01-26T22:06:51Z","isPatch":true,"sender":{"key":"bence@ferdinandy.com","avatar":"https://avatars.githubusercontent.com/u/6343487?v=4"},"body":"\nOn Fri Jan 24, 2025 at 17:07, Junio C Hamano <gitster@pobox.com> wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\n>\n>>> diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh\n>>> index 2d9587059f..cfa63ae086 100755\n>>> --- a/t/t5510-fetch.sh\n>>> +++ b/t/t5510-fetch.sh\n>>> @@ -84,6 +84,19 @@ test_expect_success \"fetch test remote HEAD\" '\n>>>  \tbranch=$(git rev-parse refs/remotes/origin/main) &&\n>>>  \ttest \"z$head\" = \"z$branch\"'\n>>>  \n>>> +test_expect_success \"fetch test remote HEAD in bare repository\" '\n>>> +\tcd \"$D\" &&\n>>> +\tgit init --bare barerepo &&\n>>> +\tcd barerepo &&\n>>\n>> The `cd` needs to happen in a subshell. ALso, the same comment here\n>> regarding whether we want to have `test_when_finished` to clean up\n>> state.\n>\n> Yes, indeed.  The change to another script we saw earlier followed\n> the \"chdir around only in a subshell\" pattern.\n>\n>> I see though that you simply follow existing code style, both for the\n>> call to cd(1) and for the single-quote, so these are fine. This test\n>> file could use a makeover, but that is obviously outside of the scope of\n>> this patch series.\n>\n> Terminating quote can stay, but chdir is a correctness issue that\n> may want to be addressed minimally (i.e. not making things worse,\n> while leaving it for later to clean up the existing ones).\n\nI'll be sending the fix with also the terminating quote fixed as well. Actually\ntests after this which I added for followremotehead followed the correct style\nso why not here as well ...\n\n5505 remote also has some style issues that came up before so if I find some\ntime I'll probably send a patches cleaning the up both.\n\n>\n> Thanks.\n\n\n\n\n-- \nbence.ferdinandy.com\n\n"},{"id":"511215","messageId":"20250126220403.289742-1-bence@ferdinandy.com","threadId":"62790","inReplyTo":"Z5Mrk02wMdABtrVZ@pks.im","subject":"[PATCH v2 1/2] fetch set_head: refactor to use remote directly","fromName":"Bence Ferdinandy","fromEmail":"bence@ferdinandy.com","sentAt":"2025-01-26T22:02:10Z","receivedAt":"2025-01-26T22:09:39Z","isPatch":true,"sender":{"key":"bence@ferdinandy.com","avatar":"https://avatars.githubusercontent.com/u/6343487?v=4"},"body":"As a preparatory step to use even more properties from the remote\nstruct, refactor set_head to take the entire struct as a parameter,\ninstead of the necessary bits. This also allows consolidating the use of\ngtransport->remote in set_head, making the access of the remote's\nproperties consistent in the function.\n\nSigned-off-by: Bence Ferdinandy <bence@ferdinandy.com>\n---\n\nNotes:\n    v2: - new patch\n\n builtin/fetch.c | 15 +++++++--------\n 1 file changed, 7 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex fe2b26c74a..3167b055d1 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -1617,13 +1617,13 @@ static void report_set_head(const char *remote, const char *head_name,\n \tstrbuf_release(&buf_prefix);\n }\n \n-static int set_head(const struct ref *remote_refs, int follow_remote_head,\n-\t\tconst char *no_warn_branch)\n+static int set_head(const struct ref *remote_refs, struct remote *remote)\n {\n \tint result = 0, create_only, is_bare, was_detached;\n \tstruct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,\n \t\t      b_local_head = STRBUF_INIT;\n-\tconst char *remote = gtransport->remote->name;\n+\tint follow_remote_head = remote->follow_remote_head;\n+\tconst char *no_warn_branch = remote->no_warn_branch;\n \tchar *head_name = NULL;\n \tstruct ref *ref, *matches;\n \tstruct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map;\n@@ -1661,8 +1661,8 @@ static int set_head(const struct ref *remote_refs, int follow_remote_head,\n \t\tstrbuf_addstr(&b_head, \"HEAD\");\n \t\tstrbuf_addf(&b_remote_head, \"refs/heads/%s\", head_name);\n \t} else {\n-\t\tstrbuf_addf(&b_head, \"refs/remotes/%s/HEAD\", remote);\n-\t\tstrbuf_addf(&b_remote_head, \"refs/remotes/%s/%s\", remote, head_name);\n+\t\tstrbuf_addf(&b_head, \"refs/remotes/%s/HEAD\", remote->name);\n+\t\tstrbuf_addf(&b_remote_head, \"refs/remotes/%s/%s\", remote->name, head_name);\n \t}\n \t\t/* make sure it's valid */\n \tif (!is_bare && !refs_ref_exists(refs, b_remote_head.buf)) {\n@@ -1678,7 +1678,7 @@ static int set_head(const struct ref *remote_refs, int follow_remote_head,\n \tif (verbosity >= 0 &&\n \t\tfollow_remote_head == FOLLOW_REMOTE_WARN &&\n \t\t(!no_warn_branch || strcmp(no_warn_branch, head_name)))\n-\t\treport_set_head(remote, head_name, &b_local_head, was_detached);\n+\t\treport_set_head(remote->name, head_name, &b_local_head, was_detached);\n \n cleanup:\n \tfree(head_name);\n@@ -1924,8 +1924,7 @@ static int do_fetch(struct transport *transport,\n \t\t\t\t  \"you need to specify exactly one branch with the --set-upstream option\"));\n \t\t}\n \t}\n-\tif (set_head(remote_refs, transport->remote->follow_remote_head,\n-\t\ttransport->remote->no_warn_branch))\n+\tif (set_head(remote_refs, transport->remote))\n \t\t;\n \t\t/*\n \t\t * Way too many cases where this can go wrong\n-- \n2.48.1.93.g276f59c085\n\n"},{"id":"511226","messageId":"Z5c2CKpYM3KevMyD@pks.im","threadId":"62790","inReplyTo":"20250126220403.289742-2-bence@ferdinandy.com","subject":"Re: [PATCH v2 2/2] fetch set_head: fix non-mirror remotes in bare repositories","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-01-27T07:30:16Z","receivedAt":"2025-01-27T07:30:20Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Sun, Jan 26, 2025 at 11:02:11PM +0100, Bence Ferdinandy wrote:\n> In b1b713f722 (fetch set_head: handle mirrored bare repositories,\n> 2024-11-22) it was implicitly assumed that all remotes will be mirrors\n> in a bare repository, thus fetching a non-mirrored remote could lead to\n> HEAD pointing to a non-existent reference. Make sure we only overwrite\n> HEAD if we are in a bare repository and fetching from a mirror.\n> Otherwise, proceed as normally, and create\n> refs/remotes/<nonmirrorremote>/HEAD instead.\n> \n> Reported-by: Christian Hesse <list@eworm.de>\n> Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>\n\nThanks, both of these patches look sensible to me.\n\nPatrick\n"},{"id":"511301","messageId":"xmqqjzagqabz.fsf@gitster.g","threadId":"62790","inReplyTo":"Z5c2CKpYM3KevMyD@pks.im","subject":"Re: [PATCH v2 2/2] fetch set_head: fix non-mirror remotes in bare repositories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-01-27T20:18:56Z","receivedAt":"2025-01-27T20:18:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> On Sun, Jan 26, 2025 at 11:02:11PM +0100, Bence Ferdinandy wrote:\n>> In b1b713f722 (fetch set_head: handle mirrored bare repositories,\n>> 2024-11-22) it was implicitly assumed that all remotes will be mirrors\n>> in a bare repository, thus fetching a non-mirrored remote could lead to\n>> HEAD pointing to a non-existent reference. Make sure we only overwrite\n>> HEAD if we are in a bare repository and fetching from a mirror.\n>> Otherwise, proceed as normally, and create\n>> refs/remotes/<nonmirrorremote>/HEAD instead.\n>> \n>> Reported-by: Christian Hesse <list@eworm.de>\n>> Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>\n>\n> Thanks, both of these patches look sensible to me.\n\nYeah, they read quite well.  Thanks, all.\nWill queue.\n"}]}