Skip to content

Commit c572b9a

Browse files
Cheskaqiqigitster
authored andcommitted
t1092: add tests for git diff-files
Before integrating the 'git diff-files' builtin with the sparse index feature, add tests to t1092-sparse-checkout-compatibility.sh to ensure it currently works with sparse-checkout and will still work with sparse index after that integration. When adding tests against a sparse-checkout definition, we test two modes: all changes are within the sparse-checkout cone and some changes are outside the sparse-checkout cone. In order to have staged changes outside of the sparse-checkout cone, create a 'newdirectory/testfile' and add it to the index, while leaving it outside of the sparse-checkout definition.Test 'newdirectory/testfile' being present on-disk without modifications, then change content inside 'newdirectory/testfile' in order to test 'newdirectory/testfile' being present on-disk with modifications. Signed-off-by: Shuqi Liang <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 725f570 commit c572b9a

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,4 +2055,52 @@ test_expect_success 'grep sparse directory within submodules' '
20552055
test_cmp actual expect
20562056
'
20572057

2058+
test_expect_success 'diff-files with pathspec inside sparse definition' '
2059+
init_repos &&
2060+
2061+
write_script edit-contents <<-\EOF &&
2062+
echo text >>"$1"
2063+
EOF
2064+
2065+
run_on_all ../edit-contents deep/a &&
2066+
2067+
test_all_match git diff-files &&
2068+
2069+
test_all_match git diff-files deep/a
2070+
2071+
'
2072+
2073+
test_expect_success 'diff-files with pathspec outside sparse definition' '
2074+
init_repos &&
2075+
2076+
write_script edit-contents <<-\EOF &&
2077+
echo text >>"$1"
2078+
EOF
2079+
2080+
# add file to the index but outside of cone
2081+
run_on_sparse mkdir newdirectory &&
2082+
run_on_sparse ../edit-contents newdirectory/testfile &&
2083+
test_sparse_match git add --sparse newdirectory/testfile &&
2084+
2085+
# file present on-disk without modifications
2086+
test_sparse_match git diff-files &&
2087+
test_must_be_empty sparse-checkout-out &&
2088+
test_must_be_empty sparse-checkout-err &&
2089+
test_sparse_match git diff-files newdirectory/testfile &&
2090+
test_must_be_empty sparse-checkout-out &&
2091+
test_must_be_empty sparse-checkout-err &&
2092+
2093+
# file present on-disk with modifications
2094+
FN=newdirectory/testfile &&
2095+
OID=$(git -C sparse-checkout hash-object $FN) &&
2096+
ZERO=$(test_oid zero) &&
2097+
echo ":100644 100644 $OID $ZERO M $FN" >expect &&
2098+
2099+
run_on_sparse ../edit-contents newdirectory/testfile &&
2100+
test_sparse_match git diff-files &&
2101+
test_cmp expect sparse-checkout-out &&
2102+
test_sparse_match git diff-files newdirectory/testfile &&
2103+
test_cmp expect sparse-checkout-out
2104+
'
2105+
20582106
test_done

0 commit comments

Comments
 (0)