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
11 test_expect_success
'setup' '
16 git commit -m "initial commit"
19 test_expect_success
'create feature branch' '
20 git checkout -b feature &&
24 git commit -m "modification"
27 test_expect_success
'perform sparse checkout of main' '
28 git config --local --bool core.sparsecheckout true &&
30 echo "!/*" >.git/info/sparse-checkout &&
31 echo "/a" >>.git/info/sparse-checkout &&
32 echo "/c" >>.git/info/sparse-checkout &&
34 test_path_is_file a &&
35 test_path_is_missing b &&
39 test_expect_success
'merge feature branch into sparse checkout of main' '
41 test_path_is_file a &&
42 test_path_is_missing b &&
43 test_path_is_file c &&
44 test "$(cat c)" = "modified"
47 test_expect_success
'return to full checkout of main' '
48 git checkout feature &&
49 echo "/*" >.git/info/sparse-checkout &&
51 test_path_is_file a &&
52 test_path_is_file b &&
53 test_path_is_file c &&
54 test "$(cat b)" = "modified"
57 test_expect_success
'skip-worktree on files outside sparse patterns' '
58 git sparse-checkout disable &&
59 git sparse-checkout set --no-cone "a*" &&
60 git checkout-index --all --ignore-skip-worktree-bits &&
62 git ls-files -t >output &&
63 ! grep ^S output >actual &&
64 test_must_be_empty actual &&
66 test_config sparse.expectFilesOutsideOfPatterns true &&
67 cat <<-\EOF >expect &&
71 git ls-files -t >output &&
72 grep ^S output >actual &&
73 test_cmp expect actual
76 test_expect_success
'in partial clone, sparse checkout only fetches needed blobs' '
77 test_create_repo server &&
78 git clone --template= "file://$(pwd)/server" client &&
80 test_config -C server uploadpack.allowfilter 1 &&
81 test_config -C server uploadpack.allowanysha1inwant 1 &&
85 echo ccc >server/c/c &&
86 git -C server add a b c/c &&
87 git -C server commit -m message &&
89 test_config -C client core.sparsecheckout 1 &&
90 mkdir client/.git/info &&
91 echo "!/*" >client/.git/info/sparse-checkout &&
92 echo "/a" >>client/.git/info/sparse-checkout &&
93 git -C client fetch --filter=blob:none origin &&
94 git -C client checkout FETCH_HEAD &&
96 git -C client rev-list HEAD \
97 --quiet --objects --missing=print >unsorted_actual &&
100 git hash-object server/b &&
102 git hash-object server/c/c
103 ) >unsorted_expect &&
104 sort unsorted_actual >actual &&
105 sort unsorted_expect >expect &&
106 test_cmp expect actual