git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Doesn't disambiguate between 'external command failed' and 'command not found'

From
MSMichael Schubert <mschub@elegosoft.com>
Date
Jul 5, 2011, 20:41 UTC
Message-ID
<4E137701.1020007@elegosoft.com>
In-Reply-To
<1309884564.18513.12.camel@umgah>
Hi,
here is a tiny patch; maybe there is a cleaner way doing this.?
-- >8 --
Subject: [PATCH] help_unknown_cmd: do not propose an "unknown" cmd

When executing an external shell script like `git foo` with the following shebang "#!/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.

Signed-off-by: Michael Schubert <mschub@elegosoft.com>
---
 help.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/help.c b/help.c
index 7654f1b..10b98ba 100644
--- a/help.c
+++ b/help.c
@@ -383,12 +383,24 @@ const char *help_unknown_cmd(const char *cmd)
 
 	fprintf(stderr, "git: '%s' is not a git command. See 'git --help'.\n", cmd);
 
-	if (SIMILAR_ENOUGH(best_similarity)) {
+	if (n==1 && !strcmp(cmd, main_cmds.names[0]->name))
+		;
+		/*
+		 * This avoids proposing the use of a command
+		 * which apparently just didn't work, e.g.
+		 * when executing a shell script git-foo with
+		 * the following shebang:
+		 *
+		 * 	#!/usr/bin/not/here
+		 *
+		 */
+	else if (SIMILAR_ENOUGH(best_similarity)) {
 		fprintf(stderr, "\nDid you mean %s?\n",
 			n < 2 ? "this": "one of these");
 
 		for (i = 0; i < n; i++)
-			fprintf(stderr, "\t%s\n", main_cmds.names[i]->name);
+			if (strcmp(cmd, main_cmds.names[i]->name))
+				fprintf(stderr, "\t%s\n", main_cmds.names[i]->name);
 	}
 
 	exit(1);
-- 
1.7.6.132.gdca5
Previous: Alex VandiverNext: Jeff King
Message 2 of 13 in “Doesn't disambiguate between 'external command failed' and 'command not found'”
  1. Alex VandiverJul 5, 2011
  2. Michael SchubertJul 5, 2011
  3. Jeff KingJul 5, 2011
  4. Jeff KingJul 5, 2011
  5. Sverre RabbelierJul 6, 2011
  6. Michael SchubertJul 6, 2011
  7. Jeff KingJul 6, 2011
  8. Jeff KingJul 6, 2011
  9. Junio C HamanoJul 6, 2011
  10. Michael SchubertJul 8, 2011
  11. Junio C HamanoJul 8, 2011
  12. Junio C HamanoJul 6, 2011
  13. Jeff KingJul 6, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.