|
|
|
|
@@ -384,6 +384,44 @@ test_expect_success 'add, commit, checkout' '
|
|
|
|
|
test_all_match git checkout -
|
|
|
|
|
'
|
|
|
|
|
|
|
|
|
|
test_expect_success 'git add, checkout, and reset with -p' '
|
|
|
|
|
init_repos &&
|
|
|
|
|
|
|
|
|
|
write_script edit-contents <<-\EOF &&
|
|
|
|
|
echo text >>$1
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
# Does not expand when edits are within sparse checkout.
|
|
|
|
|
run_on_all ../edit-contents deep/a &&
|
|
|
|
|
run_on_all ../edit-contents deep/deeper1/a &&
|
|
|
|
|
|
|
|
|
|
test_write_lines y n >in &&
|
|
|
|
|
run_on_all git add -p <in &&
|
|
|
|
|
test_all_match git status --porcelain=v2 &&
|
|
|
|
|
test_all_match git reset -p <in &&
|
|
|
|
|
|
|
|
|
|
test_write_lines u 1 "" q >in &&
|
|
|
|
|
run_on_all git add -i <in &&
|
|
|
|
|
test_all_match git status --porcelain=v2 &&
|
|
|
|
|
test_all_match git reset --hard &&
|
|
|
|
|
|
|
|
|
|
run_on_sparse mkdir -p folder1 &&
|
|
|
|
|
run_on_all ../edit-contents folder1/a &&
|
|
|
|
|
test_write_lines y n y >in &&
|
|
|
|
|
run_on_all git add -p <in &&
|
|
|
|
|
test_sparse_match git status --porcelain=v2 &&
|
|
|
|
|
test_sparse_match git reset &&
|
|
|
|
|
test_write_lines u 2 3 "" q >in &&
|
|
|
|
|
run_on_all git add -i <in &&
|
|
|
|
|
test_sparse_match git status --porcelain=v2 &&
|
|
|
|
|
|
|
|
|
|
run_on_all git add --sparse folder1 &&
|
|
|
|
|
run_on_all git commit -m "take changes" &&
|
|
|
|
|
test_write_lines y n y >in &&
|
|
|
|
|
test_sparse_match git checkout HEAD~1 --patch <in &&
|
|
|
|
|
test_sparse_match git status --porcelain=v2
|
|
|
|
|
'
|
|
|
|
|
|
|
|
|
|
test_expect_success 'deep changes during checkout' '
|
|
|
|
|
init_repos &&
|
|
|
|
|
|
|
|
|
|
@@ -1340,6 +1378,30 @@ test_expect_success 'submodule handling' '
|
|
|
|
|
grep "160000 $(git -C initial-repo rev-parse HEAD) 0 modules/sub" cache
|
|
|
|
|
'
|
|
|
|
|
|
|
|
|
|
test_expect_success 'git apply functionality' '
|
|
|
|
|
init_repos &&
|
|
|
|
|
|
|
|
|
|
test_all_match git checkout base &&
|
|
|
|
|
|
|
|
|
|
git -C full-checkout diff base..merge-right -- deep >patch-in-sparse &&
|
|
|
|
|
git -C full-checkout diff base..merge-right -- folder2 >patch-outside &&
|
|
|
|
|
|
|
|
|
|
# Apply a patch to a file inside the sparse definition
|
|
|
|
|
test_all_match git apply --index --stat ../patch-in-sparse &&
|
|
|
|
|
test_all_match git status --porcelain=v2 &&
|
|
|
|
|
|
|
|
|
|
# Apply a patch to a file outside the sparse definition
|
|
|
|
|
test_sparse_match test_must_fail git apply ../patch-outside &&
|
|
|
|
|
grep "No such file or directory" sparse-checkout-err &&
|
|
|
|
|
|
|
|
|
|
# But it works with --index and --cached
|
|
|
|
|
test_all_match git apply --index --stat ../patch-outside &&
|
|
|
|
|
test_all_match git status --porcelain=v2 &&
|
|
|
|
|
test_all_match git reset --hard &&
|
|
|
|
|
test_all_match git apply --cached --stat ../patch-outside &&
|
|
|
|
|
test_all_match git status --porcelain=v2
|
|
|
|
|
'
|
|
|
|
|
|
|
|
|
|
# When working with a sparse index, some commands will need to expand the
|
|
|
|
|
# index to operate properly. If those commands also write the index back
|
|
|
|
|
# to disk, they need to convert the index to sparse before writing.
|
|
|
|
|
@@ -2345,6 +2407,95 @@ test_expect_success 'sparse-index is not expanded: check-attr' '
|
|
|
|
|
ensure_not_expanded check-attr -a --cached -- folder1/a
|
|
|
|
|
'
|
|
|
|
|
|
|
|
|
|
test_expect_success 'sparse-index is not expanded: git apply' '
|
|
|
|
|
init_repos &&
|
|
|
|
|
|
|
|
|
|
git -C sparse-index checkout base &&
|
|
|
|
|
git -C full-checkout diff base..merge-right -- deep >patch-in-sparse &&
|
|
|
|
|
git -C full-checkout diff base..merge-right -- folder2 >patch-outside &&
|
|
|
|
|
|
|
|
|
|
# Apply a patch to a file inside the sparse definition
|
|
|
|
|
ensure_not_expanded apply --index --stat ../patch-in-sparse &&
|
|
|
|
|
|
|
|
|
|
# Apply a patch to a file outside the sparse definition
|
|
|
|
|
# Fails when caring about the worktree.
|
|
|
|
|
ensure_not_expanded ! apply ../patch-outside &&
|
|
|
|
|
|
|
|
|
|
# Expands when using --index.
|
|
|
|
|
ensure_expanded apply --index ../patch-outside &&
|
|
|
|
|
|
|
|
|
|
# Does not when index is partially expanded.
|
|
|
|
|
git -C sparse-index reset --hard &&
|
|
|
|
|
ensure_not_expanded apply --cached ../patch-outside &&
|
|
|
|
|
|
|
|
|
|
# Try again with a reset and collapsed index.
|
|
|
|
|
git -C sparse-index reset --hard &&
|
|
|
|
|
git -C sparse-index sparse-checkout reapply &&
|
|
|
|
|
|
|
|
|
|
# Expands when index is collapsed.
|
|
|
|
|
ensure_expanded apply --cached ../patch-outside
|
|
|
|
|
'
|
|
|
|
|
|
|
|
|
|
test_expect_success 'sparse-index is not expanded: git add -p' '
|
|
|
|
|
init_repos &&
|
|
|
|
|
|
|
|
|
|
# Does not expand when edits are within sparse checkout.
|
|
|
|
|
echo "new content" >sparse-index/deep/a &&
|
|
|
|
|
echo "new content" >sparse-index/deep/deeper1/a &&
|
|
|
|
|
test_write_lines y n >in &&
|
|
|
|
|
ensure_not_expanded add -p <in &&
|
|
|
|
|
git -C sparse-index reset &&
|
|
|
|
|
ensure_not_expanded add -i <in &&
|
|
|
|
|
|
|
|
|
|
# -p does expand when edits are outside sparse checkout.
|
|
|
|
|
mkdir -p sparse-index/folder1 &&
|
|
|
|
|
echo "new content" >sparse-index/folder1/a &&
|
|
|
|
|
test_write_lines y n y >in &&
|
|
|
|
|
ensure_expanded add -p <in &&
|
|
|
|
|
|
|
|
|
|
# Fully reset the index.
|
|
|
|
|
git -C sparse-index reset --hard &&
|
|
|
|
|
git -C sparse-index sparse-checkout reapply &&
|
|
|
|
|
|
|
|
|
|
# -i does expand when edits are outside sparse checkout.
|
|
|
|
|
mkdir -p sparse-index/folder1 &&
|
|
|
|
|
echo "new content" >sparse-index/folder1/a &&
|
|
|
|
|
test_write_lines u 2 3 "" q >in &&
|
|
|
|
|
ensure_expanded add -i <in
|
|
|
|
|
'
|
|
|
|
|
|
|
|
|
|
test_expect_success 'sparse-index is not expanded: checkout -p, reset -p' '
|
|
|
|
|
init_repos &&
|
|
|
|
|
|
|
|
|
|
# Does not expand when edits are within sparse checkout.
|
|
|
|
|
echo "new content" >sparse-index/deep/a &&
|
|
|
|
|
echo "new content" >sparse-index/deep/deeper1/a &&
|
|
|
|
|
git -C sparse-index commit -a -m "inside-changes" &&
|
|
|
|
|
|
|
|
|
|
test_write_lines y y >in &&
|
|
|
|
|
ensure_not_expanded checkout HEAD~1 --patch <in &&
|
|
|
|
|
|
|
|
|
|
echo "new content" >sparse-index/deep/a &&
|
|
|
|
|
echo "new content" >sparse-index/deep/deeper1/a &&
|
|
|
|
|
git -C sparse-index add . &&
|
|
|
|
|
ensure_not_expanded reset --patch <in &&
|
|
|
|
|
|
|
|
|
|
# -p does expand when edits are outside sparse checkout.
|
|
|
|
|
mkdir -p sparse-index/folder1 &&
|
|
|
|
|
echo "new content" >sparse-index/folder1/a &&
|
|
|
|
|
git -C sparse-index add --sparse folder1 &&
|
|
|
|
|
git -C sparse-index sparse-checkout reapply &&
|
|
|
|
|
ensure_expanded reset --patch <in &&
|
|
|
|
|
|
|
|
|
|
# Fully reset the index.
|
|
|
|
|
mkdir -p sparse-index/folder1 &&
|
|
|
|
|
echo "new content" >sparse-index/folder1/a &&
|
|
|
|
|
git -C sparse-index add --sparse folder1 &&
|
|
|
|
|
git -C sparse-index commit -m "folder1 change" &&
|
|
|
|
|
git -C sparse-index sparse-checkout reapply &&
|
|
|
|
|
ensure_expanded checkout HEAD~1 --patch <in
|
|
|
|
|
'
|
|
|
|
|
|
|
|
|
|
test_expect_success 'advice.sparseIndexExpanded' '
|
|
|
|
|
init_repos &&
|
|
|
|
|
|
|
|
|
|
|