]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1090-sparse-checkout-scope.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t1090-sparse-checkout-scope.sh
CommitLineData
7d782416
DT
1#!/bin/sh
2
3test_description='sparse checkout scope tests'
4
06d53148 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
ead74601 8TEST_CREATE_REPO_NO_TEMPLATE=1
7d782416
DT
9. ./test-lib.sh
10
11test_expect_success 'setup' '
12 echo "initial" >a &&
13 echo "initial" >b &&
14 echo "initial" >c &&
15 git add a b c &&
16 git commit -m "initial commit"
17'
18
19test_expect_success 'create feature branch' '
20 git checkout -b feature &&
21 echo "modified" >b &&
22 echo "modified" >c &&
23 git add b c &&
24 git commit -m "modification"
25'
26
06d53148 27test_expect_success 'perform sparse checkout of main' '
7d782416 28 git config --local --bool core.sparsecheckout true &&
ead74601 29 mkdir .git/info &&
7d782416
DT
30 echo "!/*" >.git/info/sparse-checkout &&
31 echo "/a" >>.git/info/sparse-checkout &&
32 echo "/c" >>.git/info/sparse-checkout &&
06d53148 33 git checkout main &&
7d782416
DT
34 test_path_is_file a &&
35 test_path_is_missing b &&
36 test_path_is_file c
37'
38
06d53148 39test_expect_success 'merge feature branch into sparse checkout of main' '
7d782416
DT
40 git merge feature &&
41 test_path_is_file a &&
42 test_path_is_missing b &&
43 test_path_is_file c &&
44 test "$(cat c)" = "modified"
45'
46
06d53148 47test_expect_success 'return to full checkout of main' '
7d782416
DT
48 git checkout feature &&
49 echo "/*" >.git/info/sparse-checkout &&
06d53148 50 git checkout main &&
7d782416
DT
51 test_path_is_file a &&
52 test_path_is_file b &&
53 test_path_is_file c &&
54 test "$(cat b)" = "modified"
55'
56
ecc7c884
EN
57test_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 &&
61
62 git ls-files -t >output &&
63 ! grep ^S output >actual &&
64 test_must_be_empty actual &&
65
66 test_config sparse.expectFilesOutsideOfPatterns true &&
67 cat <<-\EOF >expect &&
68 S b
69 S c
70 EOF
71 git ls-files -t >output &&
72 grep ^S output >actual &&
73 test_cmp expect actual
74'
75
2f215ff1
JT
76test_expect_success 'in partial clone, sparse checkout only fetches needed blobs' '
77 test_create_repo server &&
ead74601 78 git clone --template= "file://$(pwd)/server" client &&
2f215ff1
JT
79
80 test_config -C server uploadpack.allowfilter 1 &&
81 test_config -C server uploadpack.allowanysha1inwant 1 &&
82 echo a >server/a &&
83 echo bb >server/b &&
84 mkdir server/c &&
85 echo ccc >server/c/c &&
86 git -C server add a b c/c &&
87 git -C server commit -m message &&
88
89 test_config -C client core.sparsecheckout 1 &&
ead74601 90 mkdir client/.git/info &&
2f215ff1
JT
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 &&
95
96 git -C client rev-list HEAD \
97 --quiet --objects --missing=print >unsorted_actual &&
98 (
99 printf "?" &&
100 git hash-object server/b &&
101 printf "?" &&
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
107'
108
7d782416 109test_done