{"thread":{"id":"60428","subject":"Repository cloned using SSH does not respect bare repository initial branch","startedAt":"2023-10-25T20:36:43Z","lastAt":"2023-10-31T02:38:52Z","messageCount":7,"participants":["Sheik","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"483869","messageId":"63eb269e-72b9-4830-98fc-aeef8b8180d7@gmail.com","threadId":"60428","inReplyTo":null,"subject":"Repository cloned using SSH does not respect bare repository initial branch","fromName":"Sheik","fromEmail":"sahibzone@gmail.com","sentAt":"2023-10-25T20:36:36Z","receivedAt":"2023-10-25T20:36:43Z","isPatch":false,"sender":{"key":"sahibzone@gmail.com","avatar":null},"body":"Hi Maintainers,\n\nRepository cloned using SSH does not use the branch configured in the \nbare repository however repository cloned using filesystem does as \nexpected. Shouldn't they both behave the same?\n\n\nThanks\nSheik\n\n\nThank you for filling out a Git bug report!\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\n#Create bare repository\n     su - $user\n     git init --bare --initial-branch=test test.git\n\n#Clone repository\n     git clone ssh://$user@$computer:/home/$user/test.git test1\n     cd test1\n\n     git remote show origin\n     #Output [ORIGIN1]\n\n     echo abc >> abc.txt && git add * && git commit -a -m test && git push\n     #Output...\n     #* [new branch]      master -> master\n\n     git remote show origin\n     #Output [ORIGIN2]\n\nWhat did you expect to happen? (Expected behavior)\nRepository cloned using ssh should push to test branch just like \nrepository cloned using filesystem does below as configured in the bare \nrepository.\n\n#Clone repository\n     git clone home/$user/test.git test2\n\n     git remote show origin\n     #Output [ORIGIN3]\n\n     echo abc >> abc.txt && git add * && git commit -a -m test && git push\n\n     #Output...\n     #* [new branch]      test -> test\n\n     git remote show origin\n     #Output [ORIGIN4]\n\nWhat happened instead? (Actual behavior)\nRepository cloned using ssh pushed to master branch disregarding \nconfiguration in bare repository.\n\nWhat's different between what you expected and what actually happened?\nFor ssh cloned repository test branch should been the default branch \nhowever master was the default.\n\nAnything else you want to add:\n\n[ORIGIN1]\n* remote origin\n   HEAD branch: (unknown)\n   Local branch configured for 'git pull':\n     master merges with remote master\n\n[ORIGIN2]\n* remote origin\n   HEAD branch: (unknown)\n   Remote branch:\n     master tracked\n   Local branch configured for 'git pull':\n     master merges with remote master\n   Local ref configured for 'git push':\n     master pushes to master (up to date)\n\n[ORIGIN3]\n* remote origin\n   HEAD branch: (unknown)\n   Local branch configured for 'git pull':\n     test merges with remote test\n\n[ORIGIN4]\n* remote origin\n   HEAD branch: test\n   Remote branches:\n     master new (next fetch will store in remotes/origin)\n     test   tracked\n   Local branch configured for 'git pull':\n     test merges with remote test\n   Local ref configured for 'git push':\n     test pushes to test (up to date)\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n\n[System Info]\ngit version:\ngit version 2.42.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 6.5.0-2-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.5.6-1 \n(2023-10-07) x86_64\ncompiler info: gnuc: 13.2\nlibc info: glibc: 2.37\n$SHELL (typically, interactive shell): /bin/bash\n\n\n[Enabled Hooks]\n\n"},{"id":"484087","messageId":"20231030093605.GE84866@coredump.intra.peff.net","threadId":"60428","inReplyTo":"63eb269e-72b9-4830-98fc-aeef8b8180d7@gmail.com","subject":"Re: Repository cloned using SSH does not respect bare repository initial branch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2023-10-30T09:36:05Z","receivedAt":"2023-10-30T09:36:08Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Oct 26, 2023 at 07:36:36AM +1100, Sheik wrote:\n\n> Repository cloned using SSH does not use the branch configured in the bare\n> repository however repository cloned using filesystem does as expected.\n> Shouldn't they both behave the same?\n\nWhat version of Git is running on the ssh server?\n\nYour example seems to show that the parent repository has an unborn\nbranch (i.e., HEAD points to \"refs/heads/test\", but there are no commits\nyet). I think the server-side bits you need for that to work showed up\nin 59e1205d16 (ls-refs: report unborn targets of symrefs, 2021-02-05),\nwhich is in v2.31.\n\nSo even though your client seems to be v2.42 (from the output you gave),\nif the server is older it may not be sending sufficient information.\nThere were also some other fixes on top of that, but I _think_ they were\nall client-side (so your v2.42 clone command should be doing the right\nthing).\n\n-Peff\n"},{"id":"484115","messageId":"b310e254-f6d3-4715-b042-341bf5a98bbc@gmail.com","threadId":"60428","inReplyTo":"20231030093605.GE84866@coredump.intra.peff.net","subject":"Re: Repository cloned using SSH does not respect bare repository initial branch","fromName":"Sheik","fromEmail":"sahibzone@gmail.com","sentAt":"2023-10-30T15:24:46Z","receivedAt":"2023-10-30T15:24:53Z","isPatch":false,"sender":{"key":"sahibzone@gmail.com","avatar":null},"body":"Server version is same as client (v2.42.0) as I ran these commands all \non the same machine.\n\n\nTest on ssh server:\n\n$ git -v --build-options\n\n#Output\n\ngit version 2.42.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\n\n\nThanks\n\nSheik\n\n\nOn 30/10/23 20:36, Jeff King wrote:\n> On Thu, Oct 26, 2023 at 07:36:36AM +1100, Sheik wrote:\n>\n>> Repository cloned using SSH does not use the branch configured in the bare\n>> repository however repository cloned using filesystem does as expected.\n>> Shouldn't they both behave the same?\n> What version of Git is running on the ssh server?\n>\n> Your example seems to show that the parent repository has an unborn\n> branch (i.e., HEAD points to \"refs/heads/test\", but there are no commits\n> yet). I think the server-side bits you need for that to work showed up\n> in 59e1205d16 (ls-refs: report unborn targets of symrefs, 2021-02-05),\n> which is in v2.31.\n>\n> So even though your client seems to be v2.42 (from the output you gave),\n> if the server is older it may not be sending sufficient information.\n> There were also some other fixes on top of that, but I _think_ they were\n> all client-side (so your v2.42 clone command should be doing the right\n> thing).\n>\n> -Peff\n"},{"id":"484116","messageId":"325c742b-c909-4f43-a120-6db8b402e5f5@gmail.com","threadId":"60428","inReplyTo":"20231030093605.GE84866@coredump.intra.peff.net","subject":"Re: Repository cloned using SSH does not respect bare repository initial branch","fromName":"Sheik","fromEmail":"sahibzone@gmail.com","sentAt":"2023-10-30T15:33:45Z","receivedAt":"2023-10-30T15:33:52Z","isPatch":false,"sender":{"key":"sahibzone@gmail.com","avatar":null},"body":"On 30/10/23 20:36, Jeff King wrote:\n\n> On Thu, Oct 26, 2023 at 07:36:36AM +1100, Sheik wrote:\n>\n>> Repository cloned using SSH does not use the branch configured in the bare\n>> repository however repository cloned using filesystem does as expected.\n>> Shouldn't they both behave the same?\n> What version of Git is running on the ssh server?\n>\n> Your example seems to show that the parent repository has an unborn\n> branch (i.e., HEAD points to \"refs/heads/test\", but there are no commits\n> yet). I think the server-side bits you need for that to work showed up\n> in 59e1205d16 (ls-refs: report unborn targets of symrefs, 2021-02-05),\n> which is in v2.31.\n>\n> So even though your client seems to be v2.42 (from the output you gave),\n> if the server is older it may not be sending sufficient information.\n> There were also some other fixes on top of that, but I _think_ they were\n> all client-side (so your v2.42 clone command should be doing the right\n> thing).\n>\n> -Peff\n\n\nConfirming your observation above, yes this is a purely new bare \nrepository which has no commits yet before cloning.\n\n\nThanks\n\nSheik\n\n"},{"id":"484134","messageId":"20231030174307.GA854621@coredump.intra.peff.net","threadId":"60428","inReplyTo":"b310e254-f6d3-4715-b042-341bf5a98bbc@gmail.com","subject":"Re: Repository cloned using SSH does not respect bare repository initial branch","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2023-10-30T17:43:07Z","receivedAt":"2023-10-30T17:43:09Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Oct 31, 2023 at 02:24:46AM +1100, Sheik wrote:\n\n> Server version is same as client (v2.42.0) as I ran these commands all on\n> the same machine.\n\nOK. The next thing I'd check is running both commands with:\n\n  GIT_TRACE_PACKET=1 git clone ...\n\nto see the protocol trace, and how it differs between the two. What I\nsuspect you may see is that the local clone is using the \"v2\" protocol\n(a capabilities report, followed by \"ls-refs\", which mentions the symref\nvalue of HEAD), and the ssh one uses the older \"v0\" (it goes straight to\nthe ref advertisement).\n\nQuoting from 59e1205d16 (ls-refs: report unborn targets of symrefs,\n2021-02-05), the commit I mentioned before:\n\n    This change is only for protocol v2. A similar change for protocol\n    v0 would require independent protocol design (there being no\n    analogous position to signal support for \"unborn\") and client-side\n    plumbing of the data required, so the scope of this patch set is\n    limited to protocol v2.\n\nSo in v0 the server doesn't pass back sufficient information for the\nclient to know about the name of the unborn HEAD branch.\n\nIf that's the culprit, the next question of course is why we'd do v2\nlocally versus v0 overssh. And that probably has to do with how we\ntrigger the protocol upgrade. To see if the server supports v2, the\nclient passes extra information \"out of band\". For git-over-http, this\nhappens in an extra HTTP header. For local repositories, it happens in\nan environment variable ($GIT_PROTOCOL). For git-over-ssh it happens in\nthat sameenvironment variable, which we instruct the ssh client to pass\nusing \"-o SendEnv\". But:\n\n  1. If your ssh client doesn't look like openssh, we don't know if it\n     supports \"-o\" and may skip it. See the discussion in ssh.variant in\n     \"git help config\".\n\n  2. Some servers need to be configured to allow the client to set\n     environment variables. In the case of openssh, you'd want a line\n     like this in your sshd_config file:\n\n       AcceptEnv GIT_PROTOCOL\n\nOf the two, I'd guess that the second one is more likely to be your\nproblem (since you're running Linux, where openssh is the norm).\n\n-Peff\n"},{"id":"484163","messageId":"9cec7307-a875-4b8c-9abe-81c8879d698b@gmail.com","threadId":"60428","inReplyTo":"20231030174307.GA854621@coredump.intra.peff.net","subject":"Re: Repository cloned using SSH does not respect bare repository initial branch","fromName":"Sheik","fromEmail":"sahibzone@gmail.com","sentAt":"2023-10-30T23:30:29Z","receivedAt":"2023-10-30T23:30:36Z","isPatch":false,"sender":{"key":"sahibzone@gmail.com","avatar":null},"body":"On 31/10/23 04:43, Jeff King wrote:\n\n> On Tue, Oct 31, 2023 at 02:24:46AM +1100, Sheik wrote:\n>\n>> Server version is same as client (v2.42.0) as I ran these commands all on\n>> the same machine.\n> OK. The next thing I'd check is running both commands with:\n>\n>    GIT_TRACE_PACKET=1 git clone ...\n>\n> to see the protocol trace, and how it differs between the two. What I\n> suspect you may see is that the local clone is using the \"v2\" protocol\n> (a capabilities report, followed by \"ls-refs\", which mentions the symref\n> value of HEAD), and the ssh one uses the older \"v0\" (it goes straight to\n> the ref advertisement).\n>\n> Quoting from 59e1205d16 (ls-refs: report unborn targets of symrefs,\n> 2021-02-05), the commit I mentioned before:\n>\n>      This change is only for protocol v2. A similar change for protocol\n>      v0 would require independent protocol design (there being no\n>      analogous position to signal support for \"unborn\") and client-side\n>      plumbing of the data required, so the scope of this patch set is\n>      limited to protocol v2.\n>\n> So in v0 the server doesn't pass back sufficient information for the\n> client to know about the name of the unborn HEAD branch.\n>\n> If that's the culprit, the next question of course is why we'd do v2\n> locally versus v0 overssh. And that probably has to do with how we\n> trigger the protocol upgrade. To see if the server supports v2, the\n> client passes extra information \"out of band\". For git-over-http, this\n> happens in an extra HTTP header. For local repositories, it happens in\n> an environment variable ($GIT_PROTOCOL). For git-over-ssh it happens in\n> that sameenvironment variable, which we instruct the ssh client to pass\n> using \"-o SendEnv\". But:\n>\n>    1. If your ssh client doesn't look like openssh, we don't know if it\n>       supports \"-o\" and may skip it. See the discussion in ssh.variant in\n>       \"git help config\".\n>\n>    2. Some servers need to be configured to allow the client to set\n>       environment variables. In the case of openssh, you'd want a line\n>       like this in your sshd_config file:\n>\n>         AcceptEnv GIT_PROTOCOL\n>\n> Of the two, I'd guess that the second one is more likely to be your\n> problem (since you're running Linux, where openssh is the norm).\n>\n> -Peff\n\n\nThanks Jeff, tracing and setting the AcceptEnv indeed did the trick and \nworkflow now works as expected.\n\nTest steps on Debian/OpenSsh:\n\nServer\n1. Edit /etc/ssh/sshd_config\n2. Add AcceptEnv GIT_PROTOCOL\n3. systemctl restart sshd\n\nClient\n1. Enable ssh logging:\n    export GIT_SSH_COMMAND=ssh -v\n2. git clone ...\n3. Output from ssh shows variable being sent (although regardless if \nAcceptEnv was set or not):\n    debug1: channel 0: setting env GIT_PROTOCOL = \"version=2\"\n    debug2: channel 0: request env confirm 0\n\nReferences\n1. \nhttps://git-scm.com/docs/git/2.42.0#Documentation/git.txt-codeGITPROTOCOLcode \n\n2. https://git-scm.com/docs/gitprotocol-v2#_ssh_and_file_transport\n3. \nhttps://git-scm.com/docs/git/2.42.0#Documentation/git.txt-codeGITSSHCOMMANDcode \n\n\nThanks\nSheik\n\n"},{"id":"484175","messageId":"b7feb821-d041-47bd-9058-2f393499f62c@gmail.com","threadId":"60428","inReplyTo":"9cec7307-a875-4b8c-9abe-81c8879d698b@gmail.com","subject":"Re: Repository cloned using SSH does not respect bare repository initial branch","fromName":"Sheik","fromEmail":"sahibzone@gmail.com","sentAt":"2023-10-31T02:38:27Z","receivedAt":"2023-10-31T02:38:52Z","isPatch":false,"sender":{"key":"sahibzone@gmail.com","avatar":null},"body":"\nWondering whether a link to the protocol documentation should be added \nin \"git init --initial-branch\" to make this more obvious.\n\n 1. https://git-scm.com/docs/git-init#Documentation/git-init.txt---initial-branchltbranch-namegt\n 2. https://git-scm.com/docs/gitprotocol-v2\n\n\nThanks\n\nSheik\n\n"}]}