From: Derrick Stolee <derrickstolee@xxxxxxxxxx> Several tests validate the exact output of stderr, including when the stderr file should be empty. In advance of modifying the advice system to only output when stderr is a terminal, force the advice system to output in these cases. Signed-off-by: Derrick Stolee <derrickstolee@xxxxxxxxxx> --- t/t1092-sparse-checkout-compatibility.sh | 18 ++++++++-------- t/t2020-checkout-detach.sh | 25 ++++++++++++++--------- t/t2024-checkout-dwim.sh | 5 +++-- t/t2060-switch.sh | 4 ++-- t/t2204-add-ignored.sh | 8 ++++---- t/t2400-worktree-add.sh | 12 +++++------ t/t7500-commit-template-squash-signoff.sh | 3 ++- 7 files changed, 41 insertions(+), 34 deletions(-) diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index a2c0e1b4dcc..b5183ea7c83 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -411,10 +411,10 @@ test_expect_success 'add outside sparse cone' ' run_on_sparse mkdir folder1 && run_on_sparse ../edit-contents folder1/a && run_on_sparse ../edit-contents folder1/newfile && - test_sparse_match test_must_fail git add folder1/a && + test_env GIT_ADVICE=1 test_sparse_match test_must_fail git add folder1/a && grep "Disable or modify the sparsity rules" sparse-checkout-err && test_sparse_unstaged folder1/a && - test_sparse_match test_must_fail git add folder1/newfile && + test_env GIT_ADVICE=1 test_sparse_match test_must_fail git add folder1/newfile && grep "Disable or modify the sparsity rules" sparse-checkout-err && test_sparse_unstaged folder1/newfile ' @@ -466,13 +466,13 @@ test_expect_success 'status/add: outside sparse cone' ' test_sparse_match git status --porcelain=v2 && # Adding the path outside of the sparse-checkout cone should fail. - test_sparse_match test_must_fail git add folder1/a && + test_env GIT_ADVICE=1 test_sparse_match test_must_fail git add folder1/a && grep "Disable or modify the sparsity rules" sparse-checkout-err && test_sparse_unstaged folder1/a && test_all_match git add --refresh folder1/a && test_must_be_empty sparse-checkout-err && test_sparse_unstaged folder1/a && - test_sparse_match test_must_fail git add folder1/new && + test_env GIT_ADVICE=1 test_sparse_match test_must_fail git add folder1/new && grep "Disable or modify the sparsity rules" sparse-checkout-err && test_sparse_unstaged folder1/new && test_sparse_match git add --sparse folder1/a && @@ -1018,7 +1018,7 @@ test_expect_success 'merge with conflict outside cone' ' test_all_match git status --porcelain=v2 && # 2. Add the file with conflict markers - test_sparse_match test_must_fail git add folder1/a && + test_env GIT_ADVICE=1 test_sparse_match test_must_fail git add folder1/a && grep "Disable or modify the sparsity rules" sparse-checkout-err && test_sparse_unstaged folder1/a && test_all_match git add --sparse folder1/a && @@ -1027,7 +1027,7 @@ test_expect_success 'merge with conflict outside cone' ' # 3. Rename the file to another sparse filename and # accept conflict markers as resolved content. run_on_all mv folder2/a folder2/z && - test_sparse_match test_must_fail git add folder2 && + test_env GIT_ADVICE=1 test_sparse_match test_must_fail git add folder2 && grep "Disable or modify the sparsity rules" sparse-checkout-err && test_sparse_unstaged folder2/z && test_all_match git add --sparse folder2 && @@ -1058,7 +1058,7 @@ test_expect_success 'cherry-pick/rebase with conflict outside cone' ' # NEEDSWORK: Even though the merge conflict removed the # SKIP_WORKTREE bit from the index entry for folder1/a, we should # warn that this is a problematic add. - test_sparse_match test_must_fail git add folder1/a && + test_env GIT_ADVICE=1 test_sparse_match test_must_fail git add folder1/a && grep "Disable or modify the sparsity rules" sparse-checkout-err && test_sparse_unstaged folder1/a && test_all_match git add --sparse folder1/a && @@ -1070,7 +1070,7 @@ test_expect_success 'cherry-pick/rebase with conflict outside cone' ' # outside of the sparse-checkout cone and does not match an # existing index entry with the SKIP_WORKTREE bit cleared. run_on_all mv folder2/a folder2/z && - test_sparse_match test_must_fail git add folder2 && + test_env GIT_ADVICE=1 test_sparse_match test_must_fail git add folder2 && grep "Disable or modify the sparsity rules" sparse-checkout-err && test_sparse_unstaged folder2/z && test_all_match git add --sparse folder2 && @@ -2341,7 +2341,7 @@ test_expect_success 'advice.sparseIndexExpanded' ' git -C sparse-index sparse-checkout set deep/deeper1 && mkdir -p sparse-index/deep/deeper2/deepest && touch sparse-index/deep/deeper2/deepest/bogus && - git -C sparse-index status 2>err && + GIT_ADVICE=1 git -C sparse-index status 2>err && grep "The sparse index is expanding to a full index" err ' diff --git a/t/t2020-checkout-detach.sh b/t/t2020-checkout-detach.sh index 8d90d028504..43ee72b19bd 100755 --- a/t/t2020-checkout-detach.sh +++ b/t/t2020-checkout-detach.sh @@ -175,7 +175,7 @@ test_expect_success 'tracking count is accurate after orphan check' ' git config branch.child.remote . && git config branch.child.merge refs/heads/main && git checkout child^ && - git checkout child >stdout && + GIT_ADVICE=1 git checkout child >stdout && test_cmp expect stdout && git checkout --detach child >stdout && @@ -251,15 +251,17 @@ test_expect_success 'describe_detached_head prints no SHA-1 ellipsis when not as # Various ways of *not* asking for ellipses sane_unset GIT_PRINT_SHA1_ELLIPSIS && - git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 && + GIT_ADVICE=1 git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 && check_detached && test_cmp 1st_detach actual && - GIT_PRINT_SHA1_ELLIPSIS="no" git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 && + GIT_ADVICE=1 GIT_PRINT_SHA1_ELLIPSIS="no" git -c 'core.abbrev=12' \ + checkout HEAD^ >actual 2>&1 && check_detached && test_cmp 2nd_detach actual && - GIT_PRINT_SHA1_ELLIPSIS= git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 && + GIT_ADVICE=1 GIT_PRINT_SHA1_ELLIPSIS= git -c 'core.abbrev=12' \ + checkout HEAD^ >actual 2>&1 && check_detached && test_cmp 3rd_detach actual && @@ -270,17 +272,17 @@ test_expect_success 'describe_detached_head prints no SHA-1 ellipsis when not as check_not_detached && # Make no mention of the env var at all - git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 && + GIT_ADVICE=1 git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 && check_detached && test_cmp 1st_detach actual && GIT_PRINT_SHA1_ELLIPSIS='nope' && - git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 && + GIT_ADVICE=1 git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 && check_detached && test_cmp 2nd_detach actual && GIT_PRINT_SHA1_ELLIPSIS=nein && - git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 && + GIT_ADVICE=1 git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 && check_detached && test_cmp 3rd_detach actual && @@ -333,15 +335,18 @@ test_expect_success 'describe_detached_head does print SHA-1 ellipsis when asked # Various ways of asking for ellipses... # The user can just use any kind of quoting (including none). - GIT_PRINT_SHA1_ELLIPSIS=yes git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 && + GIT_ADVICE=1 GIT_PRINT_SHA1_ELLIPSIS=yes git -c 'core.abbrev=12' \ + checkout HEAD^ >actual 2>&1 && check_detached && test_cmp 1st_detach actual && - GIT_PRINT_SHA1_ELLIPSIS=Yes git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 && + GIT_ADVICE=1 GIT_PRINT_SHA1_ELLIPSIS=Yes git -c 'core.abbrev=12' \ + checkout HEAD^ >actual 2>&1 && check_detached && test_cmp 2nd_detach actual && - GIT_PRINT_SHA1_ELLIPSIS=YES git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 && + GIT_ADVICE=1 GIT_PRINT_SHA1_ELLIPSIS=YES git -c 'core.abbrev=12' \ + checkout HEAD^ >actual 2>&1 && check_detached && test_cmp 3rd_detach actual && diff --git a/t/t2024-checkout-dwim.sh b/t/t2024-checkout-dwim.sh index 2caada3d834..56be88b1620 100755 --- a/t/t2024-checkout-dwim.sh +++ b/t/t2024-checkout-dwim.sh @@ -103,11 +103,12 @@ test_expect_success 'when arg matches multiple remotes, do not fallback to inter test_expect_success 'checkout of branch from multiple remotes fails with advice' ' git checkout -B main && test_might_fail git branch -D foo && - test_must_fail git checkout foo 2>stderr && + test_env GIT_ADVICE=1 test_must_fail git checkout foo 2>stderr && test_branch main && status_uno_is_clean && test_grep "^hint: " stderr && - test_must_fail git -c advice.checkoutAmbiguousRemoteBranchName=false \ + test_env GIT_ADVICE=1 test_must_fail git \ + -c advice.checkoutAmbiguousRemoteBranchName=false \ checkout foo 2>stderr && test_branch main && status_uno_is_clean && diff --git a/t/t2060-switch.sh b/t/t2060-switch.sh index 77b2346291b..d84b3accf0e 100755 --- a/t/t2060-switch.sh +++ b/t/t2060-switch.sh @@ -34,13 +34,13 @@ test_expect_success 'switch and detach' ' ' test_expect_success 'suggestion to detach' ' - test_must_fail git switch main^{commit} 2>stderr && + test_env GIT_ADVICE=1 test_must_fail git switch main^{commit} 2>stderr && grep "try again with the --detach option" stderr ' test_expect_success 'suggestion to detach is suppressed with advice.suggestDetachingHead=false' ' test_config advice.suggestDetachingHead false && - test_must_fail git switch main^{commit} 2>stderr && + test_env GIT_ADVICE=1 test_must_fail git switch main^{commit} 2>stderr && ! grep "try again with the --detach option" stderr ' diff --git a/t/t2204-add-ignored.sh b/t/t2204-add-ignored.sh index b7cf1e492c1..ca46bbd22c7 100755 --- a/t/t2204-add-ignored.sh +++ b/t/t2204-add-ignored.sh @@ -30,7 +30,7 @@ for i in ign dir/ign dir/sub dir/sub/*ign sub/file sub sub/* do test_expect_success "complaints for ignored $i" ' rm -f .git/index && - test_must_fail git add "$i" 2>err && + test_env GIT_ADVICE=1 test_must_fail git add "$i" 2>err && git ls-files "$i" >out && test_must_be_empty out ' @@ -41,7 +41,7 @@ do test_expect_success "complaints for ignored $i with unignored file" ' rm -f .git/index && - test_must_fail git add "$i" file 2>err && + test_env GIT_ADVICE=1 test_must_fail git add "$i" file 2>err && git ls-files "$i" >out && test_must_be_empty out ' @@ -56,7 +56,7 @@ do rm -f .git/index && ( cd dir && - test_must_fail git add "$i" 2>err && + test_env GIT_ADVICE=1 test_must_fail git add "$i" 2>err && git ls-files "$i" >out && test_must_be_empty out ) @@ -76,7 +76,7 @@ do rm -f .git/index && ( cd sub && - test_must_fail git add "$i" 2>err && + test_env GIT_ADVICE=1 test_must_fail git add "$i" 2>err && git ls-files "$i" >out && test_must_be_empty out ) diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh index cfc4aeb1798..742002ff41e 100755 --- a/t/t2400-worktree-add.sh +++ b/t/t2400-worktree-add.sh @@ -436,7 +436,7 @@ test_wt_add_orphan_hint () { git init repo && (cd repo && test_commit commit) && git -C repo switch --orphan noref && - test_must_fail git -C repo worktree add $opts foobar/ 2>actual && + test_env GIT_ADVICE=1 test_must_fail git -C repo worktree add $opts foobar/ 2>actual && ! grep "error: unknown switch" actual && grep "hint: If you meant to create a worktree containing a new unborn branch" actual && if [ $use_branch -eq 1 ] @@ -983,7 +983,7 @@ test_dwim_orphan () { fi && if [ "$outcome" = "infer" ] then - git $dashc_args worktree add $args 2>actual && + GIT_ADVICE=1 git $dashc_args worktree add $args 2>actual && if [ $use_quiet -eq 1 ] then test_must_be_empty actual @@ -992,7 +992,7 @@ test_dwim_orphan () { fi elif [ "$outcome" = "no_infer" ] then - git $dashc_args worktree add $args 2>actual && + GIT_ADVICE=1 git $dashc_args worktree add $args 2>actual && if [ $use_quiet -eq 1 ] then test_must_be_empty actual @@ -1001,11 +1001,11 @@ test_dwim_orphan () { fi elif [ "$outcome" = "fetch_error" ] then - test_must_fail git $dashc_args worktree add $args 2>actual && + test_env GIT_ADVICE=1 test_must_fail git $dashc_args worktree add $args 2>actual && grep "$fetch_error_text" actual elif [ "$outcome" = "fatal_orphan_bad_combo" ] then - test_must_fail git $dashc_args worktree add $args 2>actual && + test_env GIT_ADVICE=1 test_must_fail git $dashc_args worktree add $args 2>actual && if [ $use_quiet -eq 1 ] then ! grep "$info_text" actual @@ -1015,7 +1015,7 @@ test_dwim_orphan () { grep "$bad_combo_regex" actual elif [ "$outcome" = "warn_bad_head" ] then - test_must_fail git $dashc_args worktree add $args 2>actual && + test_env GIT_ADVICE=1 test_must_fail git $dashc_args worktree add $args 2>actual && if [ $use_quiet -eq 1 ] then grep "$invalid_ref_regex" actual && diff --git a/t/t7500-commit-template-squash-signoff.sh b/t/t7500-commit-template-squash-signoff.sh index 4dca8d97a77..546b6f2f373 100755 --- a/t/t7500-commit-template-squash-signoff.sh +++ b/t/t7500-commit-template-squash-signoff.sh @@ -554,7 +554,8 @@ test_expect_success 'commit without staging files fails and displays hints' ' git add file && git commit -m initial && echo "changes" >>file && - test_must_fail git commit -m update >actual && + test_env GIT_ADVICE=1 test_must_fail \ + git commit -m update >actual && test_grep "no changes added to commit (use \"git add\" and/or \"git commit -a\")" actual ' -- gitgitgadget