Debian Codegraph @

t/t-lock.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 "lock with good ref"
6 (
7 set -e
8
9 reponame="lock-main-branch-required"
10 setup_remote_repo_with_file "$reponame" "a.dat"
11 clone_repo "$reponame" "$reponame"
12
13 gitscip-shell system . . git. lfs lock "a.dat" --json 2>&1 | teescip-shell system . . tee. lock.json
14 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
15 echoscip-shell system . . echo. >&2 "fatal: expected \'git lfs lock \'a.dat\'\' to succeed"
16 exit 1
17 fi
18
19 id=$(assert_lock lock.json a.dat)
20 assert_server_lock "$reponame" "$id" "refs/heads/main"
21 )
22 end_test
23
24 begin_test "lock with good tracked ref"
25 (
26 set -e
27
28 reponame="lock-tracked-branch-required"
29 setup_remote_repo "$reponame"
30 clone_repo "$reponame" "$reponame"
31
32 gitscip-shell system . . git. lfs track "*.dat"
33 echoscip-shell system . . echo. "a" > a.dat
34 gitscip-shell system . . git. add .gitattributes a.dat
35 gitscip-shell system . . git. commit -m "add a.dat"
36
37 gitscip-shell system . . git. config push.default upstream
38 gitscip-shell system . . git. config branch.main.merge refs/heads/tracked
39 gitscip-shell system . . git. config branch.main.remote origin
40 gitscip-shell system . . git. push origin main
41
42 gitscip-shell system . . git. lfs lock "a.dat" --json 2>&1 | teescip-shell system . . tee. lock.json
43 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
44 echoscip-shell system . . echo. >&2 "fatal: expected \'git lfs lock \'a.dat\'\' to succeed"
45 exit 1
46 fi
47
48 id=$(assert_lock lock.json a.dat)
49 assert_server_lock "$reponame" "$id" "refs/heads/tracked"
50 )
51 end_test
52
53 begin_test "lock with good ref (--remote overrides push default)"
54 (
55 set -e
56
57 reponame="lock-remote"
58 setup_remote_repo_with_file "$reponame" "a.dat"
59 clone_repo "$reponame" "$reponame"
60
61 # Check invalid "remote.pushDefault" configuration causes error.
62 gitscip-shell system . . git. remote add bad-remote "invalid-url"
63 gitscip-shell system . . git. config remote.pushDefault bad-remote
64
65 gitscip-shell system . . git. lfs lock "a.dat" 2>&1 | teescip-shell system . . tee. lock.log
66 if [scip-shell system . . `[`. "0" -eq "${PIPESTATUS[0]}" ]; then
67 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs lock' to fail ..."
68 exit 1
69 fi
70
71 # Check --remote option overrides "remote.pushDefault" configuration.
72 gitscip-shell system . . git. lfs lock --remote origin --json "a.dat" | teescip-shell system . . tee. lock.log
73 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
74 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs lock' to succeed ..."
75 exit 1
76 fi
77
78 id=$(assert_lock lock.log "a.dat")
79 assert_server_lock "$reponame" "$id" "refs/heads/main"
80
81 # Remove "remote.pushDefault" configuration and unlock.
82 gitscip-shell system . . git. config --unset remote.pushDefault
83
84 gitscip-shell system . . git. lfs unlock "a.dat"
85 refute_server_lock "$reponame" "$id" "refs/heads/main"
86
87 # Check invalid "branch.<name>.pushRemote" configuration causes error.
88 gitscip-shell system . . git. config branch.main.pushRemote bad-remote
89
90 gitscip-shell system . . git. lfs lock "a.dat" 2>&1 | teescip-shell system . . tee. lock.log
91 if [scip-shell system . . `[`. "0" -eq "${PIPESTATUS[0]}" ]; then
92 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs lock' to fail ..."
93 exit 1
94 fi
95
96 # Check --remote option overrides "branch.<name>.pushRemote" configuration.
97 gitscip-shell system . . git. lfs lock --remote origin --json "a.dat" | teescip-shell system . . tee. lock.log
98 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
99 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs lock' to succeed ..."
100 exit 1
101 fi
102
103 id=$(assert_lock lock.log "a.dat")
104 assert_server_lock "$reponame" "$id" "refs/heads/main"
105 )
106 end_test
107
108 begin_test "lock with bad ref"
109 (
110 set -e
111
112 reponame="lock-other-branch-required"
113 setup_remote_repo "$reponame"
114 clone_repo "$reponame" "$reponame"
115
116 gitscip-shell system . . git. lfs track "*.dat"
117 echoscip-shell system . . echo. "a" > a.dat
118 gitscip-shell system . . git. add .gitattributes a.dat
119 gitscip-shell system . . git. commit -m "add a.dat"
120 gitscip-shell system . . git. push origin main:other
121
122 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. lfs lock "a.dat" 2>&1 | teescip-shell system . . tee. lock.json
123 if [scip-shell system . . `[`. "0" -eq "${PIPESTATUS[0]}" ]; then
124 echoscip-shell system . . echo. >&2 "fatal: expected \'git lfs lock \'a.dat\'\' to fail"
125 exit 1
126 fi
127
128 grepscip-shell system . . grep. 'Locking a.dat failed: Expected ref "refs/heads/other", got "refs/heads/main"' lock.json
129 )
130 end_test
131
132 begin_test "lock multiple files"
133 (
134 set -e
135
136 reponame="lock-multiple-files"
137 setup_remote_repo "$reponame"
138 clone_repo "$reponame" "$reponame"
139
140 gitscip-shell system . . git. lfs track "*.dat"
141 echoscip-shell system . . echo. "a" > a.dat
142 echoscip-shell system . . echo. "b" > b.dat
143 gitscip-shell system . . git. add .gitattributes a.dat b.dat
144 gitscip-shell system . . git. commit -m "add dat files"
145 gitscip-shell system . . git. push origin main:other
146
147 GIT_TRACE=0 gitscip-shell system . . git. lfs lock *.dat >log 2>errlog
148 [scip-shell system . . `[`. $(grepscip-shell system . . grep. -c "Locked [ab].dat" log) -eq 2 ]
149 grepscip-shell system . . grep. -v CREDS errlog && exit 1
150 grepscip-shell system . . grep. "Usage:" errlog && exit 1
151 truescip-shell system . . true.
152 )
153 end_test
154
155 begin_test "lock multiple files (JSON)"
156 (
157 set -e
158
159 reponame="lock-multiple-files-json"
160 setup_remote_repo "$reponame"
161 clone_repo "$reponame" "$reponame"
162
163 gitscip-shell system . . git. lfs track "*.dat"
164 echoscip-shell system . . echo. "a" > a.dat
165 echoscip-shell system . . echo. "b" > b.dat
166 gitscip-shell system . . git. add .gitattributes a.dat b.dat
167 gitscip-shell system . . git. commit -m "add dat files"
168 gitscip-shell system . . git. push origin main:other
169
170 gitscip-shell system . . git. lfs lock --json *.dat | teescip-shell system . . tee. lock.json
171 grepscip-shell system . . grep. -E '\[\{"id":"[^"]+","path":"a\.dat","owner":\{"name":"Git LFS Tests"\},"locked_at":"[^"]+"\},\{"id":"[^"]+","path":"b\.dat","owner":\{"name":"Git LFS Tests"\},"locked_at":"[^"]+"\}\]' lock.json
172 )
173 end_test
174
175 begin_test "lock absolute path"
176 (
177 set -e
178
179 reponame="lock-absolute-path"
180 setup_remote_repo "$reponame"
181 clone_repo "$reponame" "$reponame"
182
183 gitscip-shell system . . git. lfs track "*.dat"
184 echoscip-shell system . . echo. "a" > a.dat
185 echoscip-shell system . . echo. "b" > b.dat
186 gitscip-shell system . . git. add .gitattributes a.dat b.dat
187 gitscip-shell system . . git. commit -m "add dat files"
188 gitscip-shell system . . git. push origin main:other
189
190 gitscip-shell system . . git. lfs lock --json "$(pwdscip-shell system . . pwd.)/a.dat" | teescip-shell system . . tee. lock.json
191 id=$(assert_lock lock.json a.dat)
192 assert_server_lock "$reponame" "$id"
193 )
194 end_test
195
196 begin_test "create lock with server using client cert"
197 (
198 set -e
199
200 gitscip-shell system . . git. config --global "http.$LFS_CLIENT_CERT_URL/.sslCert" "$LFS_CLIENT_CERT_FILE"
201 gitscip-shell system . . git. config --global "http.$LFS_CLIENT_CERT_URL/.sslKey" "$LFS_CLIENT_KEY_FILE"
202
203 reponame="lock_create_client_cert"
204 setup_remote_repo_with_file "$reponame" "cc.dat"
205
206 gitscip-shell system . . git. config lfs.url "$CLIENTCERTGITSERVER/$reponame.git/info/lfs"
207 gitscip-shell system . . git. lfs lock --json "cc.dat" | teescip-shell system . . tee. lock.json
208 id=$(assert_lock lock.json cc.dat)
209 assert_server_lock "$reponame" "$id"
210 )
211 end_test
212
213 begin_test "creating a lock (with output)"
214 (
215 set -e
216
217 reponame="lock_create_simple_output"
218 setup_remote_repo_with_file "$reponame" "a_output.dat"
219
220 gitscip-shell system . . git. lfs lock "a_output.dat" | teescip-shell system . . tee. lock.log
221 grepscip-shell system . . grep. "Locked a_output.dat" lock.log
222 id=$(grepscip-shell system . . grep. -oh "\((.*)\)" lock.log | trscip-shell system . . tr. -d \(\))
223 assert_server_lock "$reponame" "$id"
224 )
225 end_test
226
227 begin_test "locking a file that doesn't exist"
228 (
229 set -e
230
231 reponame="lock_create_nonexistent"
232 setup_remote_repo_with_file "$reponame" "a_output.dat"
233
234 gitscip-shell system . . git. lfs lock "b_output.dat" | teescip-shell system . . tee. lock.log
235 grepscip-shell system . . grep. "Locked b_output.dat" lock.log
236 id=$(grepscip-shell system . . grep. -oh "\((.*)\)" lock.log | trscip-shell system . . tr. -d \(\))
237 assert_server_lock "$reponame" "$id"
238 )
239 end_test
240
241 begin_test "locking a previously locked file"
242 (
243 set -e
244
245 reponame="lock_create_previously_created"
246 setup_remote_repo_with_file "$reponame" "b.dat"
247
248 gitscip-shell system . . git. lfs lock --json "b.dat" | teescip-shell system . . tee. lock.json
249 id=$(assert_lock lock.json b.dat)
250 assert_server_lock "$reponame" "$id"
251
252 grepscip-shell system . . grep. "lock already created" <(gitscip-shell system . . git. lfs lock "b.dat" 2>&1)
253 )
254 end_test
255
256 begin_test "locking a directory"
257 (
258 set -e
259
260 reponame="locking_directories"
261 setup_remote_repo "remote_$reponame"
262 clone_repo "remote_$reponame" "clone_$reponame"
263
264 gitscip-shell system . . git. lfs track "*.dat"
265 mkdirscip-shell system . . mkdir. dir
266 echoscip-shell system . . echo. "a" > dir/a.dat
267
268 gitscip-shell system . . git. add dir/a.dat .gitattributes
269
270 gitscip-shell system . . git. commit -m "add dir/a.dat" | teescip-shell system . . tee. commit.log
271 grepscip-shell system . . grep. "main (root-commit)" commit.log
272 grepscip-shell system . . grep. "2 files changed" commit.log
273 grepscip-shell system . . grep. "create mode 100644 dir/a.dat" commit.log
274 grepscip-shell system . . grep. "create mode 100644 .gitattributes" commit.log
275
276 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
277 grepscip-shell system . . grep. "main -> main" push.log
278
279 gitscip-shell system . . git. lfs lock ./dir/ 2>&1 | teescip-shell system . . tee. lock.log
280 grepscip-shell system . . grep. "cannot lock directory" lock.log
281 )
282 end_test
283
284 begin_test "locking a nested file"
285 (
286 set -e
287
288 reponame="locking-nested-file"
289 setup_remote_repo "$reponame"
290 clone_repo "$reponame" "$reponame"
291
292 gitscip-shell system . . git. lfs track "*.dat" --lockable
293 gitscip-shell system . . git. add .gitattributes
294 gitscip-shell system . . git. commit -m "initial commit"
295
296 mkdirscip-shell system . . mkdir. -p foo/bar/baz
297
298 contents="contents"
299 contents_oid="$(calc_oid "$contents")"
300
301 printfscip-shell system . . printf. "%s" "$contents" > foo/bar/baz/a.dat
302 gitscip-shell system . . git. add foo/bar/baz/a.dat
303 gitscip-shell system . . git. commit -m "add a.dat"
304
305 gitscip-shell system . . git. push origin main
306
307 assert_server_object "$reponame" "$contents_oid"
308
309 gitscip-shell system . . git. lfs lock foo/bar/baz/a.dat 2>&1 | teescip-shell system . . tee. lock.log
310 grepscip-shell system . . grep. "Locked foo/bar/baz/a.dat" lock.log
311
312 gitscip-shell system . . git. lfs locks 2>&1 | teescip-shell system . . tee. locks.log
313 grepscip-shell system . . grep. "foo/bar/baz/a.dat" locks.log
314 )
315 end_test
316
317 begin_test "creating a lock (within subdirectory)"
318 (
319 set -e
320
321 reponame="lock_create_within_subdirectory"
322 setup_remote_repo_with_file "$reponame" "sub/a.dat"
323
324 cd sub
325
326 gitscip-shell system . . git. lfs lock --json "a.dat" | teescip-shell system . . tee. lock.json
327 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
328 echoscip-shell system . . echo. >&2 "fatal: expected \'git lfs lock \'a.dat\'\' to succeed"
329 exit 1
330 fi
331
332 id=$(assert_lock lock.json sub/a.dat)
333 assert_server_lock "$reponame" "$id"
334 )
335 end_test
336
337 begin_test "creating a lock (symlinked working directory)"
338 (
339 set -eo pipefail
340
341 if [[ $(uname) == *"MINGW"* ]]; then
342 echoscip-shell system . . echo. >&2 "info: skipped on Windows ..."
343 exit 0
344 fi
345
346 reponame="lock-in-symlinked-working-directory"
347 setup_remote_repo "$reponame"
348 clone_repo "$reponame" "$reponame"
349
350 gitscip-shell system . . git. lfs track -l "*.dat"
351 mkdirscip-shell system . . mkdir. -p folder1 folder2
352 printfscip-shell system . . printf. "hello" > folder2/a.dat
353 add_symlink "../folder2" "folder1/folder2"
354
355 gitscip-shell system . . git. add --all .
356 gitscip-shell system . . git. commit -m "initial commit"
357 gitscip-shell system . . git. push origin main
358
359 pushd "$TRASHDIR" > /dev/nullscip-shell filesystem . . `/dev/null`.
360 lnscip-shell system . . ln. -s "$reponame" "$reponame-symlink"
361 cd "$reponame-symlink"
362
363 gitscip-shell system . . git. lfs lock --json folder1/folder2/a.dat 2>&1 | teescip-shell system . . tee. lock.json
364
365 id="$(assert_lock lock.json folder1/folder2/a.dat)"
366 assert_server_lock "$reponame" "$id" main
367 popd > /dev/nullscip-shell filesystem . . `/dev/null`.
368 )
369 end_test
370
371 begin_test "lock with .gitignore"
372 (
373 set -e
374
375 reponame="lock-with-gitignore"
376 setup_remote_repo_with_file "$reponame" "a.txt"
377 clone_repo "$reponame" "$reponame"
378
379 echoscip-shell system . . echo. "*.txt filter=lfs diff=lfs merge=lfs -text lockable" > .gitattributes
380
381 gitscip-shell system . . git. add .gitattributes
382 gitscip-shell system . . git. commit -m ".gitattributes: mark 'a.txt' as lockable"
383
384 rmscip-shell system . . rm. -f a.txt && gitscip-shell system . . git. checkout a.txt
385 refute_file_writeable a.txt
386
387 echoscip-shell system . . echo. "*.txt" > .gitignore
388 gitscip-shell system . . git. add .gitignore
389 gitscip-shell system . . git. commit -m ".gitignore: ignore 'a.txt'"
390 rmscip-shell system . . rm. -f a.txt && gitscip-shell system . . git. checkout a.txt
391 refute_file_writeable a.txt
392 )
393 end_test
394
395
396 begin_test "lock with .gitignore and lfs.lockignoredfiles"
397 (
398 set -e
399
400 reponame="lock-with-gitignore-and-ignoredfiles"
401 setup_remote_repo_with_file "$reponame" "a.txt"
402 clone_repo "$reponame" "$reponame"
403
404 gitscip-shell system . . git. config lfs.lockignoredfiles true
405 echoscip-shell system . . echo. "*.txt filter=lfs diff=lfs merge=lfs -text lockable" > .gitattributes
406
407 gitscip-shell system . . git. add .gitattributes
408 gitscip-shell system . . git. commit -m ".gitattributes: mark 'a.txt' as lockable"
409
410 rmscip-shell system . . rm. -f a.txt && gitscip-shell system . . git. checkout a.txt
411 refute_file_writeable a.txt
412
413 echoscip-shell system . . echo. "*.txt" > .gitignore
414 gitscip-shell system . . git. add .gitignore
415 gitscip-shell system . . git. commit -m ".gitignore: ignore 'a.txt'"
416 rmscip-shell system . . rm. -f a.txt && gitscip-shell system . . git. checkout a.txt
417 refute_file_writeable a.txt
418 )
419 end_test
420
421 begin_test "lock with git-lfs-transfer"
422 (
423 set -e
424
425 setup_pure_ssh
426
427 reponame="lock-with-git-lfs-transfer"
428 setup_remote_repo_with_file "$reponame" "f.dat"
429 clone_repo "$reponame" "$reponame"
430
431 sshurl=$(ssh_remote "$reponame")
432 gitscip-shell system . . git. config lfs.url "$sshurl"
433
434 GIT_TRACE_PACKET=1 gitscip-shell system . . git. lfs lock --json "f.dat" | teescip-shell system . . tee. lock.log
435
436 id=$(assert_lock lock.log f.dat)
437 assert_server_lock_ssh "$reponame" "$id" "refs/heads/main"
438 )
439 end_test