Skip to content

Commit 823e0de

Browse files
Michael Schubertgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Michael Schubert <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d28790d commit 823e0de

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

help.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
302302
#define SIMILARITY_FLOOR 7
303303
#define SIMILAR_ENOUGH(x) ((x) < SIMILARITY_FLOOR)
304304

305+
static const char bad_interpreter_advice[] =
306+
N_("'%s' appears to be a git command, but we were not\n"
307+
"able to execute it. Maybe git-%s is broken?");
308+
305309
const char *help_unknown_cmd(const char *cmd)
306310
{
307311
int i, n, best_similarity = 0;
@@ -326,6 +330,14 @@ const char *help_unknown_cmd(const char *cmd)
326330
int cmp = 0; /* avoid compiler stupidity */
327331
const char *candidate = main_cmds.names[i]->name;
328332

333+
/*
334+
* An exact match means we have the command, but
335+
* for some reason exec'ing it gave us ENOENT; probably
336+
* it's a bad interpreter in the #! line.
337+
*/
338+
if (!strcmp(candidate, cmd))
339+
die(_(bad_interpreter_advice), cmd, cmd);
340+
329341
/* Does the candidate appear in common_cmds list? */
330342
while (n < ARRAY_SIZE(common_cmds) &&
331343
(cmp = strcmp(common_cmds[n].name, candidate)) < 0)

0 commit comments

Comments
 (0)