Raw
1 #!/bin/sh
2
3 test_description='Test advise_if_enabled functionality'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=trunk
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 test_expect_success 'advice should be printed when config variable is unset' '
11 cat >expect <<-\EOF &&
12 hint: This is a piece of advice
13 hint: Disable this message with "git config set advice.nestedTag false"
14 EOF
15 test-tool advise "This is a piece of advice" 2>actual &&
16 test_cmp expect actual
17 '
18
19 test_expect_success 'advice should be printed when config variable is set to true' '
20 cat >expect <<-\EOF &&
21 hint: This is a piece of advice
22 EOF
23 test_config advice.nestedTag true &&
24 test-tool advise "This is a piece of advice" 2>actual &&
25 test_cmp expect actual
26 '
27
28 test_expect_success 'advice should not be printed when config variable is set to false' '
29 test_config advice.nestedTag false &&
30 test-tool advise "This is a piece of advice" 2>actual &&
31 test_must_be_empty actual
32 '
33
34 test_expect_success 'advice should not be printed when --no-advice is used' '
35 q_to_tab >expect <<-\EOF &&
36 On branch trunk
37
38 No commits yet
39
40 Untracked files:
41 QREADME
42
43 nothing added to commit but untracked files present
44 EOF
45
46 test_when_finished "rm -fr advice-test" &&
47 git init advice-test &&
48 (
49 cd advice-test &&
50 >README &&
51 git --no-advice status
52 ) >actual &&
53 test_cmp expect actual
54 '
55
56 test_expect_success 'advice should not be printed when GIT_ADVICE is set to false' '
57 q_to_tab >expect <<-\EOF &&
58 On branch trunk
59
60 No commits yet
61
62 Untracked files:
63 QREADME
64
65 nothing added to commit but untracked files present
66 EOF
67
68 test_when_finished "rm -fr advice-test" &&
69 git init advice-test &&
70 (
71 cd advice-test &&
72 >README &&
73 GIT_ADVICE=false git status
74 ) >actual &&
75 test_cmp expect actual
76 '
77
78 test_expect_success 'advice should be printed when GIT_ADVICE is set to true' '
79 q_to_tab >expect <<-\EOF &&
80 On branch trunk
81
82 No commits yet
83
84 Untracked files:
85 (use "git add <file>..." to include in what will be committed)
86 QREADME
87
88 nothing added to commit but untracked files present (use "git add" to track)
89 EOF
90
91 test_when_finished "rm -fr advice-test" &&
92 git init advice-test &&
93 (
94 cd advice-test &&
95 >README &&
96 GIT_ADVICE=true git status
97 ) >actual &&
98 test_cmp expect actual
99 '
100
101 test_done