[PATCH] help.autocorrect prompt

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Added a new configuration value for help.autocorrect.
A value of 'prompt' causes git to wait for confirmation
before executing the assumed command.

Signed-off-by: David Barr <david.barr@xxxxxxxxxxxx>
Reviewed-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
 help.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/help.c b/help.c
index 7f4928e..2282885 100644
--- a/help.c
+++ b/help.c
@@ -267,8 +267,12 @@ static struct cmdnames aliases;
 
 static int git_unknown_cmd_config(const char *var, const char *value, void *cb)
 {
-	if (!strcmp(var, "help.autocorrect"))
-		autocorrect = git_config_int(var,value);
+	if (!strcmp(var, "help.autocorrect")) {
+		if (!strcmp(value, "prompt"))
+			autocorrect = INT_MAX;
+		else
+			autocorrect = git_config_int(var,value);
+	}
 	/* Also use aliases for command lookup */
 	if (!prefixcmp(var, "alias."))
 		add_cmdname(&aliases, var + 6, strlen(var + 6));
@@ -342,7 +346,16 @@ const char *help_unknown_cmd(const char *cmd)
 			"which does not exist.\n"
 			"Continuing under the assumption that you meant '%s'\n",
 			cmd, assumed);
-		if (autocorrect > 0) {
+		if (autocorrect == INT_MAX) {
+			char answer[3];
+			if (!isatty(STDIN_FILENO) || !isatty(STDERR_FILENO))
+				exit(1);
+			fprintf(stderr, "Continue? (y/n) ");
+			if (!fgets(answer, sizeof(answer), stdin))
+				exit(1);
+			if (*answer != 'y' && *answer != 'Y')
+				exit(1);
+		} else if (autocorrect > 0) {
 			fprintf(stderr, "in %0.1f seconds automatically...\n",
 				(float)autocorrect/10.0);
 			poll(NULL, 0, autocorrect * 100);
-- 
1.7.2.3.392.g02377.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]