Skip to content

Commit

Permalink
t7000: add GIT_ADVICE=1 to advice tests
Browse files Browse the repository at this point in the history
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.

In addition, two more edits were made while in the neighborhood:

 1. In t7002, a redirected stderr was ignored and is now checked as empty.

 2. In t7400, a command was checked for failure with "!" but is now checked
    via test_must_fail.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
  • Loading branch information
derrickstolee committed Aug 21, 2024
1 parent e169160 commit d1d31aa
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 53 deletions.
85 changes: 43 additions & 42 deletions t/t7002-mv-sparse-checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ test_expect_success 'mv refuses to move sparse-to-sparse' '
git reset --hard &&
git sparse-checkout set --no-cone a &&
touch b &&
test_must_fail git mv b e 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv b e 2>stderr &&
cat sparse_error_header >expect &&
echo b >>expect &&
echo e >>expect &&
cat sparse_hint >>expect &&
test_cmp expect stderr &&
git mv --sparse b e 2>stderr &&
GIT_ADVICE=1 git mv --sparse b e 2>stderr &&
test_must_be_empty stderr
'

Expand All @@ -72,7 +72,7 @@ test_expect_success 'mv refuses to move sparse-to-sparse, ignores failure' '
# tracked-to-untracked
touch b &&
git mv -k b e 2>stderr &&
GIT_ADVICE=1 git mv -k b e 2>stderr &&
test_path_exists b &&
test_path_is_missing e &&
cat sparse_error_header >expect &&
Expand All @@ -81,15 +81,15 @@ test_expect_success 'mv refuses to move sparse-to-sparse, ignores failure' '
cat sparse_hint >>expect &&
test_cmp expect stderr &&
git mv --sparse b e 2>stderr &&
GIT_ADVICE=1 git mv --sparse b e 2>stderr &&
test_must_be_empty stderr &&
test_path_is_missing b &&
test_path_exists e &&
# tracked-to-tracked
git reset --hard &&
touch b &&
git mv -k b c 2>stderr &&
GIT_ADVICE=1 git mv -k b c 2>stderr &&
test_path_exists b &&
test_path_is_missing c &&
cat sparse_error_header >expect &&
Expand All @@ -98,7 +98,7 @@ test_expect_success 'mv refuses to move sparse-to-sparse, ignores failure' '
cat sparse_hint >>expect &&
test_cmp expect stderr &&
git mv --sparse b c 2>stderr &&
GIT_ADVICE=1 git mv --sparse b c 2>stderr &&
test_must_be_empty stderr &&
test_path_is_missing b &&
test_path_exists c
Expand All @@ -110,29 +110,29 @@ test_expect_success 'mv refuses to move non-sparse-to-sparse' '
git sparse-checkout set a &&
# tracked-to-untracked
test_must_fail git mv a e 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv a e 2>stderr &&
test_path_exists a &&
test_path_is_missing e &&
cat sparse_error_header >expect &&
echo e >>expect &&
cat sparse_hint >>expect &&
test_cmp expect stderr &&
git mv --sparse a e 2>stderr &&
GIT_ADVICE=1 git mv --sparse a e 2>stderr &&
test_must_be_empty stderr &&
test_path_is_missing a &&
test_path_exists e &&
# tracked-to-tracked
rm e &&
git reset --hard &&
test_must_fail git mv a c 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv a c 2>stderr &&
test_path_exists a &&
test_path_is_missing c &&
cat sparse_error_header >expect &&
echo c >>expect &&
cat sparse_hint >>expect &&
test_cmp expect stderr &&
git mv --sparse a c 2>stderr &&
GIT_ADVICE=1 git mv --sparse a c 2>stderr &&
test_must_be_empty stderr &&
test_path_is_missing a &&
test_path_exists c
Expand All @@ -145,12 +145,12 @@ test_expect_success 'mv refuses to move sparse-to-non-sparse' '
# tracked-to-untracked
touch b &&
test_must_fail git mv b e 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv b e 2>stderr &&
cat sparse_error_header >expect &&
echo b >>expect &&
cat sparse_hint >>expect &&
test_cmp expect stderr &&
git mv --sparse b e 2>stderr &&
GIT_ADVICE=1 git mv --sparse b e 2>stderr &&
test_must_be_empty stderr
'

