From: Derrick Stolee <dstolee@xxxxxxxxxxxxx> When running 'git add --refresh <path>', Git does not actually stage the change, but instead updates the index based on the stat() information in the working directory. This typically does not make sense in a sparse-checkout scenario, where Git wants this file to not exist. However, sometimes the file can exist on-disk for other reasons, such as a user manually adding the file or a merge conflict outside of the sparse cone. Since b243012 (refresh_index(): add flag to ignore SKIP_WORKTREE entries, 2021-04-08), 'git add --refresh <path>' will output an advice message to indicate that this is not allowed when <path> is outside the sparse cone. The check goes around the sparse index protections at the moment, so it does not find a match when contained in a sparse directory entry. We will update this behavior with a later change, but want to demonstrate the failure now. Signed-off-by: Derrick Stolee <dstolee@xxxxxxxxxxxxx> --- t/t1092-sparse-checkout-compatibility.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index f9e2f5f4aa1..73c48a71d89 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -347,6 +347,25 @@ test_expect_success 'status/add: outside sparse cone' ' test_all_match git commit -m folder1/newer ' +test_expect_failure 'add: pathspec within sparse directory' ' + init_repos && + + run_on_sparse mkdir folder1 && + run_on_sparse ../edit-contents folder1/a && + run_on_all ../edit-contents folder1/new && + + # This "git add folder1/a" fails with a warning + # in the sparse repos, differing from the full + # repo. This is intentional. + # + # However, in the sparse-index, folder1/a does not + # match any cache entry and fails with a different + # error message. This needs work. + 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_expect_success 'checkout and reset --hard' ' init_repos && -- gitgitgadget