git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Bug: branch checkout is detached if the case doesn't match
@ 2021-06-20 19:45 Tim Hutt
  2021-06-20 22:03 ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 6+ messages in thread
From: Tim Hutt @ 2021-06-20 19:45 UTC (permalink / raw)
  To: git

If you try to switch to a branch (e.g. `master`), but get the case wrong, e.g:

    git switch MASTER
    git checkout MASTER
    git switch Master
    git checkout Master

etc. then it autocorrects the case (bad idea but ok), but it also
enables the `--detach` flag! In other words

    git switch Master

acts like

    git switch -d master

Very unexpected!

Cheers,

Tim

[System Info]
git version:
git version 2.32.0
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Darwin 20.4.0 Darwin Kernel Version 20.4.0: Fri Mar  5 01:14:14
PST 2021; root:xnu-7195.101.1~3/RELEASE_X86_64 x86_64
compiler info: clang: 12.0.5 (clang-1205.0.22.9)
libc info: no libc information available
$SHELL (typically, interactive shell): /bin/zsh

[Enabled Hooks]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug: branch checkout is detached if the case doesn't match
  2021-06-20 19:45 Bug: branch checkout is detached if the case doesn't match Tim Hutt
@ 2021-06-20 22:03 ` Ævar Arnfjörð Bjarmason
  2021-06-21 17:20   ` Tim Hutt
  0 siblings, 1 reply; 6+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-06-20 22:03 UTC (permalink / raw)
  To: Tim Hutt; +Cc: git


On Sun, Jun 20 2021, Tim Hutt wrote:

> If you try to switch to a branch (e.g. `master`), but get the case wrong, e.g:
>
>     git switch MASTER
>     git checkout MASTER
>     git switch Master
>     git checkout Master
>
> etc. then it autocorrects the case (bad idea but ok), but it also
> enables the `--detach` flag! In other words
>
>     git switch Master
>
> acts like
>
>     git switch -d master
>
> Very unexpected!

This behavior isn't intentionaly, but ultimately isn't with Git, but
with your running of Git on a filesystem that doesn't respect POSIX
semantics.

The default FS on OSX is case insensitive, we store the "master"
reference (unpacked) under that name on the FS, so this is emergent
behavior. Can you reproduce this after a:

    git pack-refs --all

?

Even after that we'll have a .git/HEAD, and I know on OSX e.g. "git log
head...<branch>" unintentionally resolved to "HEAD" too at some point
(probably still).

There's various workarounds in git's code to deal with funny behavior on
OSX, but it's hard to catch them all as it means having to second-guess
standard library calls. I think you're best off creating a
case-sensitive partition on your computer and using git there if you
want to avoid these cases entirely.

> [System Info]
> git version:
> git version 2.32.0
> cpu: x86_64
> no commit associated with this build
> sizeof-long: 8
> sizeof-size_t: 8
> shell-path: /bin/sh
> uname: Darwin 20.4.0 Darwin Kernel Version 20.4.0: Fri Mar  5 01:14:14
> PST 2021; root:xnu-7195.101.1~3/RELEASE_X86_64 x86_64
> compiler info: clang: 12.0.5 (clang-1205.0.22.9)
> libc info: no libc information available
> $SHELL (typically, interactive shell): /bin/zsh
>
> [Enabled Hooks]


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug: branch checkout is detached if the case doesn't match
  2021-06-20 22:03 ` Ævar Arnfjörð Bjarmason
@ 2021-06-21 17:20   ` Tim Hutt
  2021-06-23  2:38     ` brian m. carlson
  0 siblings, 1 reply; 6+ messages in thread
From: Tim Hutt @ 2021-06-21 17:20 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: git

Ah of course!

> git pack-refs --all

Yeah that "fixes" things so you get `fatal: invalid reference: MASTER`.

I guess `git checkout` checks whether `MASTER` exists (yes, according
to MacOS), but git log checks whether the current branch (`MASTER`)
matches `master` (it doesn't).

Very unfortunate, but I guess it's not worth fixing.

Cheers,

Tim

On Sun, 20 Jun 2021 at 23:09, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
>
>
> On Sun, Jun 20 2021, Tim Hutt wrote:
>
> > If you try to switch to a branch (e.g. `master`), but get the case wrong, e.g:
> >
> >     git switch MASTER
> >     git checkout MASTER
> >     git switch Master
> >     git checkout Master
> >
> > etc. then it autocorrects the case (bad idea but ok), but it also
> > enables the `--detach` flag! In other words
> >
> >     git switch Master
> >
> > acts like
> >
> >     git switch -d master
> >
> > Very unexpected!
>
> This behavior isn't intentionaly, but ultimately isn't with Git, but
> with your running of Git on a filesystem that doesn't respect POSIX
> semantics.
>
> The default FS on OSX is case insensitive, we store the "master"
> reference (unpacked) under that name on the FS, so this is emergent
> behavior. Can you reproduce this after a:
>
>     git pack-refs --all
>
> ?
>
> Even after that we'll have a .git/HEAD, and I know on OSX e.g. "git log
> head...<branch>" unintentionally resolved to "HEAD" too at some point
> (probably still).
>
> There's various workarounds in git's code to deal with funny behavior on
> OSX, but it's hard to catch them all as it means having to second-guess
> standard library calls. I think you're best off creating a
> case-sensitive partition on your computer and using git there if you
> want to avoid these cases entirely.
>
> > [System Info]
> > git version:
> > git version 2.32.0
> > cpu: x86_64
> > no commit associated with this build
> > sizeof-long: 8
> > sizeof-size_t: 8
> > shell-path: /bin/sh
> > uname: Darwin 20.4.0 Darwin Kernel Version 20.4.0: Fri Mar  5 01:14:14
> > PST 2021; root:xnu-7195.101.1~3/RELEASE_X86_64 x86_64
> > compiler info: clang: 12.0.5 (clang-1205.0.22.9)
> > libc info: no libc information available
> > $SHELL (typically, interactive shell): /bin/zsh
> >
> > [Enabled Hooks]
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug: branch checkout is detached if the case doesn't match
  2021-06-21 17:20   ` Tim Hutt
