Debian Codegraph @

t/t-install.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 . "$(dirnamescip-shell system . . dirname. "$0")/testlib.sh"
4
5 begin_test "install again"
6 (
7 set -eo pipefail
8
9 smudge="$(gitscip-shell system . . git. config filter.lfs.smudge)"
10 clean="$(gitscip-shell system . . git. config filter.lfs.clean)"
11 filter="$(gitscip-shell system . . git. config filter.lfs.process)"
12
13 [scip-shell system . . `[`. "$smudge" = "git-lfs smudge -- %f" ]
14 [scip-shell system . . `[`. "$clean" = "git-lfs clean -- %f" ]
15 [scip-shell system . . `[`. "$filter" = "git-lfs filter-process" ]
16
17 GIT_TRACE=1 gitscip-shell system . . git. lfs install --skip-repo 2>&1 | teescip-shell system . . tee. install.log
18
19 if grepscip-shell system . . grep. -q "--replace-all" install.log; then
20 echoscip-shell system . . echo. >&2 "fatal: unexpected git config --replace-all via 'git lfs install'"
21 exit 1
22 fi
23
24 [scip-shell system . . `[`. "$smudge" = "$(gitscip-shell system . . git. config filter.lfs.smudge)" ]
25 [scip-shell system . . `[`. "$clean" = "$(gitscip-shell system . . git. config filter.lfs.clean)" ]
26 [scip-shell system . . `[`. "$filter" = "$(gitscip-shell system . . git. config filter.lfs.process)" ]
27 )
28 end_test
29
30 begin_test "install with old (non-upgradeable) settings"
31 (
32 set -e
33
34 gitscip-shell system . . git. config --global filter.lfs.smudge "git-lfs smudge --something %f"
35 gitscip-shell system . . git. config --global filter.lfs.clean "git-lfs clean --something %f"
36
37 gitscip-shell system . . git. lfs install | teescip-shell system . . tee. install.log
38 [scip-shell system . . `[`. "${PIPESTATUS[0]}" = 2 ]
39
40 grepscip-shell system . . grep. -E "(clean|smudge)\" attribute should be" install.log
41 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "(MISSING)" install.log)" ]
42
43 [scip-shell system . . `[`. "git-lfs smudge --something %f" = "$(gitscip-shell system . . git. config --global filter.lfs.smudge)" ]
44 [scip-shell system . . `[`. "git-lfs clean --something %f" = "$(gitscip-shell system . . git. config --global filter.lfs.clean)" ]
45
46 gitscip-shell system . . git. lfs install --force
47
48 [scip-shell system . . `[`. "git-lfs smudge -- %f" = "$(gitscip-shell system . . git. config --global filter.lfs.smudge)" ]
49 [scip-shell system . . `[`. "git-lfs clean -- %f" = "$(gitscip-shell system . . git. config --global filter.lfs.clean)" ]
50 )
51 end_test
52
53 begin_test "install with upgradeable settings"
54 (
55 set -e
56
57 gitscip-shell system . . git. config --global filter.lfs.smudge "git-lfs smudge %f"
58 gitscip-shell system . . git. config --global filter.lfs.clean "git-lfs clean %f"
59
60 # should not need force, should upgrade this old style
61 gitscip-shell system . . git. lfs install
62 [scip-shell system . . `[`. "git-lfs smudge -- %f" = "$(gitscip-shell system . . git. config --global filter.lfs.smudge)" ]
63 [scip-shell system . . `[`. "git-lfs clean -- %f" = "$(gitscip-shell system . . git. config --global filter.lfs.clean)" ]
64 [scip-shell system . . `[`. "git-lfs filter-process" = "$(gitscip-shell system . . git. config --global filter.lfs.process)" ]
65 )
66 end_test
67
68 begin_test "install updates repo hooks"
69 (
70 set -e
71
72 mkdirscip-shell system . . mkdir. install-repo-hooks
73 cd install-repo-hooks
74 gitscip-shell system . . git. init
75
76 pre_push_hook="#!/bin/sh
77 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\\n%s\\n\\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
78 git lfs pre-push \"\$@\""
79
80 post_checkout_hook="#!/bin/sh
81 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\\n%s\\n\\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
82 git lfs post-checkout \"\$@\""
83
84 post_commit_hook="#!/bin/sh
85 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\\n%s\\n\\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
86 git lfs post-commit \"\$@\""
87
88 post_merge_hook="#!/bin/sh
89 command -v git-lfs >/dev/null 2>&1 || { printf >&2 \"\\n%s\\n\\n\" \"This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\"; exit 2; }
90 git lfs post-merge \"\$@\""
91
92 [scip-shell system . . `[`. "Updated Git hooks.
93 Git LFS initialized." = "$(gitscip-shell system . . git. lfs install)" ]
94 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
95 [scip-shell system . . `[`. "$post_checkout_hook" = "$(catscip-shell system . . cat. .git/hooks/post-checkout)" ]
96 [scip-shell system . . `[`. "$post_commit_hook" = "$(catscip-shell system . . cat. .git/hooks/post-commit)" ]
97 [scip-shell system . . `[`. "$post_merge_hook" = "$(catscip-shell system . . cat. .git/hooks/post-merge)" ]
98
99 # replace old hook
100 # more-comprehensive hook update tests are in test-update.sh
101 echoscip-shell system . . echo. "#!/bin/sh
102 git lfs push --stdin \$*" > .git/hooks/pre-push
103 [scip-shell system . . `[`. "Updated Git hooks.
104 Git LFS initialized." = "$(gitscip-shell system . . git. lfs install)" ]
105 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
106
107 # don't replace unexpected hook
108 expected="Hook already exists: pre-push
109
110 test
111
112 To resolve this, either:
113 1: run \`git lfs update --manual\` for instructions on how to merge hooks.
114 2: run \`git lfs update --force\` to overwrite your hook."
115
116 echoscip-shell system . . echo. "test" > .git/hooks/pre-push
117 echoscip-shell system . . echo. "test" > .git/hooks/post-checkout
118 echoscip-shell system . . echo. "test" > .git/hooks/post-commit
119 echoscip-shell system . . echo. "test" > .git/hooks/post-merge
120 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
121 [scip-shell system . . `[`. "$expected" = "$(gitscip-shell system . . git. lfs install 2>&1)" ]
122 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
123 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. .git/hooks/post-checkout)" ]
124 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. .git/hooks/post-commit)" ]
125 [scip-shell system . . `[`. "test" = "$(catscip-shell system . . cat. .git/hooks/post-merge)" ]
126
127 # Make sure returns non-zero
128 set +e
129 gitscip-shell system . . git. lfs install
130 if [scip-shell system . . `[`. $? -eq 0 ]
131 then
132 exit 1
133 fi
134 set -e
135
136 # force replace unexpected hook
137 [scip-shell system . . `[`. "Updated Git hooks.
138 Git LFS initialized." = "$(gitscip-shell system . . git. lfs install --force)" ]
139 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. .git/hooks/pre-push)" ]
140 [scip-shell system . . `[`. "$post_checkout_hook" = "$(catscip-shell system . . cat. .git/hooks/post-checkout)" ]
141 [scip-shell system . . `[`. "$post_commit_hook" = "$(catscip-shell system . . cat. .git/hooks/post-commit)" ]
142 [scip-shell system . . `[`. "$post_merge_hook" = "$(catscip-shell system . . cat. .git/hooks/post-merge)" ]
143
144 has_test_dir || exit 0
145
146 echoscip-shell system . . echo. "test with bare repository"
147 cd ..
148 gitscip-shell system . . git. clone --mirror install-repo-hooks bare-install-repo-hooks
149 cd bare-install-repo-hooks
150 gitscip-shell system . . git. lfs env
151 gitscip-shell system . . git. lfs install
152 lsscip-shell system . . ls. -al hooks
153 [scip-shell system . . `[`. "$pre_push_hook" = "$(catscip-shell system . . cat. hooks/pre-push)" ]
154 )
155 end_test
156
157 begin_test "install outside repository directory"
158 (
159 set -e
160 if [scip-shell system . . `[`. -d "hooks" ]; then
161 lsscip-shell system . . ls. -al
162 echoscip-shell system . . echo. "hooks dir exists"
163 exit 1
164 fi
165
166 gitscip-shell system . . git. lfs install > check.log 2>&1
167
168 if [scip-shell system . . `[`. -d "hooks" ]; then
169 lsscip-shell system . . ls. -al
170 echoscip-shell system . . echo. "hooks dir exists"
171 exit 1
172 fi
173
174 catscip-shell system . . cat. check.log
175
176 # doesn't print this because being in a git repo is not necessary for install
177 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "Not in a Git repository" check.log)" ]
178 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "Error" check.log)" ]
179 )
180 end_test
181
182 begin_test "install --skip-smudge"
183 (
184 set -e
185
186 mkdirscip-shell system . . mkdir. install-skip-smudge-test
187 cd install-skip-smudge-test
188
189 gitscip-shell system . . git. lfs install
190 [scip-shell system . . `[`. "git-lfs clean -- %f" = "$(gitscip-shell system . . git. config --global filter.lfs.clean)" ]
191 [scip-shell system . . `[`. "git-lfs smudge -- %f" = "$(gitscip-shell system . . git. config --global filter.lfs.smudge)" ]
192 [scip-shell system . . `[`. "git-lfs filter-process" = "$(gitscip-shell system . . git. config --global filter.lfs.process)" ]
193
194 gitscip-shell system . . git. lfs install --skip-smudge
195 [scip-shell system . . `[`. "git-lfs clean -- %f" = "$(gitscip-shell system . . git. config --global filter.lfs.clean)" ]
196 [scip-shell system . . `[`. "git-lfs smudge --skip -- %f" = "$(gitscip-shell system . . git. config --global filter.lfs.smudge)" ]
197 [scip-shell system . . `[`. "git-lfs filter-process --skip" = "$(gitscip-shell system . . git. config --global filter.lfs.process)" ]
198
199 gitscip-shell system . . git. lfs install
200 [scip-shell system . . `[`. "git-lfs clean -- %f" = "$(gitscip-shell system . . git. config --global filter.lfs.clean)" ]
201 [scip-shell system . . `[`. "git-lfs smudge -- %f" = "$(gitscip-shell system . . git. config --global filter.lfs.smudge)" ]
202 [scip-shell system . . `[`. "git-lfs filter-process" = "$(gitscip-shell system . . git. config --global filter.lfs.process)" ]
203
204 [scip-shell system . . `[`. ! -e "lfs" ]
205 )
206 end_test
207
208 begin_test "install --local"
209 (
210 set -e
211
212 # old values that should be ignored by `install --local`
213 gitscip-shell system . . git. config --global filter.lfs.smudge "global smudge"
214 gitscip-shell system . . git. config --global filter.lfs.clean "global clean"
215 gitscip-shell system . . git. config --global filter.lfs.process "global filter"
216
217 mkdirscip-shell system . . mkdir. install-local-repo
218 cd install-local-repo
219 gitscip-shell system . . git. init
220 gitscip-shell system . . git. lfs install --local
221
222 # local configs are correct
223 [scip-shell system . . `[`. "git-lfs smudge -- %f" = "$(gitscip-shell system . . git. config filter.lfs.smudge)" ]
224 [scip-shell system . . `[`. "git-lfs smudge -- %f" = "$(gitscip-shell system . . git. config --local filter.lfs.smudge)" ]
225 [scip-shell system . . `[`. "git-lfs clean -- %f" = "$(gitscip-shell system . . git. config filter.lfs.clean)" ]
226 [scip-shell system . . `[`. "git-lfs clean -- %f" = "$(gitscip-shell system . . git. config --local filter.lfs.clean)" ]
227 [scip-shell system . . `[`. "git-lfs filter-process" = "$(gitscip-shell system . . git. config filter.lfs.process)" ]
228 [scip-shell system . . `[`. "git-lfs filter-process" = "$(gitscip-shell system . . git. config --local filter.lfs.process)" ]
229
230 # global configs
231 [scip-shell system . . `[`. "global smudge" = "$(gitscip-shell system . . git. config --global filter.lfs.smudge)" ]
232 [scip-shell system . . `[`. "global clean" = "$(gitscip-shell system . . git. config --global filter.lfs.clean)" ]
233 [scip-shell system . . `[`. "global filter" = "$(gitscip-shell system . . git. config --global filter.lfs.process)" ]
234 )
235 end_test
236
237 begin_test "install --file"
238 (
239 set -e
240
241 # old values that should be ignored by `install --local`
242 gitscip-shell system . . git. config --global filter.lfs.smudge "global smudge"
243 gitscip-shell system . . git. config --global filter.lfs.clean "global clean"
244 gitscip-shell system . . git. config --global filter.lfs.process "global filter"
245
246 mkdirscip-shell system . . mkdir. install-file-repo
247 cd install-file-repo
248 gitscip-shell system . . git. init
249 gitscip-shell system . . git. lfs install --file=test-file
250
251 # local configs are correct
252 [scip-shell system . . `[`. "git-lfs smudge -- %f" = "$(gitscip-shell system . . git. config --file test-file filter.lfs.smudge)" ]
253 [scip-shell system . . `[`. "git-lfs clean -- %f" = "$(gitscip-shell system . . git. config --file test-file filter.lfs.clean)" ]
254 [scip-shell system . . `[`. "git-lfs filter-process" = "$(gitscip-shell system . . git. config --file test-file filter.lfs.process)" ]
255
256 # global configs
257 [scip-shell system . . `[`. "global smudge" = "$(gitscip-shell system . . git. config --global filter.lfs.smudge)" ]
258 [scip-shell system . . `[`. "global clean" = "$(gitscip-shell system . . git. config --global filter.lfs.clean)" ]
259 [scip-shell system . . `[`. "global filter" = "$(gitscip-shell system . . git. config --global filter.lfs.process)" ]
260 )
261 end_test
262
263 begin_test "install --local with failed permissions"
264 (
265 set -e
266
267 # Windows lacks POSIX permissions.
268 [scip-shell system . . `[`. "$IS_WINDOWS" -eq 1 ] && exit 0
269
270 # Root is exempt from permissions.
271 [scip-shell system . . `[`. "$(idscip-shell system . . id. -u)" -eq 0 ] && exit 0
272
273 mkdirscip-shell system . . mkdir. install-local-repo-perms
274 cd install-local-repo-perms
275 gitscip-shell system . . git. init
276
277 # Make it impossible to write a new .git/config file so we can't write config
278 # options.
279 chmodscip-shell system . . chmod. 500 .git
280
281 res=0
282 gitscip-shell system . . git. lfs install --local >out.log || res=$?
283
284 # Cleanup fails without this.
285 chmodscip-shell system . . chmod. 700 .git
286
287 catscip-shell system . . cat. out.log
288 grepscip-shell system . . grep. -E "error running.*git.*config" out.log
289 [scip-shell system . . `[`. "$res" -eq 2 ]
290 )
291 end_test
292
293 begin_test "install --local outside repository"
294 (
295 set -e
296
297 # If run inside the git-lfs source dir this will update its .git/config & cause issues
298 if [scip-shell system . . `[`. "$GIT_LFS_TEST_DIR" == "" ]; then
299 echoscip-shell system . . echo. "Skipping install --local because GIT_LFS_TEST_DIR is not set"
300 exit 0
301 fi
302
303 has_test_dir || exit 0
304
305 set +e
306 gitscip-shell system . . git. lfs install --local >out.log
307 res=$?
308 set -e
309
310 [scip-shell system . . `[`. "Not in a Git repository." = "$(catscip-shell system . . cat. out.log)" ]
311 [scip-shell system . . `[`. "0" != "$res" ]
312 )
313 end_test
314
315 begin_test "install --local with conflicting scope"
316 (
317 set -e
318
319 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-scope-conflict"
320 mkdirscip-shell system . . mkdir. "$reponame"
321 cd "$reponame"
322 gitscip-shell system . . git. init
323
324 set +e
325 gitscip-shell system . . git. lfs install --local --system 2>err.log
326 res=$?
327 set -e
328
329 [scip-shell system . . `[`. "Only one of the --local, --system, --worktree, and --file options can be specified." = "$(catscip-shell system . . cat. err.log)" ]
330 [scip-shell system . . `[`. "0" != "$res" ]
331 )
332 end_test
333
334 begin_test "install in directory without access to .git/lfs"
335 (
336 set -e
337 mkdirscip-shell system . . mkdir. not-a-repo
338 cd not-a-repo
339 mkdirscip-shell system . . mkdir. .git
340 touchscip-shell system . . touch. .git/lfs
341 touchscip-shell system . . touch. lfs
342
343 gitscip-shell system . . git. config --global filter.lfs.clean whatevs
344 [scip-shell system . . `[`. "whatevs" = "$(gitscip-shell system . . git. config filter.lfs.clean)" ]
345
346 gitscip-shell system . . git. lfs install --force
347
348 [scip-shell system . . `[`. "git-lfs clean -- %f" = "$(gitscip-shell system . . git. config filter.lfs.clean)" ]
349 )
350 end_test
351
352 begin_test "install in repo without changing hooks"
353 (
354 set -e
355 gitscip-shell system . . git. init non-lfs-repo
356 cd non-lfs-repo
357
358 gitscip-shell system . . git. lfs install --skip-repo
359
360 # should not install hooks
361 [scip-shell system . . `[`. ! -f .git/hooks/pre-push ]
362 [scip-shell system . . `[`. ! -f .git/hooks/post-checkout ]
363 [scip-shell system . . `[`. ! -f .git/hooks/post-merge ]
364 [scip-shell system . . `[`. ! -f .git/hooks/post-commit ]
365
366 # filters should still be installed
367 [scip-shell system . . `[`. "git-lfs clean -- %f" = "$(gitscip-shell system . . git. config filter.lfs.clean)" ]
368 [scip-shell system . . `[`. "git-lfs smudge -- %f" = "$(gitscip-shell system . . git. config filter.lfs.smudge)" ]
369 [scip-shell system . . `[`. "git-lfs filter-process" = "$(gitscip-shell system . . git. config filter.lfs.process)" ]
370 )
371 end_test
372
373 begin_test "can install when multiple global values registered"
374 (
375 set -e
376
377 gitscip-shell system . . git. config --global filter.lfs.smudge "git-lfs smudge --something %f"
378 gitscip-shell system . . git. config --global --add filter.lfs.smudge "git-lfs smudge --something-else %f"
379
380 gitscip-shell system . . git. lfs install --force
381 )
382 end_test