# What is 'git BRANCH'?

8 messages from 2008-07-29 to 2008-07-30. Participants: Jurko Gospodnetić, Junio C Hamano, Kevin Ballard, Sverre Rabbelier, Eric Raible, Jeff King.
Thread: https://gitlist.dev/t/14745

## Jurko Gospodnetić, 2008-07-29 22:18

Subject: What is 'git BRANCH'?
Message-ID: <g6o4vi$rap$1@ger.gmane.org>
URL: https://gitlist.dev/e/g6o4vi%24rap%241%40ger.gmane.org

```
   Hi.

   I typed in "git BRANCH" by accident and got the error message: 
"fatal: cannot handle BRANCH internally".

   What does that mean?

   It is different from the usual "git: 'yada-yada' is not a 
git-command. See 'git --help'." message you get when you type in an 
incorrect command name.

   Just curious...

   Best regards,
     Jurko Gospodnetić

```

## Junio C Hamano, 2008-07-29 22:24

Subject: Re: What is 'git BRANCH'?
Message-ID: <7vej5cba6z.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vej5cba6z.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <g6o4vi$rap$1@ger.gmane.org>

```
Jurko Gospodnetić <jurko.gospodnetic@docte.hr> writes:

>   Hi.
>
>   I typed in "git BRANCH" by accident and got the error message:
> "fatal: cannot handle BRANCH internally".
>
>   What does that mean?
>
>   It is different from the usual "git: 'yada-yada' is not a
> git-command. See 'git --help'." message you get when you type in an
> incorrect command name.

Just a guess; your git is installed on a case-challenged filesystem?

```

## Kevin Ballard, 2008-07-29 22:32

Subject: Re: What is 'git BRANCH'?
Message-ID: <DEBF93FC-BA8D-4513-B4EE-A8648DA1D591@sb.org>
URL: https://gitlist.dev/e/DEBF93FC-BA8D-4513-B4EE-A8648DA1D591%40sb.org
In-Reply-To: <7vej5cba6z.fsf@gitster.siamese.dyndns.org>

```
On Jul 29, 2008, at 3:24 PM, Junio C Hamano wrote:

> Jurko Gospodnetić <jurko.gospodnetic@docte.hr> writes:
>
>>  Hi.
>>
>>  I typed in "git BRANCH" by accident and got the error message:
>> "fatal: cannot handle BRANCH internally".
>>
>>  What does that mean?
>>
>>  It is different from the usual "git: 'yada-yada' is not a
>> git-command. See 'git --help'." message you get when you type in an
>> incorrect command name.
>
> Just a guess; your git is installed on a case-challenged filesystem?

 From what I can tell, this happens when you execute one of the git-*  
builtin binaries using a name that doesn't actually match the binary,  
case-sensitively. When you type `git BRANCH` on OS X, git matches that  
against the git-branch binary and executes it, but argv[0] contains  
"git-BRANCH". When this is compared by the git-branch binary to the  
list of internal commands, it comes up empty, and the fallback code  
(to die with "fatal: cannot handle BRANCH internally") gets executed  
instead.

In other words, this is identical to running `/usr/local/libexec/git- 
core/git-BRANCH` or to doing something like `exec -a git-BRANCH /usr/ 
local/libexec/git-core/git-branch` (this example should work on any  
filesystem).

-Kevin Ballard

-- 
Kevin Ballard
http://kevin.sb.org
kevin@sb.org
http://www.tildesoft.com

```

## Junio C Hamano, 2008-07-29 22:39

Subject: Re: What is 'git BRANCH'?
Message-ID: <7v63qob9hz.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v63qob9hz.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <7vej5cba6z.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano <gitster@pobox.com> writes:

> Jurko Gospodnetić <jurko.gospodnetic@docte.hr> writes:
>
>>   Hi.
>>
>>   I typed in "git BRANCH" by accident and got the error message:
>> "fatal: cannot handle BRANCH internally".
>>
>>   What does that mean?
>>
>>   It is different from the usual "git: 'yada-yada' is not a
>> git-command. See 'git --help'." message you get when you type in an
>> incorrect command name.
>
> Just a guess; your git is installed on a case-challenged filesystem?

Yeah, that must be it.  This can happen on MacOS and Windows, I would
imagine.

-- >8 --
[PATCH] Fail on unknown command sensibly on case-challenged filesystems

The callchain on a case-challenged filesystem when the user runs "git
BRANCH" looks like this:

  - main(): git BRANCH
   - execv_dashed_external("BRANCH")
    - execvp("git-BRANCH")

     - main(): git-BRANCH
      - prefixcmp("git-BRANCH", "git-")
       - handle_internal_command()
         struct cmd_struct commands[] does not have "BRANCH"
         so it returns, instead of exiting.

When the "git wrapper" execs "git-BRANCH", if your filesystem knows
"branch" and "BRANCH" are different, execvp() would fail and we will see
the familiar error message from the git.c::main().

