git/t/t0018-advice.sh
James Liu b79deeb554 advice: add --no-advice global option
Advice hints must be disabled individually by setting the relevant
advice.* variables to false in the Git configuration. For server-side
and scripted usages of Git where hints can be a hindrance, it can be
cumbersome to maintain configuration to ensure all advice hints are
disabled in perpetuity. This is a particular concern in tests, where
new or changed hints can result in failed assertions.

Add a --no-advice global option to disable all advice hints from being
displayed. This is independent of the toggles for individual advice
hints. Use an internal environment variable (GIT_ADVICE) to ensure this
configuration is propagated to the usage site, even if it executes in a
subprocess.

Signed-off-by: James Liu <james@jamesliu.io>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-05-03 10:36:59 -07:00

101 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
test_description='Test advise_if_enabled functionality'
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 master
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 master
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 master
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