Skip to contentSkip to conversation

What is 'git BRANCH'?

DISCUSSION Jurko Gospodnetić 6 participants 8 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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ć

#1 lore raw
Quoted 10 lines · Jurko Gospodnetić

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?

#2 lore raw
Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Jurko Gospodnetić

Hi.

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

Quoted 7 lines
Quoted 5 lines

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.

---
 git.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
git.c +1 -1
index 37b1d76..c99e769 100644
@@ -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.. */
#3 lore raw

git.c int main(int argc, const char **argv) · line 454

Quoted 13 lines · Junio C Hamano
git.c +1 -1
index 37b1d76..c99e769 100644
@@ -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?

Signature · 3 lines
Cheers,

Sverre Rabbelier
#4 lore raw
Quoted 4 lines · Sverre Rabbelier

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

#5 lore raw
In reply to Junio C Hamano

git.c int main(int argc, const char **argv) · line 452

Quoted 11 lines · Junio C Hamano <gitster <at> pobox.com> writes:
git.c +1 -1
index 37b1d76..c99e769 100644
@@ -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

#6 lore raw
In reply to Junio C Hamano
Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Jurko Gospodnetić

Hi.

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

Quoted 7 lines
Quoted 5 lines

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

Signature · 4 lines
Kevin Ballard
http://kevin.sb.org
[email protected]
http://www.tildesoft.com
#7 lore raw

Hi all.

Quoted 9 lines · Junio C Hamano
Quoted 8 lines
Quoted 5 lines · Jurko Gospodnetić

Hi.

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

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

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ć