git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Drew DeVault <sir@cmpwn.com>
To: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Cc: Drew DeVault <sir@cmpwn.com>, lanodan <contact+git@hacktivis.me>
Subject: [PATCH] help.c: add advice.correctTypos option
Date: Mon, 16 Nov 2020 13:55:21 -0500	[thread overview]
Message-ID: <20201116185521.2276-1-sir@cmpwn.com> (raw)

This allows users to disable guessing the commands or options that they
meant to use.
---
Questions:

- Is advice.* the right namespace?
- How should this interact with help.autocorrect?

 Documentation/config/advice.txt |  2 ++
 help.c                          | 19 ++++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/Documentation/config/advice.txt b/Documentation/config/advice.txt
index acbd0c09aa..135d1345af 100644
--- a/Documentation/config/advice.txt
+++ b/Documentation/config/advice.txt
@@ -119,4 +119,6 @@ advice.*::
 	addEmptyPathspec::
 		Advice shown if a user runs the add command without providing
 		the pathspec parameter.
+	correctTypos::
+		Detect typos and suggest corrections.
 --
diff --git a/help.c b/help.c
index 919cbb9206..c35c4c99da 100644
--- a/help.c
+++ b/help.c
@@ -515,10 +515,16 @@ static const char bad_interpreter_advice[] =
 
 const char *help_unknown_cmd(const char *cmd)
 {
-	int i, n, best_similarity = 0;
+	int i, n, best_similarity = 0, enable = 1;
 	struct cmdnames main_cmds, other_cmds;
 	struct cmdname_help *common_cmds;
 
+	git_config_get_bool("advice.correctTypos", &enable);
+	if (!enable) {
+		fprintf_ln(stderr, _("git: '%s' is not a git command. See 'git --help'."), cmd);
+		exit(1);
+	}
+
 	memset(&main_cmds, 0, sizeof(main_cmds));
 	memset(&other_cmds, 0, sizeof(other_cmds));
 	memset(&aliases, 0, sizeof(aliases));
@@ -705,11 +711,18 @@ static struct string_list guess_refs(const char *ref)
 NORETURN void help_unknown_ref(const char *ref, const char *cmd,
 			       const char *error)
 {
-	int i;
-	struct string_list suggested_refs = guess_refs(ref);
+	int i, enable = 1;
+	struct string_list suggested_refs;
 
 	fprintf_ln(stderr, _("%s: %s - %s"), cmd, ref, error);
 
+	git_config_get_bool("advice.correctTypos", &enable);
+	if (!enable) {
+		exit(1);
+	}
+
+	suggested_refs = guess_refs(ref);
+
 	if (suggested_refs.nr > 0) {
 		fprintf_ln(stderr,
 			   Q_("\nDid you mean this?",
-- 
2.29.2


             reply	other threads:[~2020-11-16 19:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-16 18:55 Drew DeVault [this message]
2020-11-16 23:41 ` [PATCH] help.c: add advice.correctTypos option Junio C Hamano

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

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

  git send-email \
    --in-reply-to=20201116185521.2276-1-sir@cmpwn.com \
    --to=sir@cmpwn.com \
    --cc=contact+git@hacktivis.me \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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.
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 NNTP newsgroup(s).