Skip to content

Commit e21bf2c

Browse files
davvidgitster
authored andcommitted
help: show the suggested command when help.autocorrect is false
Make the handling of false boolean values for help.autocorrect consistent with the handling of value 0 by showing the suggested commands but not running them. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent a0fc18f commit e21bf2c

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-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 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: 4 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
}
@@ -713,7 +714,8 @@ char *help_unknown_cmd(const char *cmd)
713714
n++)
714715
; /* still counting */
715716
}
716-
if (cfg.autocorrect && n == 1 && SIMILAR_ENOUGH(best_similarity)) {
717+
if (cfg.autocorrect && cfg.autocorrect != AUTOCORRECT_SHOW && n == 1 &&
718+
SIMILAR_ENOUGH(best_similarity)) {
717719
char *assumed = xstrdup(main_cmds.names[0]->name);
718720

719721
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
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)