blob: 29306b367c11e762f2dafd1e2d1bcfa2d76f9d32 [file] [log] [blame]
Heba Walyb3b18d12020-03-02 20:01:59 +00001#!/bin/sh
2
3test_description='Test advise_if_enabled functionality'
4
Junio C Hamanocbdc83f2024-05-07 17:40:51 -07005GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=trunk
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
Ævar Arnfjörð Bjarmason956d2e42021-09-23 11:20:46 +02008TEST_PASSES_SANITIZE_LEAK=true
Heba Walyb3b18d12020-03-02 20:01:59 +00009. ./test-lib.sh
10
11test_expect_success 'advice should be printed when config variable is unset' '
12 cat >expect <<-\EOF &&
13 hint: This is a piece of advice
14 hint: Disable this message with "git config advice.nestedTag false"
15 EOF
16 test-tool advise "This is a piece of advice" 2>actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +010017 test_cmp expect actual
Heba Walyb3b18d12020-03-02 20:01:59 +000018'
19
20test_expect_success 'advice should be printed when config variable is set to true' '
21 cat >expect <<-\EOF &&
22 hint: This is a piece of advice
Heba Walyb3b18d12020-03-02 20:01:59 +000023 EOF
24 test_config advice.nestedTag true &&
25 test-tool advise "This is a piece of advice" 2>actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +010026 test_cmp expect actual
Heba Walyb3b18d12020-03-02 20:01:59 +000027'
28
29test_expect_success 'advice should not be printed when config variable is set to false' '
30 test_config advice.nestedTag false &&
31 test-tool advise "This is a piece of advice" 2>actual &&
32 test_must_be_empty actual
33'
34
James Liub79deeb2024-05-03 17:17:06 +100035test_expect_success 'advice should not be printed when --no-advice is used' '
36 q_to_tab >expect <<-\EOF &&
Junio C Hamanocbdc83f2024-05-07 17:40:51 -070037 On branch trunk
James Liub79deeb2024-05-03 17:17:06 +100038
Junio C Hamanocbdc83f2024-05-07 17:40:51 -070039 No commits yet
James Liub79deeb2024-05-03 17:17:06 +100040
Junio C Hamanocbdc83f2024-05-07 17:40:51 -070041 Untracked files:
42 QREADME
James Liub79deeb2024-05-03 17:17:06 +100043
Junio C Hamanocbdc83f2024-05-07 17:40:51 -070044 nothing added to commit but untracked files present
45 EOF
James Liub79deeb2024-05-03 17:17:06 +100046
47 test_when_finished "rm -fr advice-test" &&
48 git init advice-test &&
49 (
50 cd advice-test &&
51 >README &&
52 git --no-advice status
53 ) >actual &&
54 test_cmp expect actual
55'
56
57test_expect_success 'advice should not be printed when GIT_ADVICE is set to false' '
58 q_to_tab >expect <<-\EOF &&
Junio C Hamanocbdc83f2024-05-07 17:40:51 -070059 On branch trunk
James Liub79deeb2024-05-03 17:17:06 +100060
Junio C Hamanocbdc83f2024-05-07 17:40:51 -070061 No commits yet
James Liub79deeb2024-05-03 17:17:06 +100062
Junio C Hamanocbdc83f2024-05-07 17:40:51 -070063 Untracked files:
64 QREADME
James Liub79deeb2024-05-03 17:17:06 +100065
Junio C Hamanocbdc83f2024-05-07 17:40:51 -070066 nothing added to commit but untracked files present
67 EOF
James Liub79deeb2024-05-03 17:17:06 +100068
69 test_when_finished "rm -fr advice-test" &&
70 git init advice-test &&
71 (
72 cd advice-test &&
73 >README &&
74 GIT_ADVICE=false git status
75 ) >actual &&
76 test_cmp expect actual
77'
78
79test_expect_success 'advice should be printed when GIT_ADVICE is set to true' '
80 q_to_tab >expect <<-\EOF &&
Junio C Hamanocbdc83f2024-05-07 17:40:51 -070081 On branch trunk
James Liub79deeb2024-05-03 17:17:06 +100082
Junio C Hamanocbdc83f2024-05-07 17:40:51 -070083 No commits yet
James Liub79deeb2024-05-03 17:17:06 +100084
Junio C Hamanocbdc83f2024-05-07 17:40:51 -070085 Untracked files:
86 (use "git add <file>..." to include in what will be committed)
87 QREADME
James Liub79deeb2024-05-03 17:17:06 +100088
Junio C Hamanocbdc83f2024-05-07 17:40:51 -070089 nothing added to commit but untracked files present (use "git add" to track)
90 EOF
James Liub79deeb2024-05-03 17:17:06 +100091
92 test_when_finished "rm -fr advice-test" &&
93 git init advice-test &&
94 (
95 cd advice-test &&
96 >README &&
97 GIT_ADVICE=true git status
98 ) >actual &&
99 cat actual > /tmp/actual &&
100 test_cmp expect actual
101'
102
Heba Walyb3b18d12020-03-02 20:01:59 +0000103test_done