summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Michael Schubert <mschub@elegosoft.com>2011-07-08 12:08:49 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2011-07-08 08:59:44 -0700
commit823e0ded8a319425496967dcb284e7e3ce2b6c29 (patch)
tree82c2eee4b73bc4a99a1e509370586a89aa1b4781
parentdocs: document --textconv diff option (diff)
downloadtgif-823e0ded8a319425496967dcb284e7e3ce2b6c29.tar.xz
help_unknown_cmd: do not propose an "unknown" cmd
When executing an external shell script like `git foo` with a bad shebang, e.g. "#!/usr/bin/not/existing", execvp returns 127 (ENOENT). Since help_unknown_cmd proposes the use of all external commands similar to the name of the "unknown" command, it suggests the just failed command again. Stop it and give some advice to the user. Helped-by: Jeff King <peff@peff.net> Signed-off-by: Michael Schubert <mschub@elegosoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--help.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/help.c b/help.c
index 7654f1bfd6..42193550f0 100644
--- a/help.c
+++ b/help.c
@@ -302,6 +302,10 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
#define SIMILARITY_FLOOR 7
#define SIMILAR_ENOUGH(x) ((x) < SIMILARITY_FLOOR)
+static const char bad_interpreter_advice[] =
+ N_("'%s' appears to be a git command, but we were not\n"
+ "able to execute it. Maybe git-%s is broken?");
+
const char *help_unknown_cmd(const char *cmd)
{
int i, n, best_similarity = 0;
@@ -326,6 +330,14 @@ const char *help_unknown_cmd(const char *cmd)
int cmp = 0; /* avoid compiler stupidity */
const char *candidate = main_cmds.names[i]->name;
+ /*
+ * An exact match means we have the command, but
+ * for some reason exec'ing it gave us ENOENT; probably
+ * it's a bad interpreter in the #! line.
+ */
+ if (!strcmp(candidate, cmd))
+ die(_(bad_interpreter_advice), cmd, cmd);
+
/* Does the candidate appear in common_cmds list? */
while (n < ARRAY_SIZE(common_cmds) &&
(cmp = strcmp(common_cmds[n].name, candidate)) < 0)