Expand All @@ -164,7 +164,7 @@ test_expect_success 'recursive mv refuses to move (possible) sparse' '
mkdir sub/dir2 &&
touch sub/d sub/dir2/e &&
test_must_fail git mv sub sub2 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv sub sub2 2>stderr &&
cat sparse_error_header >expect &&
cat >>expect <<-\EOF &&
sub/d
Expand All @@ -174,7 +174,7 @@ test_expect_success 'recursive mv refuses to move (possible) sparse' '
EOF
cat sparse_hint >>expect &&
test_cmp expect stderr &&
git mv --sparse sub sub2 2>stderr &&
GIT_ADVICE=1 git mv --sparse sub sub2 2>stderr &&
test_must_be_empty stderr &&
git commit -m "moved sub to sub2" &&
git rev-parse HEAD~1:sub >expect &&
Expand All @@ -193,15 +193,15 @@ test_expect_success 'recursive mv refuses to move sparse' '
mkdir sub/dir2 &&
touch sub/dir2/e &&
test_must_fail git mv sub sub2 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv sub sub2 2>stderr &&
cat sparse_error_header >expect &&
cat >>expect <<-\EOF &&
sub/dir2/e
sub2/dir2/e
EOF
cat sparse_hint >>expect &&
test_cmp expect stderr &&
git mv --sparse sub sub2 2>stderr &&
GIT_ADVICE=1 git mv --sparse sub sub2 2>stderr &&
test_must_be_empty stderr &&
git commit -m "moved sub to sub2" &&
git rev-parse HEAD~1:sub >expect &&
Expand All @@ -216,8 +216,9 @@ test_expect_success 'can move files to non-sparse dir' '
git sparse-checkout set a b c w !/x y/ &&
mkdir -p w x/y &&
git mv a w/new-a 2>stderr &&
git mv b x/y/new-b 2>stderr &&
GIT_ADVICE=1 git mv a w/new-a 2>stderr &&
test_must_be_empty stderr &&
GIT_ADVICE=1 git mv b x/y/new-b 2>stderr &&
test_must_be_empty stderr
'

