aboutsummaryrefslogtreecommitdiffstats
path: root/t/t0018-advice.sh
blob: 29306b367c11e762f2dafd1e2d1bcfa2d76f9d32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/sh

test_description='Test advise_if_enabled functionality'

GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=trunk
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME

TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh

test_expect_success 'advice should be printed when config variable is unset' '
	cat >expect <<-\EOF &&
	hint: This is a piece of advice
	hint: Disable this message with "git config advice.nestedTag false"
	EOF
	test-tool advise "This is a piece of advice" 2>actual &&
	test_cmp expect actual
'

test_expect_success 'advice should be printed when config variable is set to true' '
	cat >expect <<-\EOF &&
	hint: This is a piece of advice
	EOF
	test_config advice.nestedTag true &&
	test-tool advise "This is a piece of advice" 2>actual &&
	test_cmp expect actual
'

test_expect_success 'advice should not be printed when config variable is set to false' '
	test_config advice.nestedTag false &&
	test-tool advise "This is a piece of advice" 2>actual &&
	test_must_be_empty actual
'

test_expect_success 'advice should not be printed when --no-advice is used' '
	q_to_tab >expect <<-\EOF &&
	On branch trunk

	No commits yet

	Untracked files:
	QREADME

	nothing added to commit but untracked files present
	EOF

	test_when_finished "rm -fr advice-test" &&
	git init advice-test &&
	(
		cd advice-test &&
		>README &&
		git --no-advice status
	) >actual &&
	test_cmp expect actual
'

test_expect_success 'advice should not be printed when GIT_ADVICE is set to false' '
	q_to_tab >expect <<-\EOF &&
	On branch trunk

	No commits yet

	Untracked files:
	QREADME

	nothing added to commit but untracked files present
	EOF

	test_when_finished "rm -fr advice-test" &&
	git init advice-test &&
	(
		cd advice-test &&
		>README &&
		GIT_ADVICE=false git status
	) >actual &&
	test_cmp expect actual
'

test_expect_success 'advice should be printed when GIT_ADVICE is set to true' '
	q_to_tab >expect <<-\EOF &&
	On branch trunk

	No commits yet

	Untracked files:
	  (use "git add <file>..." to include in what will be committed)
	QREADME

	nothing added to commit but untracked files present (use "git add" to track)
	EOF

	test_when_finished "rm -fr advice-test" &&
	git init advice-test &&
	(
		cd advice-test &&
		>README &&
		GIT_ADVICE=true git status
	) >actual &&
	cat actual > /tmp/actual &&
	test_cmp expect actual
'

test_done