{"thread":{"id":"55971","subject":"Bug: branch checkout is detached if the case doesn't match","startedAt":"2021-06-20T19:45:51Z","lastAt":"2021-06-23T13:01:50Z","messageCount":6,"participants":["Tim Hutt","Ævar Arnfjörð Bjarmason","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"427993","messageId":"CAKuVd4DfvEhXDUvxaU_jjNk8JSZANM8jpSEOxi1cbSAp23ohjg@mail.gmail.com","threadId":"55971","inReplyTo":null,"subject":"Bug: branch checkout is detached if the case doesn't match","fromName":"Tim Hutt","fromEmail":"tdhutt@gmail.com","sentAt":"2021-06-20T19:45:35Z","receivedAt":"2021-06-20T19:45:51Z","isPatch":false,"sender":{"key":"tdhutt@gmail.com","avatar":null},"body":"If you try to switch to a branch (e.g. `master`), but get the case wrong, e.g:\n\n    git switch MASTER\n    git checkout MASTER\n    git switch Master\n    git checkout Master\n\netc. then it autocorrects the case (bad idea but ok), but it also\nenables the `--detach` flag! In other words\n\n    git switch Master\n\nacts like\n\n    git switch -d master\n\nVery unexpected!\n\nCheers,\n\nTim\n\n[System Info]\ngit version:\ngit version 2.32.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Darwin 20.4.0 Darwin Kernel Version 20.4.0: Fri Mar  5 01:14:14\nPST 2021; root:xnu-7195.101.1~3/RELEASE_X86_64 x86_64\ncompiler info: clang: 12.0.5 (clang-1205.0.22.9)\nlibc info: no libc information available\n$SHELL (typically, interactive shell): /bin/zsh\n\n[Enabled Hooks]\n"},{"id":"428005","messageId":"87czsg429h.fsf@evledraar.gmail.com","threadId":"55971","inReplyTo":"CAKuVd4DfvEhXDUvxaU_jjNk8JSZANM8jpSEOxi1cbSAp23ohjg@mail.gmail.com","subject":"Re: Bug: branch checkout is detached if the case doesn't match","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-06-20T22:03:41Z","receivedAt":"2021-06-20T22:09:25Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Sun, Jun 20 2021, Tim Hutt wrote:\n\n> If you try to switch to a branch (e.g. `master`), but get the case wrong, e.g:\n>\n>     git switch MASTER\n>     git checkout MASTER\n>     git switch Master\n>     git checkout Master\n>\n> etc. then it autocorrects the case (bad idea but ok), but it also\n> enables the `--detach` flag! In other words\n>\n>     git switch Master\n>\n> acts like\n>\n>     git switch -d master\n>\n> Very unexpected!\n\nThis behavior isn't intentionaly, but ultimately isn't with Git, but\nwith your running of Git on a filesystem that doesn't respect POSIX\nsemantics.\n\nThe default FS on OSX is case insensitive, we store the \"master\"\nreference (unpacked) under that name on the FS, so this is emergent\nbehavior. Can you reproduce this after a:\n\n    git pack-refs --all\n\n?\n\nEven after that we'll have a .git/HEAD, and I know on OSX e.g. \"git log\nhead...<branch>\" unintentionally resolved to \"HEAD\" too at some point\n(probably still).\n\nThere's various workarounds in git's code to deal with funny behavior on\nOSX, but it's hard to catch them all as it means having to second-guess\nstandard library calls. I think you're best off creating a\ncase-sensitive partition on your computer and using git there if you\nwant to avoid these cases entirely.\n\n> [System Info]\n> git version:\n> git version 2.32.0\n> cpu: x86_64\n> no commit associated with this build\n> sizeof-long: 8\n> sizeof-size_t: 8\n> shell-path: /bin/sh\n> uname: Darwin 20.4.0 Darwin Kernel Version 20.4.0: Fri Mar  5 01:14:14\n> PST 2021; root:xnu-7195.101.1~3/RELEASE_X86_64 x86_64\n> compiler info: clang: 12.0.5 (clang-1205.0.22.9)\n> libc info: no libc information available\n> $SHELL (typically, interactive shell): /bin/zsh\n>\n> [Enabled Hooks]\n\n"},{"id":"428077","messageId":"CAKuVd4Bfykm0xe0P5FMy3W8HuECJHqP-RGo+T_VK4hn43sgEpg@mail.gmail.com","threadId":"55971","inReplyTo":"87czsg429h.fsf@evledraar.gmail.com","subject":"Re: Bug: branch checkout is detached if the case doesn't match","fromName":"Tim Hutt","fromEmail":"tdhutt@gmail.com","sentAt":"2021-06-21T17:20:28Z","receivedAt":"2021-06-21T17:20:43Z","isPatch":false,"sender":{"key":"tdhutt@gmail.com","avatar":null},"body":"Ah of course!\n\n> git pack-refs --all\n\nYeah that \"fixes\" things so you get `fatal: invalid reference: MASTER`.\n\nI guess `git checkout` checks whether `MASTER` exists (yes, according\nto MacOS), but git log checks whether the current branch (`MASTER`)\nmatches `master` (it doesn't).\n\nVery unfortunate, but I guess it's not worth fixing.\n\nCheers,\n\nTim\n\nOn Sun, 20 Jun 2021 at 23:09, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:\n>\n>\n> On Sun, Jun 20 2021, Tim Hutt wrote:\n>\n> > If you try to switch to a branch (e.g. `master`), but get the case wrong, e.g:\n> >\n> >     git switch MASTER\n> >     git checkout MASTER\n> >     git switch Master\n> >     git checkout Master\n> >\n> > etc. then it autocorrects the case (bad idea but ok), but it also\n> > enables the `--detach` flag! In other words\n> >\n> >     git switch Master\n> >\n> > acts like\n> >\n> >     git switch -d master\n> >\n> > Very unexpected!\n>\n> This behavior isn't intentionaly, but ultimately isn't with Git, but\n> with your running of Git on a filesystem that doesn't respect POSIX\n> semantics.\n>\n> The default FS on OSX is case insensitive, we store the \"master\"\n> reference (unpacked) under that name on the FS, so this is emergent\n> behavior. Can you reproduce this after a:\n>\n>     git pack-refs --all\n>\n> ?\n>\n> Even after that we'll have a .git/HEAD, and I know on OSX e.g. \"git log\n> head...<branch>\" unintentionally resolved to \"HEAD\" too at some point\n> (probably still).\n>\n> There's various workarounds in git's code to deal with funny behavior on\n> OSX, but it's hard to catch them all as it means having to second-guess\n> standard library calls. I think you're best off creating a\n> case-sensitive partition on your computer and using git there if you\n> want to avoid these cases entirely.\n>\n> > [System Info]\n> > git version:\n> > git version 2.32.0\n> > cpu: x86_64\n> > no commit associated with this build\n> > sizeof-long: 8\n> > sizeof-size_t: 8\n> > shell-path: /bin/sh\n> > uname: Darwin 20.4.0 Darwin Kernel Version 20.4.0: Fri Mar  5 01:14:14\n> > PST 2021; root:xnu-7195.101.1~3/RELEASE_X86_64 x86_64\n> > compiler info: clang: 12.0.5 (clang-1205.0.22.9)\n> > libc info: no libc information available\n> > $SHELL (typically, interactive shell): /bin/zsh\n> >\n> > [Enabled Hooks]\n>\n"},{"id":"428248","messageId":"YNKeq5mSu3f0A/5I@camp.crustytoothpaste.net","threadId":"55971","inReplyTo":"CAKuVd4Bfykm0xe0P5FMy3W8HuECJHqP-RGo+T_VK4hn43sgEpg@mail.gmail.com","subject":"Re: Bug: branch checkout is detached if the case doesn't match","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2021-06-23T02:38:35Z","receivedAt":"2021-06-23T02:39:11Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2021-06-21 at 17:20:28, Tim Hutt wrote:\n> Ah of course!\n> \n> > git pack-refs --all\n> \n> Yeah that \"fixes\" things so you get `fatal: invalid reference: MASTER`.\n> \n> I guess `git checkout` checks whether `MASTER` exists (yes, according\n> to MacOS), but git log checks whether the current branch (`MASTER`)\n> matches `master` (it doesn't).\n> \n> Very unfortunate, but I guess it's not worth fixing.\n\nI should point out that there is work underway to add a ref backend\ncalled reftable that doesn't store things in the file system and hence\ndoesn't suffer from this problem.  It's just a big project and it\ninvolves touching a lot of code, so it's slow going, but when it's\ncompleted, people who are using that won't have this problem (\"MASTER\"\nwill be rejected if the branch is \"master\").\n\nYou aren't the first person to report this problem in some variation (it\ncomes up quite frequently); we've known about it a long time, but fixing\nit just isn't trivial.  In the mean time, you may prefer to adopt a\nnaming convention for your project branches; for example, even though I\nuse Linux and don't have this problem, I always use lowercase, which\nmakes things easier for colleagues on other systems (and is also easier\nto type).\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"},{"id":"428269","messageId":"CAKuVd4D1qeuY_4+4eXQsU-q5oNw0+40PP46y_65GiNZdSgddCA@mail.gmail.com","threadId":"55971","inReplyTo":"YNKeq5mSu3f0A/5I@camp.crustytoothpaste.net","subject":"Re: Bug: branch checkout is detached if the case doesn't match","fromName":"Tim Hutt","fromEmail":"tdhutt@gmail.com","sentAt":"2021-06-23T11:00:06Z","receivedAt":"2021-06-23T11:00:47Z","isPatch":false,"sender":{"key":"tdhutt@gmail.com","avatar":null},"body":"On Wed, 23 Jun 2021 at 03:38, brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n> I should point out that there is work underway to add a ref backend\n> called reftable that doesn't store things in the file system and hence\n> doesn't suffer from this problem.\n\nAh nice - good luck!\n"},{"id":"428270","messageId":"87wnqk20qv.fsf@evledraar.gmail.com","threadId":"55971","inReplyTo":"YNKeq5mSu3f0A/5I@camp.crustytoothpaste.net","subject":"Re: Bug: branch checkout is detached if the case doesn't match","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-06-23T13:00:24Z","receivedAt":"2021-06-23T13:01:50Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Wed, Jun 23 2021, brian m. carlson wrote:\n\n> [...] In the mean time, you may prefer to adopt a naming convention\n> for your project branches; for example, even though I use Linux and\n> don't have this problem, I always use lowercase, which makes things\n> easier for colleagues on other systems (and is also easier to type).\n\nThe reported issue is one that doesn't have to do with the naming of the\nbranch itself, but git accepting it due to how the ref backend interacts\nwith the FS.\n\nAs noted I've run into e.g. people writing unportable \"head..\" code,\nwhich we happily resolve to \"HEAD\"., ditto \"master\", \"Master\", \"MASTER\"\netc. on OSX.\n"}]}