]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9003-help-autocorrect.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t9003-help-autocorrect.sh
CommitLineData
9d1d2b7f
JH
1#!/bin/sh
2
3test_description='help.autocorrect finding a match'
03267e86
ÆAB
4
5TEST_PASSES_SANITIZE_LEAK=true
9d1d2b7f
JH
6. ./test-lib.sh
7
8test_expect_success 'setup' '
9 # An alias
10 git config alias.lgf "log --format=%s --first-parent" &&
11
12 # A random user-defined command
13 write_script git-distimdistim <<-EOF &&
14 echo distimdistim was called
15 EOF
16
17 PATH="$PATH:." &&
18 export PATH &&
19
20 git commit --allow-empty -m "a single log entry" &&
21
22 # Sanity check
23 git lgf >actual &&
24 echo "a single log entry" >expect &&
25 test_cmp expect actual &&
26
27 git distimdistim >actual &&
28 echo "distimdistim was called" >expect &&
29 test_cmp expect actual
30'
31
32test_expect_success 'autocorrect showing candidates' '
33 git config help.autocorrect 0 &&
34
35 test_must_fail git lfg 2>actual &&
f9b32424 36 grep "^ lgf" actual &&
9d1d2b7f
JH
37
38 test_must_fail git distimdist 2>actual &&
f9b32424 39 grep "^ distimdistim" actual
9d1d2b7f
JH
40'
41
644bb953
DD
42for immediate in -1 immediate
43do
44 test_expect_success 'autocorrect running commands' '
45 git config help.autocorrect $immediate &&
9d1d2b7f 46
644bb953
DD
47 git lfg >actual &&
48 echo "a single log entry" >expect &&
49 test_cmp expect actual &&
9d1d2b7f 50
644bb953
DD
51 git distimdist >actual &&
52 echo "distimdistim was called" >expect &&
53 test_cmp expect actual
54 '
55done
56
57test_expect_success 'autocorrect can be declined altogether' '
58 git config help.autocorrect never &&
59
60 test_must_fail git lfg 2>actual &&
b1e07980
ÆAB
61 grep "is not a git command" actual &&
62 test_line_count = 1 actual
9d1d2b7f
JH
63'
64
0918d088
SG
65test_expect_success 'autocorrect works in work tree created from bare repo' '
66 git clone --bare . bare.git &&
67 git -C bare.git worktree add ../worktree &&
68 git -C worktree -c help.autocorrect=immediate stauts
69'
70
9d1d2b7f 71test_done