Skip to content

Commit fd4faf7

Browse files
Cheskaqiqigitster
authored andcommitted
t1092: add tests for 'git check-attr'
Add tests for `git check-attr`, make sure attribute file does get read from index when path is either inside or outside of sparse-checkout definition. Add a test named 'diff --check with pathspec outside sparse definition'. It starts by disabling the trailing whitespace and space-before-tab checks using the core. whitespace configuration option. Then, it specifically re-enables the trailing whitespace check for a file located in a sparse directory by adding a whitespace=trailing-space rule to the .gitattributes file within that directory. Next, create and populate the folder1 directory, and then add the .gitattributes file to the index. Edit the contents of folder1/a, add it to the index, and proceed to "re-sparsify" 'folder1/' with 'git sparse-checkout reapply'. Finally, use 'git diff --check --cached' to compare the 'index vs. HEAD', ensuring the correct application of the attribute rules even when the file's path is outside the sparse-checkout definition. Mark the two tests 'check-attr with pathspec outside sparse definition' and 'diff --check with pathspec outside sparse definition' as 'test_expect_failure' to reflect an existing issue where the attributes inside a sparse directory are ignored. Ensure that the 'check-attr' command fails to read the required attributes to demonstrate this expected failure. Helped-by: Victoria Dye <[email protected]> Signed-off-by: Shuqi Liang <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aa9166b commit fd4faf7

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,4 +2259,53 @@ test_expect_success 'worktree is not expanded' '
22592259
ensure_not_expanded worktree remove .worktrees/hotfix
22602260
'
22612261

2262+
test_expect_success 'check-attr with pathspec inside sparse definition' '
2263+
init_repos &&
2264+
2265+
echo "a -crlf myAttr" >>.gitattributes &&
2266+
run_on_all cp ../.gitattributes ./deep &&
2267+
2268+
test_all_match git check-attr -a -- deep/a &&
2269+
2270+
test_all_match git add deep/.gitattributes &&
2271+
test_all_match git check-attr -a --cached -- deep/a
2272+
'
2273+
2274+
test_expect_failure 'check-attr with pathspec outside sparse definition' '
2275+
init_repos &&
2276+
2277+
echo "a -crlf myAttr" >>.gitattributes &&
2278+
run_on_sparse mkdir folder1 &&
2279+
run_on_all cp ../.gitattributes ./folder1 &&
2280+
run_on_all cp a folder1/a &&
2281+
2282+
test_all_match git check-attr -a -- folder1/a &&
2283+
2284+
git -C full-checkout add folder1/.gitattributes &&
2285+
test_sparse_match git add --sparse folder1/.gitattributes &&
2286+
test_all_match git commit -m "add .gitattributes" &&
2287+
test_sparse_match git sparse-checkout reapply &&
2288+
test_all_match git check-attr -a --cached -- folder1/a
2289+
'
2290+
2291+
test_expect_failure 'diff --check with pathspec outside sparse definition' '
2292+
init_repos &&
2293+
2294+
write_script edit-contents <<-\EOF &&
2295+
echo "a " >"$1"
2296+
EOF
2297+
2298+
test_all_match git config core.whitespace -trailing-space,-space-before-tab &&
2299+
2300+
echo "a whitespace=trailing-space,space-before-tab" >>.gitattributes &&
2301+
run_on_all mkdir -p folder1 &&
2302+
run_on_all cp ../.gitattributes ./folder1 &&
2303+
test_all_match git add --sparse folder1/.gitattributes &&
2304+
run_on_all ../edit-contents folder1/a &&
2305+
test_all_match git add --sparse folder1/a &&
2306+
2307+
test_sparse_match git sparse-checkout reapply &&
2308+
test_all_match test_must_fail git diff --check --cached -- folder1/a
2309+
'
2310+
22622311
test_done

0 commit comments

Comments
 (0)