blob: 3deb490187415ec37ae5465ae980d10a775a58db [file] [log] [blame]
David Turner7d782412015-07-17 17:19:27 -04001#!/bin/sh
2
3test_description='sparse checkout scope tests'
4
Johannes Schindelin06d53142020-11-18 23:44:21 +00005GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00006export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
David Turner7d782412015-07-17 17:19:27 -04008. ./test-lib.sh
9
10test_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
18test_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
Johannes Schindelin06d53142020-11-18 23:44:21 +000026test_expect_success 'perform sparse checkout of main' '
David Turner7d782412015-07-17 17:19:27 -040027 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 &&
Johannes Schindelin06d53142020-11-18 23:44:21 +000031 git checkout main &&
David Turner7d782412015-07-17 17:19:27 -040032 test_path_is_file a &&
33 test_path_is_missing b &&
34 test_path_is_file c
35'
36
Johannes Schindelin06d53142020-11-18 23:44:21 +000037test_expect_success 'merge feature branch into sparse checkout of main' '
David Turner7d782412015-07-17 17:19:27 -040038 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
Johannes Schindelin06d53142020-11-18 23:44:21 +000045test_expect_success 'return to full checkout of main' '
David Turner7d782412015-07-17 17:19:27 -040046 git checkout feature &&
47 echo "/*" >.git/info/sparse-checkout &&
Johannes Schindelin06d53142020-11-18 23:44:21 +000048 git checkout main &&
David Turner7d782412015-07-17 17:19:27 -040049 test_path_is_file a &&
50 test_path_is_file b &&
51 test_path_is_file c &&
52 test "$(cat b)" = "modified"
53'
54
Jonathan Tan2f215ff2018-10-09 11:40:37 -070055test_expect_success 'in partial clone, sparse checkout only fetches needed blobs' '
56 test_create_repo server &&
57 git clone "file://$(pwd)/server" client &&
58
59 test_config -C server uploadpack.allowfilter 1 &&
60 test_config -C server uploadpack.allowanysha1inwant 1 &&
61 echo a >server/a &&
62 echo bb >server/b &&
63 mkdir server/c &&
64 echo ccc >server/c/c &&
65 git -C server add a b c/c &&
66 git -C server commit -m message &&
67
68 test_config -C client core.sparsecheckout 1 &&
Jonathan Tan2f215ff2018-10-09 11:40:37 -070069 echo "!/*" >client/.git/info/sparse-checkout &&
70 echo "/a" >>client/.git/info/sparse-checkout &&
71 git -C client fetch --filter=blob:none origin &&
72 git -C client checkout FETCH_HEAD &&
73
74 git -C client rev-list HEAD \
75 --quiet --objects --missing=print >unsorted_actual &&
76 (
77 printf "?" &&
78 git hash-object server/b &&
79 printf "?" &&
80 git hash-object server/c/c
81 ) >unsorted_expect &&
82 sort unsorted_actual >actual &&
83 sort unsorted_expect >expect &&
84 test_cmp expect actual
85'
86
David Turner7d782412015-07-17 17:19:27 -040087test_done