@@ -9,13 +9,19 @@ help.format:: help.autoCorrect:: If git detects typos and can identify exactly one valid command similar- to the error, git will automatically run the intended command after- waiting a duration of time defined by this configuration value in- deciseconds (0.1 sec). If this value is 0, the suggested corrections- will be shown, but not executed. If it is a negative integer, or- "immediate", the suggested command- is run immediately. If "never", suggestions are not shown at all. The- default value is zero.+ to the error, git will try to suggest the correct command or even+ run the intended command.+ If this config value is 0, then the suggested command will be shown.+ If it is positive, the suggested command will automatically+ run after waiting for that many deciseconds (0.1 sec).+ If it is "immediate", the suggested command will be+ run immediately.+ If it is "prompt", then the user will be shown the+ suggestion and will be prompted for confirmation before the command+ is run.+ If it is "never", then no suggestion will be shown and no command+ will be run.+ 0 is the default value for this config. help.htmlPath:: Specify the path where the HTML documentation resides. File system paths
@@ -618,7 +622,18 @@ const char *help_unknown_cmd(const char *cmd)_("Continuing under the assumption that ""you meant '%s'."),assumed);-else{+elseif(autocorrect==AUTOCORRECT_PROMPT){+if(!isatty(STDIN_FILENO)|!isatty(STDERR_FILENO))+exit(1);++char*answer;+fprintf_ln(stderr,_("Assuming you meant: '%s'."),+assumed);+answer=git_prompt(_("Continue? (y/N)"),PROMPT_ECHO);+if(!(starts_with(answer,"y")||+starts_with(answer,"Y")))+exit(1);+}else{fprintf_ln(stderr,_("Continuing in %0.1f seconds, ""assuming that you meant '%s'."),
On 11/08/21 07.15, Azeem Bande-Ali via GitGitGadget wrote:
help.autoCorrect::
If git detects typos and can identify exactly one valid command similar
- to the error, git will automatically run the intended command after
- waiting a duration of time defined by this configuration value in
- deciseconds (0.1 sec). If this value is 0, the suggested corrections
- will be shown, but not executed. If it is a negative integer, or
- "immediate", the suggested command
- is run immediately. If "never", suggestions are not shown at all. The
- default value is zero.
+ to the error, git will try to suggest the correct command or even
+ run the intended command.
+ If this config value is 0, then the suggested command will be shown.
+ If it is positive, the suggested command will automatically
+ run after waiting for that many deciseconds (0.1 sec).
+ If it is "immediate", the suggested command will be
+ run immediately.
+ If it is "prompt", then the user will be shown the
+ suggestion and will be prompted for confirmation before the command
+ is run.
+ If it is "never", then no suggestion will be shown and no command
+ will be run.
+ 0 is the default value for this config.
From: Azeem Bande-Ali via GitGitGadget <hidden> Date: 2021-08-14 05:13:24
From: Azeem Bande-Ali <redacted>
If help.autocorrect is set to 'prompt', the user is prompted
before the suggested action is executed.
Based on original patch by David Barr
https://lore.kernel.org/git/1283758030-13345-1-git-send-email-david.barr@cordelta.com/
Signed-off-by: Azeem Bande-Ali <redacted>
---
New config for help.autocorrect to prompt user before action
Changes since v1:
* Use bullet lists for documenting the various settings now supported
by help.autoCorrect
* Add a check for an interactive terminal early to bail if the user has
the "prompt" setting
* Make the output more compact so the user can see the suggestion and
the prompt in one line.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1012%2Fazeemba%2Fautoprompt-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1012/azeemba/autoprompt-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1012
Range-diff vs v1:
1: 7f72819b805 ! 1: 5819b872356 help.c: help.autocorrect=prompt waits for user action
@@ Documentation/config/help.txt: help.format::
- is run immediately. If "never", suggestions are not shown at all. The
- default value is zero.
+ to the error, git will try to suggest the correct command or even
-+ run the intended command.
-+ If this config value is 0, then the suggested command will be shown.
-+ If it is positive, the suggested command will automatically
-+ run after waiting for that many deciseconds (0.1 sec).
-+ If it is "immediate", the suggested command will be
-+ run immediately.
-+ If it is "prompt", then the user will be shown the
-+ suggestion and will be prompted for confirmation before the command
-+ is run.
-+ If it is "never", then no suggestion will be shown and no command
-+ will be run.
-+ 0 is the default value for this config.
++ run the suggestion automatically. Possible config values are:
++ - 0 (default): show the suggested command.
++ - positive number: run the suggested command after specified
++deciseconds (0.1 sec).
++ - "immediate": run the suggested command immediately.
++ - "prompt": show the suggestion and prompt for confirmation to run
++the command.
++ - "never": don't run or show any suggested command.
help.htmlPath::
Specify the path where the HTML documentation resides. File system paths
@@ help.c: static int git_unknown_cmd_config(const char *var, const char *value, vo
int v = git_config_int(var, value);
autocorrect = (v < 0)
@@ help.c: const char *help_unknown_cmd(const char *cmd)
+
+ read_early_config(git_unknown_cmd_config, NULL);
+
++ /*
++ * Disable autocorrection prompt in a non-interactive session
++ */
++ if ((autocorrect == AUTOCORRECT_PROMPT) && (!isatty(0) || !isatty(2)))
++ autocorrect = AUTOCORRECT_NEVER;
++
+ if (autocorrect == AUTOCORRECT_NEVER) {
+ fprintf_ln(stderr, _("git: '%s' is not a git command. See 'git --help'."), cmd);
+ exit(1);
+@@ help.c: const char *help_unknown_cmd(const char *cmd)
_("Continuing under the assumption that "
"you meant '%s'."),
assumed);
- else {
+ else if (autocorrect == AUTOCORRECT_PROMPT) {
-+ if (!isatty(STDIN_FILENO) | !isatty(STDERR_FILENO))
-+ exit(1);
-+
-+ char *answer;
-+ fprintf_ln(stderr, _("Assuming you meant: '%s'."),
-+ assumed);
-+ answer = git_prompt(_("Continue? (y/N)"), PROMPT_ECHO);
++ char* answer;
++ struct strbuf msg = STRBUF_INIT;
++ strbuf_addf(&msg, _("Run '%s' instead? (y/N)"),
++ assumed);
++ answer = git_prompt(msg.buf, PROMPT_ECHO);
++ strbuf_release(&msg);
+ if (!(starts_with(answer, "y") ||
+ starts_with(answer, "Y")))
+ exit(1);
Documentation/config/help.txt | 16 +++++++++-------
help.c | 22 +++++++++++++++++++++-
2 files changed, 30 insertions(+), 8 deletions(-)
@@ -9,13 +9,15 @@ help.format:: help.autoCorrect:: If git detects typos and can identify exactly one valid command similar- to the error, git will automatically run the intended command after- waiting a duration of time defined by this configuration value in- deciseconds (0.1 sec). If this value is 0, the suggested corrections- will be shown, but not executed. If it is a negative integer, or- "immediate", the suggested command- is run immediately. If "never", suggestions are not shown at all. The- default value is zero.+ to the error, git will try to suggest the correct command or even+ run the suggestion automatically. Possible config values are:+ - 0 (default): show the suggested command.+ - positive number: run the suggested command after specified+deciseconds (0.1 sec).+ - "immediate": run the suggested command immediately.+ - "prompt": show the suggestion and prompt for confirmation to run+the command.+ - "never": don't run or show any suggested command. help.htmlPath:: Specify the path where the HTML documentation resides. File system paths
@@ -539,6 +543,12 @@ const char *help_unknown_cmd(const char *cmd)read_early_config(git_unknown_cmd_config,NULL);+/*+*Disableautocorrectionpromptinanon-interactivesession+*/+if((autocorrect==AUTOCORRECT_PROMPT)&&(!isatty(0)||!isatty(2)))+autocorrect=AUTOCORRECT_NEVER;+if(autocorrect==AUTOCORRECT_NEVER){fprintf_ln(stderr,_("git: '%s' is not a git command. See 'git --help'."),cmd);exit(1);
@@ -618,7 +628,17 @@ const char *help_unknown_cmd(const char *cmd)_("Continuing under the assumption that ""you meant '%s'."),assumed);-else{+elseif(autocorrect==AUTOCORRECT_PROMPT){+char*answer;+structstrbufmsg=STRBUF_INIT;+strbuf_addf(&msg,_("Run '%s' instead? (y/N)"),+assumed);+answer=git_prompt(msg.buf,PROMPT_ECHO);+strbuf_release(&msg);+if(!(starts_with(answer,"y")||+starts_with(answer,"Y")))+exit(1);+}else{fprintf_ln(stderr,_("Continuing in %0.1f seconds, ""assuming that you meant '%s'."),
On 14/08/21 12.11, Azeem Bande-Ali via GitGitGadget wrote:
help.autoCorrect::
If git detects typos and can identify exactly one valid command similar
- to the error, git will automatically run the intended command after
- waiting a duration of time defined by this configuration value in
- deciseconds (0.1 sec). If this value is 0, the suggested corrections
- will be shown, but not executed. If it is a negative integer, or
- "immediate", the suggested command
- is run immediately. If "never", suggestions are not shown at all. The
- default value is zero.
+ to the error, git will try to suggest the correct command or even
+ run the suggestion automatically. Possible config values are:
+ - 0 (default): show the suggested command.
+ - positive number: run the suggested command after specified
+deciseconds (0.1 sec).
+ - "immediate": run the suggested command immediately.
+ - "prompt": show the suggestion and prompt for confirmation to run
+the command.
+ - "never": don't run or show any suggested command.
Looks OK.
Reviewed-by: Bagas Sanjaya <redacted>
--
An old man doll... just what I always wanted! - Clara
From: Azeem Bande-Ali via GitGitGadget <hidden> Date: 2021-08-15 01:50:34
From: Azeem Bande-Ali <redacted>
If help.autocorrect is set to 'prompt', the user is prompted
before the suggested action is executed.
Based on original patch by David Barr
https://lore.kernel.org/git/1283758030-13345-1-git-send-email-david.barr@cordelta.com/
Reviewed-by: Bagas Sanjaya <redacted>
Signed-off-by: Azeem Bande-Ali <redacted>
---
New config for help.autocorrect to prompt user before action
Only minor style changes have been made since v2:
* Moved * to variable name instead of the type name
* Keep code in the same line for readability
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1012%2Fazeemba%2Fautoprompt-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1012/azeemba/autoprompt-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/1012
Range-diff vs v2:
1: 5819b872356 ! 1: f3f38f0d141 help.c: help.autocorrect=prompt waits for user action
@@ Commit message
Based on original patch by David Barr
https://lore.kernel.org/git/1283758030-13345-1-git-send-email-david.barr@cordelta.com/
+ Reviewed-by: Bagas Sanjaya [off-list ref]
Signed-off-by: Azeem Bande-Ali [off-list ref]
## Documentation/config/help.txt ##
@@ help.c: const char *help_unknown_cmd(const char *cmd)
assumed);
- else {
+ else if (autocorrect == AUTOCORRECT_PROMPT) {
-+ char* answer;
++ char *answer;
+ struct strbuf msg = STRBUF_INIT;
-+ strbuf_addf(&msg, _("Run '%s' instead? (y/N)"),
-+ assumed);
++ strbuf_addf(&msg, _("Run '%s' instead? (y/N)"), assumed);
+ answer = git_prompt(msg.buf, PROMPT_ECHO);
+ strbuf_release(&msg);
+ if (!(starts_with(answer, "y") ||
Documentation/config/help.txt | 16 +++++++++-------
help.c | 21 ++++++++++++++++++++-
2 files changed, 29 insertions(+), 8 deletions(-)
@@ -9,13 +9,15 @@ help.format:: help.autoCorrect:: If git detects typos and can identify exactly one valid command similar- to the error, git will automatically run the intended command after- waiting a duration of time defined by this configuration value in- deciseconds (0.1 sec). If this value is 0, the suggested corrections- will be shown, but not executed. If it is a negative integer, or- "immediate", the suggested command- is run immediately. If "never", suggestions are not shown at all. The- default value is zero.+ to the error, git will try to suggest the correct command or even+ run the suggestion automatically. Possible config values are:+ - 0 (default): show the suggested command.+ - positive number: run the suggested command after specified+deciseconds (0.1 sec).+ - "immediate": run the suggested command immediately.+ - "prompt": show the suggestion and prompt for confirmation to run+the command.+ - "never": don't run or show any suggested command. help.htmlPath:: Specify the path where the HTML documentation resides. File system paths
@@ -539,6 +543,12 @@ const char *help_unknown_cmd(const char *cmd)read_early_config(git_unknown_cmd_config,NULL);+/*+*Disableautocorrectionpromptinanon-interactivesession+*/+if((autocorrect==AUTOCORRECT_PROMPT)&&(!isatty(0)||!isatty(2)))+autocorrect=AUTOCORRECT_NEVER;+if(autocorrect==AUTOCORRECT_NEVER){fprintf_ln(stderr,_("git: '%s' is not a git command. See 'git --help'."),cmd);exit(1);
@@ -618,7 +628,16 @@ const char *help_unknown_cmd(const char *cmd)_("Continuing under the assumption that ""you meant '%s'."),assumed);-else{+elseif(autocorrect==AUTOCORRECT_PROMPT){+char*answer;+structstrbufmsg=STRBUF_INIT;+strbuf_addf(&msg,_("Run '%s' instead? (y/N)"),assumed);+answer=git_prompt(msg.buf,PROMPT_ECHO);+strbuf_release(&msg);+if(!(starts_with(answer,"y")||+starts_with(answer,"Y")))+exit(1);+}else{fprintf_ln(stderr,_("Continuing in %0.1f seconds, ""assuming that you meant '%s'."),