Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2021-07-28 23:18:01 +0300
committerJunio C Hamano <gitster@pobox.com>2021-07-28 23:18:02 +0300
commitb271a3034fc54a7c84ae5803d72f14a29b172c78 (patch)
treeecace44004f0254c6b107d1748f0977eab2c98de /t
parent6d56fb28fb0de8add352352c9b271cace08670b8 (diff)
parente5ca291076a8a936283bb2c57433c4393d3f80c2 (diff)
Merge branch 'ds/status-with-sparse-index'
"git status" codepath learned to work with sparsely populated index without hydrating it fully. * ds/status-with-sparse-index: t1092: document bad sparse-checkout behavior fsmonitor: integrate with sparse index wt-status: expand added sparse directory entries status: use sparse-index throughout status: skip sparse-checkout percentage with sparse-index diff-lib: handle index diffs with sparse dirs dir.c: accept a directory as part of cone-mode patterns unpack-trees: unpack sparse directory entries unpack-trees: rename unpack_nondirectories() unpack-trees: compare sparse directories correctly unpack-trees: preserve cache_bottom t1092: add tests for status/add and sparse files t1092: expand repository data shape t1092: replace incorrect 'echo' with 'cat' sparse-index: include EXTENDED flag when expanding sparse-index: skip indexes with unmerged entries
Diffstat (limited to 't')
-rwxr-xr-xt/t1092-sparse-checkout-compatibility.sh168
-rwxr-xr-xt/t7519-status-fsmonitor.sh49
2 files changed, 206 insertions, 11 deletions
diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
index d028b73eba..cabbd42e33 100755
--- a/t/t1092-sparse-checkout-compatibility.sh
+++ b/t/t1092-sparse-checkout-compatibility.sh
@@ -17,7 +17,7 @@ test_expect_success 'setup' '
echo "after folder1" >g &&
echo "after x" >z &&
mkdir folder1 folder2 deep x &&
- mkdir deep/deeper1 deep/deeper2 &&
+ mkdir deep/deeper1 deep/deeper2 deep/before deep/later &&
mkdir deep/deeper1/deepest &&
echo "after deeper1" >deep/e &&
echo "after deepest" >deep/deeper1/e &&
@@ -25,10 +25,23 @@ test_expect_success 'setup' '
cp a folder2 &&
cp a x &&
cp a deep &&
+ cp a deep/before &&
cp a deep/deeper1 &&
cp a deep/deeper2 &&
+ cp a deep/later &&
cp a deep/deeper1/deepest &&
cp -r deep/deeper1/deepest deep/deeper2 &&
+ mkdir deep/deeper1/0 &&
+ mkdir deep/deeper1/0/0 &&
+ touch deep/deeper1/0/1 &&
+ touch deep/deeper1/0/0/0 &&
+ >folder1- &&
+ >folder1.x &&
+ >folder10 &&
+ cp -r deep/deeper1/0 folder1 &&
+ cp -r deep/deeper1/0 folder2 &&
+ echo >>folder1/0/0/0 &&
+ echo >>folder2/0/1 &&
git add . &&
git commit -m "initial commit" &&
git checkout -b base &&
@@ -40,7 +53,7 @@ test_expect_success 'setup' '
done &&
git checkout -b rename-base base &&
- echo >folder1/larger-content <<-\EOF &&
+ cat >folder1/larger-content <<-\EOF &&
matching
lines
help
@@ -56,11 +69,17 @@ test_expect_success 'setup' '
mv folder1/a folder2/b &&
mv folder1/larger-content folder2/edited-content &&
echo >>folder2/edited-content &&
+ echo >>folder2/0/1 &&
+ echo stuff >>deep/deeper1/a &&
git add . &&
git commit -m "rename folder1/... to folder2/..." &&
git checkout -b rename-out-to-in rename-base &&
mv folder1/a deep/deeper1/b &&
+ echo more stuff >>deep/deeper1/a &&
+ rm folder2/0/1 &&
+ mkdir folder2/0/1 &&
+ echo >>folder2/0/1/1 &&
mv folder1/larger-content deep/deeper1/edited-content &&
echo >>deep/deeper1/edited-content &&
git add . &&
@@ -68,6 +87,9 @@ test_expect_success 'setup' '
git checkout -b rename-in-to-out rename-base &&
mv deep/deeper1/a folder1/b &&
+ echo >>folder2/0/1 &&
+ rm -rf folder1/0/0 &&
+ echo >>folder1/0/0 &&
mv deep/deeper1/larger-content folder1/edited-content &&
echo >>folder1/edited-content &&
git add . &&
@@ -196,6 +218,14 @@ test_expect_success 'status with options' '
test_all_match git status --porcelain=v2 -uno
'
+test_expect_success 'status reports sparse-checkout' '
+ init_repos &&
+ git -C sparse-checkout status >full &&
+ git -C sparse-index status >sparse &&
+ test_i18ngrep "You are in a sparse checkout with " full &&
+ test_i18ngrep "You are in a sparse checkout." sparse
+'
+
test_expect_success 'add, commit, checkout' '
init_repos &&
@@ -232,6 +262,44 @@ test_expect_success 'add, commit, checkout' '
test_all_match git checkout -
'
+test_expect_success 'status/add: outside sparse cone' '
+ init_repos &&
+
+ # adding a "missing" file outside the cone should fail
+ test_sparse_match test_must_fail git add folder1/a &&
+
+ # folder1 is at HEAD, but outside the sparse cone
+ run_on_sparse mkdir folder1 &&
+ cp initial-repo/folder1/a sparse-checkout/folder1/a &&
+ cp initial-repo/folder1/a sparse-index/folder1/a &&
+
+ test_sparse_match git status &&
+
+ write_script edit-contents <<-\EOF &&
+ echo text >>$1
+ EOF
+ run_on_sparse ../edit-contents folder1/a &&
+ run_on_all ../edit-contents folder1/new &&
+
+ test_sparse_match git status --porcelain=v2 &&
+
+ # This "git add folder1/a" fails with a warning
+ # in the sparse repos, differing from the full
+ # repo. This is intentional.
+ test_sparse_match test_must_fail git add folder1/a &&
+ test_sparse_match test_must_fail git add --refresh folder1/a &&
+ test_all_match git status --porcelain=v2 &&
+
+ test_all_match git add . &&
+ test_all_match git status --porcelain=v2 &&
+ test_all_match git commit -m folder1/new &&
+
+ run_on_all ../edit-contents folder1/newer &&
+ test_all_match git add folder1/ &&
+ test_all_match git status --porcelain=v2 &&
+ test_all_match git commit -m folder1/newer
+'
+
test_expect_success 'checkout and reset --hard' '
init_repos &&
@@ -262,13 +330,29 @@ test_expect_success 'diff --staged' '
test_all_match git diff --staged
'
-test_expect_success 'diff with renames' '
+test_expect_success 'diff with renames and conflicts' '
init_repos &&
for branch in rename-out-to-out rename-out-to-in rename-in-to-out
do
test_all_match git checkout rename-base &&
test_all_match git checkout $branch -- . &&
+ test_all_match git status --porcelain=v2 &&
+ test_all_match git diff --staged --no-renames &&
+ test_all_match git diff --staged --find-renames || return 1
+ done
+'
+
+test_expect_success 'diff with directory/file conflicts' '
+ init_repos &&
+
+ for branch in rename-out-to-out rename-out-to-in rename-in-to-out
+ do
+ git -C full-checkout reset --hard &&
+ test_sparse_match git reset --hard &&
+ test_all_match git checkout $branch &&
+ test_all_match git checkout rename-base -- . &&
+ test_all_match git status --porcelain=v2 &&
test_all_match git diff --staged --no-renames &&
test_all_match git diff --staged --find-renames || return 1
done
@@ -308,8 +392,8 @@ test_expect_failure 'blame with pathspec outside sparse definition' '
test_all_match git blame deep/deeper2/deepest/a
'
-# TODO: reset currently does not behave as expected when in a
-# sparse-checkout.
+# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
+# in this scenario, but it shouldn't.
test_expect_failure 'checkout and reset (mixed)' '
init_repos &&
@@ -319,8 +403,8 @@ test_expect_failure 'checkout and reset (mixed)' '
test_all_match git reset update-folder2
'
-# Ensure that sparse-index behaves identically to
-# sparse-checkout with a full index.
+# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
+# in this scenario, but it shouldn't.
test_expect_success 'checkout and reset (mixed) [sparse]' '
init_repos &&
@@ -352,6 +436,28 @@ test_expect_success 'merge with outside renames' '
done
'
+# Sparse-index fails to convert the index in the
+# final 'git cherry-pick' command.
+test_expect_success 'cherry-pick with conflicts' '
+ init_repos &&
+
+ write_script edit-conflict <<-\EOF &&
+ echo $1 >conflict
+ EOF
+
+ test_all_match git checkout -b to-cherry-pick &&
+ run_on_all ../edit-conflict ABC &&
+ test_all_match git add conflict &&
+ test_all_match git commit -m "conflict to pick" &&
+
+ test_all_match git checkout -B base HEAD~1 &&
+ run_on_all ../edit-conflict DEF &&
+ test_all_match git add conflict &&
+ test_all_match git commit -m "conflict in base" &&
+
+ test_all_match test_must_fail git cherry-pick to-cherry-pick
+'
+
test_expect_success 'clean' '
init_repos &&
@@ -405,12 +511,52 @@ test_expect_success 'sparse-index is expanded and converted back' '
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
git -C sparse-index -c core.fsmonitor="" reset --hard &&
test_region index convert_to_sparse trace2.txt &&
- test_region index ensure_full_index trace2.txt &&
+ test_region index ensure_full_index trace2.txt
+'
- rm trace2.txt &&
+test_expect_success 'sparse-index is not expanded' '
+ init_repos &&
+
+ rm -f trace2.txt &&
+ echo >>sparse-index/untracked.txt &&
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
- git -C sparse-index -c core.fsmonitor="" status -uno &&
- test_region index ensure_full_index trace2.txt
+ git -C sparse-index status &&
+ test_region ! index ensure_full_index trace2.txt
+'
+
+# NEEDSWORK: a sparse-checkout behaves differently from a full checkout
+# in this scenario, but it shouldn't.
+test_expect_success 'reset mixed and checkout orphan' '
+ init_repos &&
+
+ test_all_match git checkout rename-out-to-in &&
+
+ # Sparse checkouts do not agree with full checkouts about
+ # how to report a directory/file conflict during a reset.
+ # This command would fail with test_all_match because the
+ # full checkout reports "T folder1/0/1" while a sparse
+ # checkout reports "D folder1/0/1". This matches because
+ # the sparse checkouts skip "adding" the other side of
+ # the conflict.
+ test_sparse_match git reset --mixed HEAD~1 &&
+ test_sparse_match test-tool read-cache --table --expand &&
+ test_sparse_match git status --porcelain=v2 &&
+
+ # At this point, sparse-checkouts behave differently
+ # from the full-checkout.
+ test_sparse_match git checkout --orphan new-branch &&
+ test_sparse_match test-tool read-cache --table --expand &&
+ test_sparse_match git status --porcelain=v2
+'
+
+test_expect_success 'add everything with deep new file' '
+ init_repos &&
+
+ run_on_sparse git sparse-checkout set deep/deeper1/deepest &&
+
+ run_on_all touch deep/deeper1/x &&
+ test_all_match git add . &&
+ test_all_match git status --porcelain=v2
'
test_done
diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh
index 637391c6ce..deea88d443 100755
--- a/t/t7519-status-fsmonitor.sh
+++ b/t/t7519-status-fsmonitor.sh
@@ -73,6 +73,7 @@ test_expect_success 'setup' '
expect*
actual*
marker*
+ trace2*
EOF
'
@@ -383,4 +384,52 @@ test_expect_success 'status succeeds after staging/unstaging' '
)
'
+# Usage:
+# check_sparse_index_behavior [!]
+# If "!" is supplied, then we verify that we do not call ensure_full_index
+# during a call to 'git status'. Otherwise, we verify that we _do_ call it.
+check_sparse_index_behavior () {
+ git status --porcelain=v2 >expect &&
+ git sparse-checkout init --cone --sparse-index &&
+ git sparse-checkout set dir1 dir2 &&
+ GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
+ git status --porcelain=v2 >actual &&
+ test_region $1 index ensure_full_index trace2.txt &&
+ test_region fsm_hook query trace2.txt &&
+ test_cmp expect actual &&
+ rm trace2.txt &&
+ git sparse-checkout disable
+}
+
+test_expect_success 'status succeeds with sparse index' '
+ git reset --hard &&
+
+ test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" &&
+ check_sparse_index_behavior ! &&
+
+ write_script .git/hooks/fsmonitor-test<<-\EOF &&
+ printf "last_update_token\0"
+ EOF
+ git config core.fsmonitor .git/hooks/fsmonitor-test &&
+ check_sparse_index_behavior ! &&
+
+ write_script .git/hooks/fsmonitor-test<<-\EOF &&
+ printf "last_update_token\0"
+ printf "dir1/modified\0"
+ EOF
+ check_sparse_index_behavior ! &&
+
+ cp -r dir1 dir1a &&
+ git add dir1a &&
+ git commit -m "add dir1a" &&
+
+ # This one modifies outside the sparse-checkout definition
+ # and hence we expect to expand the sparse-index.
+ write_script .git/hooks/fsmonitor-test<<-\EOF &&
+ printf "last_update_token\0"
+ printf "dir1a/modified\0"
+ EOF
+ check_sparse_index_behavior
+'
+
test_done