Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions t/t7002-mv-sparse-checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,84 @@ test_expect_success 'move sparse file to existing destination with --force and -
test_cmp expect sub/file1
'

test_expect_failure 'move clean path from in-cone to out-of-cone' '
test_when_finished "cleanup_sparse_checkout" &&
setup_sparse_checkout &&

git mv --sparse sub/d folder1 2>stderr &&
test_must_be_empty stderr &&

test_path_is_missing sub/d &&
test_path_is_missing folder1/d &&
git ls-files -t >actual &&
! grep -x "H sub/d" actual &&
grep -x "S folder1/d" actual
'

test_expect_failure 'move dirty path from in-cone to out-of-cone' '
test_when_finished "cleanup_sparse_checkout" &&
setup_sparse_checkout &&
echo "modified" >>sub/d &&

git mv --sparse sub/d folder1 2>stderr &&
cat >expect <<-EOF &&
The following dirty paths and/or pathspecs are moved
but not sparsified. Use "git add" to stage them then
use "git sparse-checkout reapply" to sparsify them.
folder1/d
EOF
test_cmp expect stderr &&

test_path_is_missing sub/d &&
test_path_is_file folder1/d &&
git ls-files -t >actual &&
! grep -x "H sub/d" actual &&
grep -x "H folder1/d" actual
'

test_expect_failure 'move dir from in-cone to out-of-cone' '
test_when_finished "cleanup_sparse_checkout" &&
setup_sparse_checkout &&

git mv --sparse sub/dir folder1 2>stderr &&
test_must_be_empty stderr &&

test_path_is_missing sub/dir &&
test_path_is_missing folder1 &&
git ls-files -t >actual &&
! grep -x "H sub/dir/e" actual &&
grep -x "S folder1/dir/e" actual
'

test_expect_failure 'move partially-dirty dir from in-cone to out-of-cone' '
test_when_finished "cleanup_sparse_checkout" &&
setup_sparse_checkout &&
touch sub/dir/e2 sub/dir/e3 &&
git add sub/dir/e2 sub/dir/e3 &&
echo "modified" >>sub/dir/e2 &&
echo "modified" >>sub/dir/e3 &&

git mv --sparse sub/dir folder1 2>stderr &&
cat >expect <<-EOF &&
The following dirty paths and/or pathspecs are moved
but not sparsified. Use "git add" to stage them then
use "git sparse-checkout reapply" to sparsify them.
folder1/dir/e2
folder1/dir/e3
EOF
test_cmp expect stderr &&
Comment on lines +350 to +358
Copy link
Copy Markdown

@vdye vdye Jul 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this section, you might want to verify that the non-dirty contents of the folder were not moved, i.e.:

test_path_is_file sub/dir/e

EDIT: nevermind, didn't read the warning message. Instead, you can check that sub/dir/e was moved, and exists on disk:

test_path_is_empty sub/dir &&
test_path_is_empty folder1/e &&
test_path_is_file folder1/e2 &&

Copy link
Copy Markdown
Owner Author

@ffyuanda ffyuanda Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic in this in-cone to out-of-cone move is that:

  1. Clean paths are sparsified.
  2. Dirty paths are moved to the required (usually requires mkdir -p), and they are not sparsified.

So I think the "non-dirty contents of the folder" should actually be moved and sparsified?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, I added an update after the "EDIT" in my previous comment.


test_path_is_missing sub/dir &&
test_path_is_missing folder1/dir/e &&
test_path_is_file folder1/dir/e2 &&
test_path_is_file folder1/dir/e3 &&
git ls-files -t >actual &&
! grep -x "H sub/dir/e" actual &&
! grep -x "H sub/dir/e2" actual &&
! grep -x "H sub/dir/e3" actual &&
grep -x "S folder1/dir/e" actual &&
grep -x "H folder1/dir/e2" actual &&
grep -x "H folder1/dir/e3" actual
'

test_done