The eleventh batch
[git/gitster.git] / t / t1090-sparse-checkout-scope.sh
blobda0e7714d5ac5c94a04e7aa100288ef85f42a860
1 #!/bin/sh
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
10 . ./test-lib.sh
12 test_expect_success 'setup' '
13 echo "initial" >a &&
14 echo "initial" >b &&
15 echo "initial" >c &&
16 git add a b c &&
17 git commit -m "initial commit"
20 test_expect_success 'create feature branch' '
21 git checkout -b feature &&
22 echo "modified" >b &&
23 echo "modified" >c &&
24 git add b c &&
25 git commit -m "modification"
28 test_expect_success 'perform sparse checkout of main' '
29 git config --local --bool core.sparsecheckout true &&
30 mkdir .git/info &&
31 echo "!/*" >.git/info/sparse-checkout &&
32 echo "/a" >>.git/info/sparse-checkout &&
33 echo "/c" >>.git/info/sparse-checkout &&
34 git checkout main &&
35 test_path_is_file a &&
36 test_path_is_missing b &&
37 test_path_is_file c
40 test_expect_success 'merge feature branch into sparse checkout of main' '
41 git merge feature &&
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 &&
51 git checkout main &&
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 &&
69 S b
70 S c
71 EOF
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 &&
83 echo a >server/a &&
84 echo bb >server/b &&
85 mkdir server/c &&
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 &&
100 printf "?" &&
101 git hash-object server/b &&
102 printf "?" &&
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
110 test_done