Expand All @@ -228,7 +229,7 @@ test_expect_success 'refuse to move file to non-skip-worktree sparse path' '
git sparse-checkout set a !/x y/ !x/y/z &&
mkdir -p x/y/z &&
test_must_fail git mv a x/y/z/new-a 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv a x/y/z/new-a 2>stderr &&
echo x/y/z/new-a | cat sparse_error_header - sparse_hint >expect &&
test_cmp expect stderr
'
Expand All @@ -237,7 +238,7 @@ test_expect_success 'refuse to move out-of-cone directory without --sparse' '
test_when_finished "cleanup_sparse_checkout" &&
setup_sparse_checkout &&
test_must_fail git mv folder1 sub 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv folder1 sub 2>stderr &&
cat sparse_error_header >expect &&
echo folder1/file1 >>expect &&
cat sparse_hint >>expect &&
Expand All @@ -248,7 +249,7 @@ test_expect_success 'can move out-of-cone directory with --sparse' '
test_when_finished "cleanup_sparse_checkout" &&
setup_sparse_checkout &&
git mv --sparse folder1 sub 2>stderr &&
GIT_ADVICE=1 git mv --sparse folder1 sub 2>stderr &&
test_must_be_empty stderr &&
test_path_is_dir sub/folder1 &&
Expand All @@ -259,7 +260,7 @@ test_expect_success 'refuse to move out-of-cone file without --sparse' '
test_when_finished "cleanup_sparse_checkout" &&
setup_sparse_checkout &&
test_must_fail git mv folder1/file1 sub 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv folder1/file1 sub 2>stderr &&
cat sparse_error_header >expect &&
echo folder1/file1 >>expect &&
cat sparse_hint >>expect &&
Expand All @@ -270,7 +271,7 @@ test_expect_success 'can move out-of-cone file with --sparse' '
test_when_finished "cleanup_sparse_checkout" &&
setup_sparse_checkout &&
git mv --sparse folder1/file1 sub 2>stderr &&
GIT_ADVICE=1 git mv --sparse folder1/file1 sub 2>stderr &&
test_must_be_empty stderr &&
test_path_is_file sub/file1
Expand All @@ -284,7 +285,7 @@ test_expect_success 'refuse to move sparse file to existing destination' '
git add folder1 sub/file1 &&
git sparse-checkout set --cone sub &&
test_must_fail git mv --sparse folder1/file1 sub 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv --sparse folder1/file1 sub 2>stderr &&
echo "fatal: destination exists, source=folder1/file1, destination=sub/file1" >expect &&
test_cmp expect stderr
'
Expand All @@ -298,7 +299,7 @@ test_expect_success 'move sparse file to existing destination with --force and -
git add folder1 sub/file1 &&
git sparse-checkout set --cone sub &&
git mv --sparse --force folder1/file1 sub 2>stderr &&
GIT_ADVICE=1 git mv --sparse --force folder1/file1 sub 2>stderr &&
test_must_be_empty stderr &&
echo "overwrite" >expect &&
test_cmp expect sub/file1
Expand All @@ -308,13 +309,13 @@ test_expect_success 'move clean path from in-cone to out-of-cone' '
test_when_finished "cleanup_sparse_checkout" &&
setup_sparse_checkout &&
test_must_fail git mv sub/d folder1 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv sub/d folder1 2>stderr &&
cat sparse_error_header >expect &&
echo "folder1/d" >>expect &&
cat sparse_hint >>expect &&
test_cmp expect stderr &&
git mv --sparse sub/d folder1 2>stderr &&
GIT_ADVICE=1 git mv --sparse sub/d folder1 2>stderr &&
test_must_be_empty stderr &&
test_path_is_missing sub/d &&
Expand All @@ -330,18 +331,18 @@ test_expect_success 'move clean path from in-cone to out-of-cone overwrite' '
echo "sub/file1 overwrite" >sub/file1 &&
git add sub/file1 &&
test_must_fail git mv sub/file1 folder1 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv sub/file1 folder1 2>stderr &&
cat sparse_error_header >expect &&
echo "folder1/file1" >>expect &&
cat sparse_hint >>expect &&
test_cmp expect stderr &&
test_must_fail git mv --sparse sub/file1 folder1 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv --sparse sub/file1 folder1 2>stderr &&
echo "fatal: destination exists in the index, source=sub/file1, destination=folder1/file1" \
>expect &&
test_cmp expect stderr &&
git mv --sparse -f sub/file1 folder1 2>stderr &&
GIT_ADVICE=1 git mv --sparse -f sub/file1 folder1 2>stderr &&
test_must_be_empty stderr &&
test_path_is_missing sub/file1 &&
Expand All @@ -366,18 +367,18 @@ test_expect_success 'move clean path from in-cone to out-of-cone file overwrite'
echo "sub/file1 overwrite" >sub/file1 &&
git add sub/file1 &&
test_must_fail git mv sub/file1 folder1/file1 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv sub/file1 folder1/file1 2>stderr &&
cat sparse_error_header >expect &&
echo "folder1/file1" >>expect &&
cat sparse_hint >>expect &&
test_cmp expect stderr &&
test_must_fail git mv --sparse sub/file1 folder1/file1 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv --sparse sub/file1 folder1/file1 2>stderr &&
echo "fatal: destination exists in the index, source=sub/file1, destination=folder1/file1" \
>expect &&
test_cmp expect stderr &&
git mv --sparse -f sub/file1 folder1/file1 2>stderr &&
GIT_ADVICE=1 git mv --sparse -f sub/file1 folder1/file1 2>stderr &&
test_must_be_empty stderr &&
test_path_is_missing sub/file1 &&
Expand All @@ -403,19 +404,19 @@ test_expect_success 'move directory with one of the files overwrite' '
echo test >sub/dir/file1 &&
git add sub/dir/file1 &&
test_must_fail git mv sub/dir folder1 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv sub/dir folder1 2>stderr &&
cat sparse_error_header >expect &&
echo "folder1/dir/e" >>expect &&
echo "folder1/dir/file1" >>expect &&
cat sparse_hint >>expect &&
test_cmp expect stderr &&
test_must_fail git mv --sparse sub/dir folder1 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv --sparse sub/dir folder1 2>stderr &&
echo "fatal: destination exists in the index, source=sub/dir/file1, destination=folder1/dir/file1" \
>expect &&
test_cmp expect stderr &&
git mv --sparse -f sub/dir folder1 2>stderr &&
GIT_ADVICE=1 git mv --sparse -f sub/dir folder1 2>stderr &&
test_must_be_empty stderr &&
test_path_is_missing sub/dir/file1 &&
Expand All @@ -438,13 +439,13 @@ test_expect_success 'move dirty path from in-cone to out-of-cone' '
setup_sparse_checkout &&
echo "modified" >>sub/d &&
test_must_fail git mv sub/d folder1 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv sub/d folder1 2>stderr &&
cat sparse_error_header >expect &&
echo "folder1/d" >>expect &&
cat sparse_hint >>expect &&
test_cmp expect stderr &&
git mv --sparse sub/d folder1 2>stderr &&
GIT_ADVICE=1 git mv --sparse sub/d folder1 2>stderr &&
cat dirty_error_header >expect &&
echo "folder1/d" >>expect &&
cat dirty_hint >>expect &&
Expand All @@ -462,13 +463,13 @@ test_expect_success 'move dir from in-cone to out-of-cone' '
setup_sparse_checkout &&
mkdir sub/dir/deep &&
test_must_fail git mv sub/dir folder1 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv sub/dir folder1 2>stderr &&
cat sparse_error_header >expect &&
echo "folder1/dir/e" >>expect &&
cat sparse_hint >>expect &&
test_cmp expect stderr &&
git mv --sparse sub/dir folder1 2>stderr &&
GIT_ADVICE=1 git mv --sparse sub/dir folder1 2>stderr &&
test_must_be_empty stderr &&
test_path_is_missing sub/dir &&
Expand All @@ -487,15 +488,15 @@ test_expect_success 'move partially-dirty dir from in-cone to out-of-cone' '
echo "modified" >>sub/dir/e2 &&
echo "modified" >>sub/dir/e3 &&
test_must_fail git mv sub/dir folder1 2>stderr &&
test_env GIT_ADVICE=1 test_must_fail git mv sub/dir folder1 2>stderr &&
cat sparse_error_header >expect &&
echo "folder1/dir/e" >>expect &&
echo "folder1/dir/e2" >>expect &&
echo "folder1/dir/e3" >>expect &&
cat sparse_hint >>expect &&
test_cmp expect stderr &&
git mv --sparse sub/dir folder1 2>stderr &&
GIT_ADVICE=1 git mv --sparse sub/dir folder1 2>stderr &&
cat dirty_error_header >expect &&
echo "folder1/dir/e2" >>expect &&
echo "folder1/dir/e3" >>expect &&
Expand Down
2 changes: 1 addition & 1 deletion t/t7004-tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ test_expect_success 'recursive tagging should give advice' '
hint: git tag -f nested annotated-v4.0^{}
hint: Disable this message with "git config advice.nestedTag false"
EOF
git tag -m nested nested annotated-v4.0 2>actual &&
GIT_ADVICE=1 git tag -m nested nested annotated-v4.0 2>actual &&
test_cmp expect actual
'

