3 test_description
='sparse checkout scope tests'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_CREATE_REPO_NO_TEMPLATE
=1
9 TEST_PASSES_SANITIZE_LEAK
=true
12 test_expect_success
'setup' '
17 git commit -m "initial commit"
20 test_expect_success
'create feature branch' '
21 git checkout -b feature &&
25 git commit -m "modification"
28 test_expect_success
'perform sparse checkout of main' '
29 git config --local --bool core.sparsecheckout true &&
31 echo "!/*" >.git/info/sparse-checkout &&
32 echo "/a" >>.git/info/sparse-checkout &&
33 echo "/c" >>.git/info/sparse-checkout &&
35 test_path_is_file a &&
36 test_path_is_missing b &&
40 test_expect_success
'merge feature branch into sparse checkout of main' '
42 test_path_is_file a &&
43 test_path_is_missing b &&
44 test_path_is_file c &&
45 test "$(cat c)" = "modified"
48 test_expect_success
'return to full checkout of main' '
49 git checkout feature &&
50 echo "/*" >.git/info/sparse-checkout &&
52 test_path_is_file a &&
53 test_path_is_file b &&
54 test_path_is_file c &&
55 test "$(cat b)" = "modified"
58 test_expect_success
'skip-worktree on files outside sparse patterns' '
59 git sparse-checkout disable &&
60 git sparse-checkout set --no-cone "a*" &&
61 git checkout-index --all --ignore-skip-worktree-bits &&
63 git ls-files -t >output &&
64 ! grep ^S output >actual &&
65 test_must_be_empty actual &&
67 test_config sparse.expectFilesOutsideOfPatterns true &&
68 cat <<-\EOF >expect &&
72 git ls-files -t >output &&
73 grep ^S output >actual &&
74 test_cmp expect actual
77 test_expect_success
'in partial clone, sparse checkout only fetches needed blobs' '
78 test_create_repo server &&
79 git clone --template= "file://$(pwd)/server" client &&
81 test_config -C server uploadpack.allowfilter 1 &&
82 test_config -C server uploadpack.allowanysha1inwant 1 &&
86 echo ccc >server/c/c &&
87 git -C server add a b c/c &&
88 git -C server commit -m message &&
90 test_config -C client core.sparsecheckout 1 &&
91 mkdir client/.git/info &&
92 echo "!/*" >client/.git/info/sparse-checkout &&
93 echo "/a" >>client/.git/info/sparse-checkout &&
94 git -C client fetch --filter=blob:none origin &&
95 git -C client checkout FETCH_HEAD &&
97 git -C client rev-list HEAD \
98 --quiet --objects --missing=print >unsorted_actual &&
101 git hash-object server/b &&
103 git hash-object server/c/c
104 ) >unsorted_expect &&
105 sort unsorted_actual >actual &&
106 sort unsorted_expect >expect &&
107 test_cmp expect actual