git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Michael Schubert <mschub@elegosoft.com>
To: git@vger.kernel.org, Alex Vandiver <alex@chmrr.net>
Subject: Re: Doesn't disambiguate between 'external command failed' and 'command not found'
Date: Tue, 05 Jul 2011 22:41:37 +0200	[thread overview]
Message-ID: <4E137701.1020007@elegosoft.com> (raw)
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

  reply	other threads:[~2011-07-05 20:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-05 16:49 Doesn't disambiguate between 'external command failed' and 'command not found' Alex Vandiver
2011-07-05 20:41 ` Michael Schubert [this message]
2011-07-05 23:16   ` Jeff King
2011-07-05 23:22     ` Jeff King
2011-07-06 11:24       ` Sverre Rabbelier
2011-07-06 11:47     ` Michael Schubert
2011-07-06 17:58       ` Jeff King
2011-07-06 18:00         ` Jeff King
2011-07-06 23:25           ` Junio C Hamano
2011-07-08 10:08             ` Michael Schubert
2011-07-08 16:52               ` Junio C Hamano
2011-07-06 17:24     ` Junio C Hamano
2011-07-06 17:56       ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E137701.1020007@elegosoft.com \
    --to=mschub@elegosoft.com \
    --cc=alex@chmrr.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).