However, if execvp() succeeds, we feed an unknown command name to
handle_internal_command() and it triggers a different error message.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 git.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git.c b/git.c
index 37b1d76..c99e769 100644
--- a/git.c
+++ b/git.c
@@ -448,7 +448,7 @@ int main(int argc, const char **argv)
 		cmd += 4;
 		argv[0] = cmd;
 		handle_internal_command(argc, argv);
-		die("cannot handle %s internally", cmd);
+		help_unknown_cmd(cmd);
 	}
 
 	/* Look for flags.. */

```

## Jurko Gospodnetić, 2008-07-29 22:43

Subject: Re: What is 'git BRANCH'?
Message-ID: <488F9D17.8020703@docte.hr>
URL: https://gitlist.dev/e/488F9D17.8020703%40docte.hr
In-Reply-To: <DEBF93FC-BA8D-4513-B4EE-A8648DA1D591@sb.org>

```
   Hi all.

> On Jul 29, 2008, at 3:24 PM, Junio C Hamano wrote:
> 
>> Jurko Gospodnetić <jurko.gospodnetic@docte.hr> writes:
>>
>>>  Hi.
>>>
>>>  I typed in "git BRANCH" by accident and got the error message:
>>> "fatal: cannot handle BRANCH internally".
>>>
>>>  What does that mean?
>>>
>>>  It is different from the usual "git: 'yada-yada' is not a
>>> git-command. See 'git --help'." message you get when you type in an
>>> incorrect command name.
>>
>> Just a guess; your git is installed on a case-challenged filesystem?

   Thank you all for explaining this, and yes - this was detected on 
Windows with a NTFS drive set to case-insensitive.

   But, if something is running git-branch here... why does this 
script/executable/whatever try to check the name it got called with? Why 
does it not simply do its work no matter the name it got called with?

   If I'm asking something to obvious here - feel free to send me back 
to read the code... :-)

   Best regards,
     Jurko Gospodnetić

```

## Sverre Rabbelier, 2008-07-29 22:49

Subject: Re: What is 'git BRANCH'?
Message-ID: <bd6139dc0807291549y66c56fbah928a854f37573680@mail.gmail.com>
URL: https://gitlist.dev/e/bd6139dc0807291549y66c56fbah928a854f37573680%40mail.gmail.com
In-Reply-To: <7v63qob9hz.fsf@gitster.siamese.dyndns.org>

```
On Wed, Jul 30, 2008 at 00:39, Junio C Hamano <gitster@pobox.com> wrote:
> diff --git a/git.c b/git.c
> index 37b1d76..c99e769 100644
> --- a/git.c
> +++ b/git.c
> @@ -448,7 +448,7 @@ int main(int argc, const char **argv)
>                cmd += 4;
>                argv[0] = cmd;
>                handle_internal_command(argc, argv);
> -               die("cannot handle %s internally", cmd);
> +               help_unknown_cmd(cmd);
>        }
>
>        /* Look for flags.. */

Why does handle_internal_command not complain after the "	for (i = 0;
i < ARRAY_SIZE(commands); i++) {" that no matching commands were
found? Is that not an implicit assertion that would do well with being
asserted here?

-- 
Cheers,

Sverre Rabbelier

```

## Eric Raible, 2008-07-29 23:45

Subject: Re: What is 'git BRANCH'?
Message-ID: <loom.20080729T233158-95@post.gmane.org>
URL: https://gitlist.dev/e/loom.20080729T233158-95%40post.gmane.org
In-Reply-To: <7v63qob9hz.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano <gitster <at> pobox.com> writes:

> diff --git a/git.c b/git.c
> index 37b1d76..c99e769 100644
> --- a/git.c
> +++ b/git.c
> @@ -448,7 +448,7 @@ int main(int argc, const char **argv)
>  		cmd += 4;
>  		argv[0] = cmd;
>  		handle_internal_command(argc, argv);
> -		die("cannot handle %s internally", cmd);
> +		help_unknown_cmd(cmd);
>  	}

Which on windows leads to the less-than-friendly:

git BRANCH =>
git: 'BRANCH.exe' is not a git-command. See 'git --help'.

I wonder if it wouldn't be better to simply to a case-insensitive
comparison when comparing against the builtin array.  Alternatively,
at least the the extension (if any) ought to be stripped.

I'd be glad to come up with the patch for either given the word...

- Eric

```

## Jeff King, 2008-07-30 05:14

Subject: Re: What is 'git BRANCH'?
Message-ID: <20080730051453.GB4034@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20080730051453.GB4034%40sigill.intra.peff.net
In-Reply-To: <bd6139dc0807291549y66c56fbah928a854f37573680@mail.gmail.com>

```
On Wed, Jul 30, 2008 at 12:49:00AM +0200, Sverre Rabbelier wrote:

> Why does handle_internal_command not complain after the "	for (i = 0;
> i < ARRAY_SIZE(commands); i++) {" that no matching commands were
> found? Is that not an implicit assertion that would do well with being
> asserted here?

Because it is called from two places. In one, we _know_ that this must
be internal, so we die right after. In the other, we try internal, then
external, then alias. So we don't want to die. Grep for
handle_internal_cmmand in git.c.

-Peff

```