Expand Down
2 changes: 1 addition & 1 deletion t/t7201-co.sh
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ test_expect_success 'checkout to detach HEAD' '
rev=$(git rev-parse --short renamer^) &&
git checkout -f renamer &&
git clean -f &&
git checkout renamer^ 2>messages &&
GIT_ADVICE=1 git checkout renamer^ 2>messages &&
grep "HEAD is now at $rev" messages &&
test_line_count -gt 1 messages &&
H=$(git rev-parse --verify HEAD) &&
Expand Down
2 changes: 1 addition & 1 deletion t/t7400-submodule-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ test_expect_success 'submodule add to .gitignored path fails' '
echo "*" > .gitignore &&
git add --force .gitignore &&
git commit -m"Ignore everything" &&
! git submodule add "$submodurl" submod >actual 2>&1 &&
test_env GIT_ADVICE=1 test_must_fail git submodule add "$submodurl" submod >actual 2>&1 &&
test_cmp expect actual
)
'
Expand Down
3 changes: 2 additions & 1 deletion t/t7402-submodule-rebase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ test_expect_success 'rebasing submodule that should conflict' '
test_tick &&
git commit -m fourth &&
test_must_fail git rebase --onto HEAD^^ HEAD^ HEAD^0 2>actual_output &&
test_env GIT_ADVICE=1 test_must_fail git rebase \
--onto HEAD^^ HEAD^ HEAD^0 2>actual_output &&
git ls-files -s submodule >actual &&
(
cd submodule &&
Expand Down
2 changes: 1 addition & 1 deletion t/t7406-submodule-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ test_expect_success 'submodule update should fail due to local changes' '
(cd submodule &&
compare_head
) &&
test_must_fail git submodule update submodule 2>../actual.raw
test_env GIT_ADVICE=1 test_must_fail git submodule update submodule 2>../actual.raw
) &&
sed "s/^> //" >expect <<-\EOF &&
> error: Your local changes to the following files would be overwritten by checkout:
Expand Down
Loading

0 comments on commit d1d31aa

Please sign in to comment.