]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1090-sparse-checkout-scope.sh
clone: allow "--bare" with "-o"
[thirdparty/git.git] / t / t1090-sparse-checkout-scope.sh
1 #!/bin/sh
2
3 test_description='sparse checkout scope tests'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 test_expect_success 'setup' '
11 echo "initial" >a &&
12 echo "initial" >b &&
13 echo "initial" >c &&
14 git add a b c &&
15 git commit -m "initial commit"
16 '
17
18 test_expect_success 'create feature branch' '
19 git checkout -b feature &&
20 echo "modified" >b &&
21 echo "modified" >c &&
22 git add b c &&
23 git commit -m "modification"
24 '
25
26 test_expect_success 'perform sparse checkout of main' '
27 git config --local --bool core.sparsecheckout true &&
28 echo "!/*" >.git/info/sparse-checkout &&
29 echo "/a" >>.git/info/sparse-checkout &&
30 echo "/c" >>.git/info/sparse-checkout &&
31 git checkout main &&
32 test_path_is_file a &&
33 test_path_is_missing b &&
34 test_path_is_file c
35 '
36
37 test_expect_success 'merge feature branch into sparse checkout of main' '
38 git merge feature &&
39 test_path_is_file a &&
40 test_path_is_missing b &&
41 test_path_is_file c &&
42 test "$(cat c)" = "modified"
43 '
44
45 test_expect_success 'return to full checkout of main' '
46 git checkout feature &&
47 echo "/*" >.git/info/sparse-checkout &&
48 git checkout main &&
49 test_path_is_file a &&
50 test_path_is_file b &&
51 test_path_is_file c &&
52 test "$(cat b)" = "modified"
53 '
54
55 test_expect_success 'skip-worktree on files outside sparse patterns' '
56 git sparse-checkout disable &&
57 git sparse-checkout set --no-cone "a*" &&
58 git checkout-index --all --ignore-skip-worktree-bits &&
59
60 git ls-files -t >output &&
61 ! grep ^S output >actual &&
62 test_must_be_empty actual &&
63
64 test_config sparse.expectFilesOutsideOfPatterns true &&
65 cat <<-\EOF >expect &&
66 S b
67 S c
68 EOF
69 git ls-files -t >output &&
70 grep ^S output >actual &&
71 test_cmp expect actual
72 '
73
74 test_expect_success 'in partial clone, sparse checkout only fetches needed blobs' '
75 test_create_repo server &&
76 git clone "file://$(pwd)/server" client &&
77
78 test_config -C server uploadpack.allowfilter 1 &&
79 test_config -C server uploadpack.allowanysha1inwant 1 &&
80 echo a >server/a &&
81 echo bb >server/b &&
82 mkdir server/c &&
83 echo ccc >server/c/c &&
84 git -C server add a b c/c &&
85 git -C server commit -m message &&
86
87 test_config -C client core.sparsecheckout 1 &&
88 echo "!/*" >client/.git/info/sparse-checkout &&
89 echo "/a" >>client/.git/info/sparse-checkout &&
90 git -C client fetch --filter=blob:none origin &&
91 git -C client checkout FETCH_HEAD &&
92
93 git -C client rev-list HEAD \
94 --quiet --objects --missing=print >unsorted_actual &&
95 (
96 printf "?" &&
97 git hash-object server/b &&
98 printf "?" &&
99 git hash-object server/c/c
100 ) >unsorted_expect &&
101 sort unsorted_actual >actual &&
102 sort unsorted_expect >expect &&
103 test_cmp expect actual
104 '
105
106 test_done