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
Jeff King <peff@peff.net>
Date
Jul 5, 2011, 23:22 UTC
Message-ID
<20110705232200.GD12085@sigill.intra.peff.net>
In-Reply-To
<20110705231604.GC12085@sigill.intra.peff.net>
On Tue, Jul 05, 2011 at 07:16:05PM -0400, Jeff King wrote:
> So if you are going to follow this strategy, you are probably better to
> just skip the entry (or give it a high levenshtein distance) in the main
> loop where we calculate candidates.
And here's what that would look like.
diff --git a/help.c b/help.c
index e925ca1..15e6f0b 100644
--- a/help.c
+++ b/help.c
@@ -329,6 +329,11 @@ const char *help_unknown_cmd(const char *cmd)
 		int cmp = 0; /* avoid compiler stupidity */
 		const char *candidate = main_cmds.names[i]->name;
 
+		if (!strcmp(candidate, cmd)) {
+			main_cmds.names[i]->len = SIMILARITY_FLOOR + 1;
+			continue;
+		}
+
 		/* Does the candidate appear in common_cmds list? */
 		while (n < ARRAY_SIZE(common_cmds) &&
 		       (cmp = strcmp(common_cmds[n].name, candidate)) < 0)

I suspect it can create its own brand of confusion, though:

  $ cat `which git-broken`
  #!/bin/bogus
  $ git broken
  git: 'broken' is not a git command. See 'git --help'.

At which point I search through my PATH and confirm that indeed,
"git-broken" _is_ a git command. And I'm left on my own to figure out
that it's a broken #!-line.

So I think I prefer giving some more specific advice. Even if we don't
mention "#!" lines explicitly, saying "This exists, but exec didn't
work" is probably more helpful than pretending it's not there. It gives
clueful people an idea of where to start looking for the problem.

-Peff
Previous: Jeff KingNext: Sverre Rabbelier
Message 4 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.