Skip to content

Commit 2d7a874

Browse files
committed
Merge branch 'da/help-autocorrect-one-fix'
"git -c help.autocorrect=0 psuh" shows the suggested typofix, unlike the previous attempt in the base topic. * da/help-autocorrect-one-fix: help: add "show" as a valid configuration value help: show the suggested command when help.autocorrect is false
2 parents 39de0ff + e4542d8 commit 2d7a874

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

Documentation/config/help.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ help.autoCorrect::
1111
If git detects typos and can identify exactly one valid command similar
1212
to the error, git will try to suggest the correct command or even
1313
run the suggestion automatically. Possible config values are:
14-
- 0: show the suggested command (default).
14+
- 0, "false", "off", "no", "show": show the suggested command (default).
1515
- 1, "true", "on", "yes", "immediate": run the suggested command
1616
immediately.
1717
- positive number > 1: run the suggested command after specified
1818
deciseconds (0.1 sec).
19-
- "false", "off", "no", "never": don't run or show any suggested command.
19+
- "never": don't run or show any suggested command.
2020
- "prompt": show the suggestion and prompt for confirmation to run
2121
the command.
2222

help.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ struct help_unknown_cmd_config {
552552
struct cmdnames aliases;
553553
};
554554

555+
#define AUTOCORRECT_SHOW (-4)
555556
#define AUTOCORRECT_PROMPT (-3)
556557
#define AUTOCORRECT_NEVER (-2)
557558
#define AUTOCORRECT_IMMEDIATELY (-1)
@@ -562,7 +563,7 @@ static int parse_autocorrect(const char *value)
562563
case 1:
563564
return AUTOCORRECT_IMMEDIATELY;
564565
case 0:
565-
return AUTOCORRECT_NEVER;
566+
return AUTOCORRECT_SHOW;
566567
default: /* other random text */
567568
break;
568569
}
@@ -573,6 +574,8 @@ static int parse_autocorrect(const char *value)
573574
return AUTOCORRECT_NEVER;
574575
if (!strcmp(value, "immediate"))
575576
return AUTOCORRECT_IMMEDIATELY;
577+
if (!strcmp(value, "show"))
578+
return AUTOCORRECT_SHOW;
576579

577580
return 0;
578581
}
@@ -713,7 +716,8 @@ char *help_unknown_cmd(const char *cmd)
713716
n++)
714717
; /* still counting */
715718
}
716-
if (cfg.autocorrect && n == 1 && SIMILAR_ENOUGH(best_similarity)) {
719+
if (cfg.autocorrect && cfg.autocorrect != AUTOCORRECT_SHOW && n == 1 &&
720+
SIMILAR_ENOUGH(best_similarity)) {
717721
char *assumed = xstrdup(main_cmds.names[0]->name);
718722

719723
fprintf_ln(stderr,

t/t9003-help-autocorrect.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@ test_expect_success 'setup' '
2828
test_cmp expect actual
2929
'
3030

31-
test_expect_success 'autocorrect showing candidates' '
32-
git config help.autocorrect 0 &&
31+
for show in false no off 0 show
32+
do
33+
test_expect_success 'autocorrect showing candidates' '
34+
git config help.autocorrect $show &&
3335
34-
test_must_fail git lfg 2>actual &&
35-
grep "^ lgf" actual &&
36+
test_must_fail git lfg 2>actual &&
37+
grep "^ lgf" actual &&
3638
37-
test_must_fail git distimdist 2>actual &&
38-
grep "^ distimdistim" actual
39-
'
39+
test_must_fail git distimdist 2>actual &&
40+
grep "^ distimdistim" actual
41+
'
42+
done
4043

4144
for immediate in -1 immediate
4245
do

0 commit comments

Comments
 (0)