@ 2021-06-23  2:38     ` brian m. carlson
  2021-06-23 11:00       ` Tim Hutt
  2021-06-23 13:00       ` Ævar Arnfjörð Bjarmason
  0 siblings, 2 replies; 6+ messages in thread
From: brian m. carlson @ 2021-06-23  2:38 UTC (permalink / raw)
  To: Tim Hutt; +Cc: Ævar Arnfjörð Bjarmason, git

[-- Attachment #1: Type: text/plain, Size: 1320 bytes --]

On 2021-06-21 at 17:20:28, Tim Hutt wrote:
> Ah of course!
> 
> > git pack-refs --all
> 
> Yeah that "fixes" things so you get `fatal: invalid reference: MASTER`.
> 
> I guess `git checkout` checks whether `MASTER` exists (yes, according
> to MacOS), but git log checks whether the current branch (`MASTER`)
> matches `master` (it doesn't).
> 
> Very unfortunate, but I guess it's not worth fixing.

I should point out that there is work underway to add a ref backend
called reftable that doesn't store things in the file system and hence
doesn't suffer from this problem.  It's just a big project and it
involves touching a lot of code, so it's slow going, but when it's
completed, people who are using that won't have this problem ("MASTER"
will be rejected if the branch is "master").

You aren't the first person to report this problem in some variation (it
comes up quite frequently); we've known about it a long time, but fixing
it just isn't trivial.  In the mean time, you may prefer to adopt a
naming convention for your project branches; for example, even though I
use Linux and don't have this problem, I always use lowercase, which
makes things easier for colleagues on other systems (and is also easier
to type).
-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug: branch checkout is detached if the case doesn't match
  2021-06-23  2:38     ` brian m. carlson
@ 2021-06-23 11:00       ` Tim Hutt
  2021-06-23 13:00       ` Ævar Arnfjörð Bjarmason
  1 sibling, 0 replies; 6+ messages in thread
From: Tim Hutt @ 2021-06-23 11:00 UTC (permalink / raw)
  To: brian m. carlson, Tim Hutt,
	Ævar Arnfjörð Bjarmason, git

On Wed, 23 Jun 2021 at 03:38, brian m. carlson
<sandals@crustytoothpaste.net> wrote:
> I should point out that there is work underway to add a ref backend
> called reftable that doesn't store things in the file system and hence
> doesn't suffer from this problem.

Ah nice - good luck!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug: branch checkout is detached if the case doesn't match
  2021-06-23  2:38     ` brian m. carlson
  2021-06-23 11:00       ` Tim Hutt
@ 2021-06-23 13:00       ` Ævar Arnfjörð Bjarmason
  1 sibling, 0 replies; 6+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-06-23 13:00 UTC (permalink / raw)
  To: brian m. carlson; +Cc: Tim Hutt, git


On Wed, Jun 23 2021, brian m. carlson wrote:

> [...] In the mean time, you may prefer to adopt a naming convention
> for your project branches; for example, even though I use Linux and
> don't have this problem, I always use lowercase, which makes things
> easier for colleagues on other systems (and is also easier to type).

The reported issue is one that doesn't have to do with the naming of the
branch itself, but git accepting it due to how the ref backend interacts
with the FS.

As noted I've run into e.g. people writing unportable "head.." code,
which we happily resolve to "HEAD"., ditto "master", "Master", "MASTER"
etc. on OSX.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-23 13:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-20 19:45 Bug: branch checkout is detached if the case doesn't match Tim Hutt
2021-06-20 22:03 ` Ævar Arnfjörð Bjarmason
2021-06-21 17:20   ` Tim Hutt
2021-06-23  2:38     ` brian m. carlson
2021-06-23 11:00       ` Tim Hutt
2021-06-23 13:00       ` Ævar Arnfjörð Bjarmason

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).