@@ -1,8 +1,11 @@
advice.*::
These variables control various optional help messages designed to
- aid new users. When left unconfigured, Git will give the message
- alongside instructions on how to squelch it. You can tell Git
- that you do not need the help message by setting these to `false`:
+ aid new users. These are only output to `stderr` when it is a
+ terminal.
++
+When left unconfigured, Git will give the message alongside instructions
+on how to squelch it. You can tell Git that you do not need the help
+message by setting these to `false`:
+
--
addEmbeddedRepo::
@@ -133,7 +133,9 @@ int advice_enabled(enum advice_type type)
static int globally_enabled = -1;
if (globally_enabled < 0)
- globally_enabled = git_env_bool(GIT_ADVICE_ENVIRONMENT, 1);
+ globally_enabled = git_env_bool(GIT_ADVICE_ENVIRONMENT, -1);
+ if (globally_enabled < 0)
+ globally_enabled = isatty(2);
if (!globally_enabled)
return 0;
@@ -8,7 +8,7 @@ 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' '
+test_expect_success TTY '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"
@@ -17,7 +17,7 @@ test_expect_success 'advice should be printed when config variable is unset' '
test_cmp expect actual
'
-test_expect_success 'advice should be printed when config variable is set to true' '
+test_expect_success TTY 'advice should be printed when config variable is set to true' '
cat >expect <<-\EOF &&
hint: This is a piece of advice
EOF
@@ -26,13 +26,13 @@ test_expect_success 'advice should be printed when config variable is set to tru
test_cmp expect actual
'
-test_expect_success 'advice should not be printed when config variable is set to false' '
+test_expect_success TTY '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' '
+test_expect_success TTY 'advice should not be printed when --no-advice is used' '
q_to_tab >expect <<-\EOF &&
On branch trunk
@@ -54,7 +54,7 @@ test_expect_success 'advice should not be printed when --no-advice is used' '
test_cmp expect actual
'
-test_expect_success 'advice should not be printed when GIT_ADVICE is set to false' '
+test_expect_success TTY 'advice should not be printed when GIT_ADVICE is set to false' '
q_to_tab >expect <<-\EOF &&
On branch trunk
@@ -76,6 +76,8 @@ test_expect_success 'advice should not be printed when GIT_ADVICE is set to fals
test_cmp expect actual
'
+# This test also verifies that GIT_ADVICE=1 ignores the requirement
+# that stderr is a terminal.
test_expect_success 'advice should be printed when GIT_ADVICE is set to true' '
q_to_tab >expect <<-\EOF &&
On branch trunk
@@ -99,4 +101,10 @@ test_expect_success 'advice should be printed when GIT_ADVICE is set to true' '
test_cmp expect actual
'
+test_expect_success 'advice should not be printed when stderr is not a terminal' '
+ test_config advice.nestedTag true &&
+ test-tool advise "This is a piece of advice" 2>actual &&
+ test_must_be_empty actual
+'
+
test_done