pack-objects: simplify --filter handling
[git/debian.git] / t / t9210-scalar.sh
blobbe51a8bb7a4e38e2c53c675850265c6433e905ed
1 #!/bin/sh
3 test_description='test the `scalar` command'
5 . ./test-lib.sh
7 GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab cron.txt,launchctl:true,schtasks:true"
8 export GIT_TEST_MAINT_SCHEDULER
10 test_expect_success 'scalar shows a usage' '
11 test_expect_code 129 scalar -h
14 test_expect_success 'scalar invoked on enlistment root' '
15 test_when_finished rm -rf test src deeper &&
17 for enlistment_root in test src deeper/test
19 git init ${enlistment_root}/src &&
21 # Register
22 scalar register ${enlistment_root} &&
23 scalar list >out &&
24 grep "$(pwd)/${enlistment_root}/src\$" out &&
26 # Delete (including enlistment root)
27 scalar delete $enlistment_root &&
28 test_path_is_missing $enlistment_root &&
29 scalar list >out &&
30 ! grep "^$(pwd)/${enlistment_root}/src\$" out || return 1
31 done
34 test_expect_success 'scalar invoked on enlistment src repo' '
35 test_when_finished rm -rf test src deeper &&
37 for enlistment_root in test src deeper/test
39 git init ${enlistment_root}/src &&
41 # Register
42 scalar register ${enlistment_root}/src &&
43 scalar list >out &&
44 grep "$(pwd)/${enlistment_root}/src\$" out &&
46 # Delete (will not include enlistment root)
47 scalar delete ${enlistment_root}/src &&
48 test_path_is_dir $enlistment_root &&
49 scalar list >out &&
50 ! grep "^$(pwd)/${enlistment_root}/src\$" out || return 1
51 done
54 test_expect_success 'scalar invoked when enlistment root and repo are the same' '
55 test_when_finished rm -rf test src deeper &&
57 for enlistment_root in test src deeper/test
59 git init ${enlistment_root} &&
61 # Register
62 scalar register ${enlistment_root} &&
63 scalar list >out &&
64 grep "$(pwd)/${enlistment_root}\$" out &&
66 # Delete (will not include enlistment root)
67 scalar delete ${enlistment_root} &&
68 test_path_is_missing $enlistment_root &&
69 scalar list >out &&
70 ! grep "^$(pwd)/${enlistment_root}\$" out &&
72 # Make sure we did not accidentally delete the trash dir
73 test_path_is_dir "$TRASH_DIRECTORY" || return 1
74 done
77 test_expect_success 'scalar repo search respects GIT_CEILING_DIRECTORIES' '
78 test_when_finished rm -rf test &&
80 git init test/src &&
81 mkdir -p test/src/deep &&
82 GIT_CEILING_DIRECTORIES="$(pwd)/test/src" &&
83 ! scalar register test/src/deep 2>err &&
84 grep "not a git repository" err
87 test_expect_success 'scalar enlistments need a worktree' '
88 test_when_finished rm -rf bare test &&
90 git init --bare bare/src &&
91 ! scalar register bare/src 2>err &&
92 grep "Scalar enlistments require a worktree" err &&
94 git init test/src &&
95 ! scalar register test/src/.git 2>err &&
96 grep "Scalar enlistments require a worktree" err
99 test_expect_success FSMONITOR_DAEMON 'scalar register starts fsmon daemon' '
100 git init test/src &&
101 test_must_fail git -C test/src fsmonitor--daemon status &&
102 scalar register test/src &&
103 git -C test/src fsmonitor--daemon status &&
104 test_cmp_config -C test/src true core.fsmonitor
107 test_expect_success 'scalar unregister' '
108 git init vanish/src &&
109 scalar register vanish/src &&
110 git config --get --global --fixed-value \
111 maintenance.repo "$(pwd)/vanish/src" &&
112 scalar list >scalar.repos &&
113 grep -F "$(pwd)/vanish/src" scalar.repos &&
114 rm -rf vanish/src/.git &&
115 scalar unregister vanish &&
116 test_must_fail git config --get --global --fixed-value \
117 maintenance.repo "$(pwd)/vanish/src" &&
118 scalar list >scalar.repos &&
119 ! grep -F "$(pwd)/vanish/src" scalar.repos &&
121 # scalar unregister should be idempotent
122 scalar unregister vanish
125 test_expect_success 'set up repository to clone' '
126 test_commit first &&
127 test_commit second &&
128 test_commit third &&
129 git switch -c parallel first &&
130 mkdir -p 1/2 &&
131 test_commit 1/2/3 &&
132 git config uploadPack.allowFilter true &&
133 git config uploadPack.allowAnySHA1InWant true
136 test_expect_success 'scalar clone' '
137 second=$(git rev-parse --verify second:second.t) &&
138 scalar clone "file://$(pwd)" cloned --single-branch &&
140 cd cloned/src &&
142 git config --get --global --fixed-value maintenance.repo \
143 "$(pwd)" &&
145 git for-each-ref --format="%(refname)" refs/remotes/origin/ >actual &&
146 echo "refs/remotes/origin/parallel" >expect &&
147 test_cmp expect actual &&
149 test_path_is_missing 1/2 &&
150 test_must_fail git rev-list --missing=print $second &&
151 git rev-list $second &&
152 git cat-file blob $second >actual &&
153 echo "second" >expect &&
154 test_cmp expect actual
158 test_expect_success 'scalar reconfigure' '
159 git init one/src &&
160 scalar register one &&
161 git -C one/src config core.preloadIndex false &&
162 scalar reconfigure one &&
163 test true = "$(git -C one/src config core.preloadIndex)" &&
164 git -C one/src config core.preloadIndex false &&
165 scalar reconfigure -a &&
166 test true = "$(git -C one/src config core.preloadIndex)"
169 test_expect_success 'scalar delete without enlistment shows a usage' '
170 test_expect_code 129 scalar delete
173 test_expect_success 'scalar delete with enlistment' '
174 scalar delete cloned &&
175 test_path_is_missing cloned
178 test_expect_success 'scalar supports -c/-C' '
179 test_when_finished "scalar delete sub" &&
180 git init sub &&
181 scalar -C sub -c status.aheadBehind=bogus register &&
182 test -z "$(git -C sub config --local status.aheadBehind)" &&
183 test true = "$(git -C sub config core.preloadIndex)"
186 test_expect_success '`scalar [...] <dir>` errors out when dir is missing' '
187 ! scalar run config cloned 2>err &&
188 grep "cloned. does not exist" err
191 SQ="'"
192 test_expect_success UNZIP 'scalar diagnose' '
193 scalar clone "file://$(pwd)" cloned --single-branch &&
194 git repack &&
195 echo "$(pwd)/.git/objects/" >>cloned/src/.git/objects/info/alternates &&
196 test_commit -C cloned/src loose &&
197 scalar diagnose cloned >out 2>err &&
198 grep "Available space" out &&
199 sed -n "s/.*$SQ\\(.*\\.zip\\)$SQ.*/\\1/p" <err >zip_path &&
200 zip_path=$(cat zip_path) &&
201 test -n "$zip_path" &&
202 "$GIT_UNZIP" -v "$zip_path" &&
203 folder=${zip_path%.zip} &&
204 test_path_is_missing "$folder" &&
205 "$GIT_UNZIP" -p "$zip_path" diagnostics.log >out &&
206 test_file_not_empty out &&
207 "$GIT_UNZIP" -p "$zip_path" packs-local.txt >out &&
208 grep "$(pwd)/.git/objects" out &&
209 "$GIT_UNZIP" -p "$zip_path" objects-local.txt >out &&
210 grep "^Total: [1-9]" out
213 test_done