Debian Codegraph @

t/t-locks.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 "list a single lock with bad ref"
6 (
7 set -e
8
9 reponame="locks-list-other-branch-required"
10 setup_remote_repo "$reponame"
11 clone_repo "$reponame" "$reponame"
12
13 gitscip-shell system . . git. lfs track "*.dat"
14 echoscip-shell system . . echo. "f" > f.dat
15 gitscip-shell system . . git. add .gitattributes f.dat
16 gitscip-shell system . . git. commit -m "add f.dat"
17 gitscip-shell system . . git. push origin main:other
18
19 gitscip-shell system . . git. checkout -b other
20 gitscip-shell system . . git. lfs lock --json "f.dat" | teescip-shell system . . tee. lock.log
21
22 gitscip-shell system . . git. checkout main
23 gitscip-shell system . . git. lfs locks --path "f.dat" 2>&1 | teescip-shell system . . tee. locks.log
24 if [scip-shell system . . `[`. "0" -eq "${PIPESTATUS[0]}" ]; then
25 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs lock \'a.dat\'' to fail"
26 exit 1
27 fi
28
29 grepscip-shell system . . grep. 'Expected ref "refs/heads/other", got "refs/heads/main"' locks.log
30 )
31 end_test
32
33 begin_test "list a single lock"
34 (
35 set -e
36
37 reponame="locks-list-main-branch-required"
38 setup_remote_repo_with_file "$reponame" "f.dat"
39 clone_repo "$reponame" "$reponame"
40
41 gitscip-shell system . . git. lfs lock --json "f.dat" | teescip-shell system . . tee. lock.log
42
43 id=$(assert_lock lock.log f.dat)
44 assert_server_lock "$reponame" "$id" "refs/heads/main"
45
46 gitscip-shell system . . git. lfs locks --path "f.dat" | teescip-shell system . . tee. locks.log
47 [scip-shell system . . `[`. $(wcscip-shell system . . wc. -l < locks.log) -eq 1 ]
48 grepscip-shell system . . grep. "f.dat" locks.log
49 grepscip-shell system . . grep. "Git LFS Tests" locks.log
50 )
51 end_test
52
53 begin_test "list a single lock (--remote overrides push default)"
54 (
55 set -e
56
57 reponame="locks-list-remote"
58 setup_remote_repo_with_file "$reponame" "a.dat"
59 clone_repo "$reponame" "$reponame"
60
61 gitscip-shell system . . git. lfs lock --json "a.dat" | teescip-shell system . . tee. lock.log
62
63 id=$(assert_lock lock.log "a.dat")
64 assert_server_lock "$reponame" "$id" "refs/heads/main"
65
66 # Check invalid "remote.pushDefault" configuration causes error.
67 gitscip-shell system . . git. remote add bad-remote "invalid-url"
68 gitscip-shell system . . git. config remote.pushDefault bad-remote
69
70 gitscip-shell system . . git. lfs locks 2>&1 | teescip-shell system . . tee. locks.log
71 if [scip-shell system . . `[`. "0" -eq "${PIPESTATUS[0]}" ]; then
72 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs locks' to fail ..."
73 exit 1
74 fi
75
76 # Check --remote option overrides "remote.pushDefault" configuration.
77 gitscip-shell system . . git. lfs locks --remote origin --path "a.dat" | teescip-shell system . . tee. locks.log
78 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
79 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs locks' to succeed ..."
80 exit 1
81 fi
82
83 [scip-shell system . . `[`. 1 -eq "$(wcscip-shell system . . wc. -l <locks.log)" ]
84 grepscip-shell system . . grep. -F "a.dat" locks.log
85 grepscip-shell system . . grep. -F "ID:$id" locks.log
86
87 # Remove "remote.pushDefault" configuration.
88 gitscip-shell system . . git. config --unset remote.pushDefault
89
90 # Check invalid "branch.<name>.pushRemote" configuration causes error.
91 gitscip-shell system . . git. config branch.main.pushRemote bad-remote
92
93 gitscip-shell system . . git. lfs locks 2>&1 | teescip-shell system . . tee. locks.log
94 if [scip-shell system . . `[`. "0" -eq "${PIPESTATUS[0]}" ]; then
95 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs locks' to fail ..."
96 exit 1
97 fi
98
99 # Check --remote option overrides "branch.<name>.pushRemote" configuration.
100 gitscip-shell system . . git. lfs locks --remote origin --path "a.dat" | teescip-shell system . . tee. locks.log
101 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
102 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs locks' to succeed ..."
103 exit 1
104 fi
105
106 [scip-shell system . . `[`. 1 -eq "$(wcscip-shell system . . wc. -l <locks.log)" ]
107 grepscip-shell system . . grep. -F "a.dat" locks.log
108 grepscip-shell system . . grep. -F "ID:$id" locks.log
109 )
110 end_test
111
112 begin_test "list a single lock (SSH; git-lfs-authenticate)"
113 (
114 set -e
115
116 reponame="locks-list-ssh"
117 setup_remote_repo_with_file "$reponame" "f.dat"
118 clone_repo "$reponame" "$reponame"
119
120 sshurl="${GITSERVER/http:\/\//ssh://git@}/$reponame"
121 gitscip-shell system . . git. config lfs.url "$sshurl"
122
123 gitscip-shell system . . git. lfs lock --json "f.dat" | teescip-shell system . . tee. lock.log
124
125 id=$(assert_lock lock.log f.dat)
126 assert_server_lock "$reponame" "$id" "refs/heads/main"
127
128 GIT_TRACE=1 gitscip-shell system . . git. lfs locks --path "f.dat" 2>trace.log | teescip-shell system . . tee. locks.log
129 catscip-shell system . . cat. trace.log
130 [scip-shell system . . `[`. $(wcscip-shell system . . wc. -l < locks.log) -eq 1 ]
131 grepscip-shell system . . grep. "f.dat" locks.log
132 grepscip-shell system . . grep. "Git LFS Tests" locks.log
133 grepscip-shell system . . grep. "lfs-ssh-echo.*git-lfs-authenticate /$reponame download" trace.log
134
135 GIT_TRACE=1 gitscip-shell system . . git. -c lfs."$sshurl".sshtransfer=never lfs locks --path "f.dat" 2>trace.log | teescip-shell system . . tee. locks.log
136 [scip-shell system . . `[`. $(wcscip-shell system . . wc. -l < locks.log) -eq 1 ]
137 grepscip-shell system . . grep. "f.dat" locks.log
138 grepscip-shell system . . grep. "Git LFS Tests" locks.log
139 grepscip-shell system . . grep. "lfs-ssh-echo.*git-lfs-authenticate /$reponame download" trace.log
140 grepscip-shell system . . grep. "skipping pure SSH protocol" trace.log
141
142 GIT_TRACE=1 gitscip-shell system . . git. -c lfs."$sshurl".sshtransfer=always lfs locks --path "f.dat" 2>trace.log && exit 1
143 grepscip-shell system . . grep. "git-lfs-authenticate has been disabled by request" trace.log
144 )
145 end_test
146
147 begin_test "list a single lock (SSH; git-lfs-transfer)"
148 (
149 set -e
150
151 setup_pure_ssh
152
153 reponame="locks-list-ssh-pure"
154 setup_remote_repo_with_file "$reponame" "f.dat"
155 clone_repo "$reponame" "$reponame"
156
157 sshurl=$(ssh_remote "$reponame")
158 gitscip-shell system . . git. config lfs.url "$sshurl"
159
160 GIT_TRACE_PACKET=1 gitscip-shell system . . git. lfs lock --json "f.dat" | teescip-shell system . . tee. lock.log
161
162 id=$(assert_lock lock.log f.dat)
163 assert_server_lock_ssh "$reponame" "$id" "refs/heads/main"
164
165 GIT_TRACE=1 gitscip-shell system . . git. lfs locks --path "f.dat" 2>trace.log | teescip-shell system . . tee. locks.log
166 catscip-shell system . . cat. trace.log
167 [scip-shell system . . `[`. $(wcscip-shell system . . wc. -l < locks.log) -eq 1 ]
168 grepscip-shell system . . grep. "f.dat" locks.log
169 grepscip-shell system . . grep. "lfs-ssh-echo.*git-lfs-transfer .*$reponame.git download" trace.log
170
171 GIT_TRACE=1 gitscip-shell system . . git. -c lfs."$sshurl".sshtransfer=always lfs locks --path "f.dat" 2>trace.log | teescip-shell system . . tee. locks.log
172 [scip-shell system . . `[`. $(wcscip-shell system . . wc. -l < locks.log) -eq 1 ]
173 grepscip-shell system . . grep. "f.dat" locks.log
174 grepscip-shell system . . grep. "lfs-ssh-echo.*git-lfs-transfer .*$reponame.git download" trace.log
175
176 GIT_TRACE=1 gitscip-shell system . . git. -c lfs."$sshurl".sshtransfer=negotiate lfs locks --path "f.dat" 2>trace.log | teescip-shell system . . tee. locks.log
177 [scip-shell system . . `[`. $(wcscip-shell system . . wc. -l < locks.log) -eq 1 ]
178 grepscip-shell system . . grep. "f.dat" locks.log
179 grepscip-shell system . . grep. "lfs-ssh-echo.*git-lfs-transfer .*$reponame.git download" trace.log
180 )
181 end_test
182
183 begin_test "list a single lock (--json)"
184 (
185 set -e
186
187 reponame="locks_list_single_json"
188 setup_remote_repo_with_file "$reponame" "f_json.dat"
189
190 gitscip-shell system . . git. lfs lock --json "f_json.dat" | teescip-shell system . . tee. lock.log
191
192 id=$(assert_lock lock.log f_json.dat)
193 assert_server_lock "$reponame" "$id"
194
195 gitscip-shell system . . git. lfs locks --json --path "f_json.dat" | teescip-shell system . . tee. locks.log
196 grepscip-shell system . . grep. "\"path\":\"f_json.dat\"" locks.log
197 grepscip-shell system . . grep. "\"owner\":{\"name\":\"Git LFS Tests\"}" locks.log
198 )
199 end_test
200
201 begin_test "list locks with a limit"
202 (
203 set -e
204
205 reponame="locks_list_limit"
206 setup_remote_repo "$reponame"
207 clone_repo "$reponame" "clone_$reponame"
208
209 gitscip-shell system . . git. lfs track "*.dat"
210 echoscip-shell system . . echo. "foo" > "g_1.dat"
211 echoscip-shell system . . echo. "bar" > "g_2.dat"
212
213 gitscip-shell system . . git. add "g_1.dat" "g_2.dat" ".gitattributes"
214 gitscip-shell system . . git. commit -m "add files" | teescip-shell system . . tee. commit.log
215 grepscip-shell system . . grep. "3 files changed" commit.log
216 grepscip-shell system . . grep. "create mode 100644 g_1.dat" commit.log
217 grepscip-shell system . . grep. "create mode 100644 g_2.dat" commit.log
218 grepscip-shell system . . grep. "create mode 100644 .gitattributes" commit.log
219
220
221 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
222 grepscip-shell system . . grep. "main -> main" push.log
223
224 gitscip-shell system . . git. lfs lock --json "g_1.dat" | teescip-shell system . . tee. lock.log
225 assert_server_lock "$reponame" "$(assert_log "lock.log" g_1.dat)"
226
227 gitscip-shell system . . git. lfs lock --json "g_2.dat" | teescip-shell system . . tee. lock.log
228 assert_server_lock "$reponame" "$(assert_lock "lock.log" g_2.dat)"
229
230 gitscip-shell system . . git. lfs locks --limit 1 | teescip-shell system . . tee. locks.log
231 [scip-shell system . . `[`. $(wcscip-shell system . . wc. -l < locks.log) -eq 1 ]
232 )
233 end_test
234
235 begin_test "list locks with pagination"
236 (
237 set -e
238
239 reponame="locks_list_paginate"
240 setup_remote_repo "$reponame"
241 clone_repo "$reponame" "clone_$reponame"
242
243 gitscip-shell system . . git. lfs track "*.dat"
244 for i in $(seqscip-shell system . . seq. 1 5); do
245 echoscip-shell system . . echo. "$i" > "h_$i.dat"
246 done
247
248 gitscip-shell system . . git. add "h_1.dat" "h_2.dat" "h_3.dat" "h_4.dat" "h_5.dat" ".gitattributes"
249
250 gitscip-shell system . . git. commit -m "add files" | teescip-shell system . . tee. commit.log
251 grepscip-shell system . . grep. "6 files changed" commit.log
252 for i in $(seqscip-shell system . . seq. 1 5); do
253 grepscip-shell system . . grep. "create mode 100644 h_$i.dat" commit.log
254 done
255 grepscip-shell system . . grep. "create mode 100644 .gitattributes" commit.log
256
257 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
258 grepscip-shell system . . grep. "main -> main" push.log
259
260 for i in $(seqscip-shell system . . seq. 1 5); do
261 gitscip-shell system . . git. lfs lock --json "h_$i.dat" | teescip-shell system . . tee. lock.log
262 assert_server_lock "$reponame" "$(assert_lock "lock.log" "h_$i.dat")"
263 done
264
265 # The server will return, at most, three locks at a time
266 gitscip-shell system . . git. lfs locks --limit 4 | teescip-shell system . . tee. locks.log
267 [scip-shell system . . `[`. $(wcscip-shell system . . wc. -l < locks.log) -eq 4 ]
268 )
269 end_test
270
271 begin_test "cached locks"
272 (
273 set -e
274
275 reponame="cached_locks"
276 setup_remote_repo "remote_$reponame"
277 clone_repo "remote_$reponame" "clone_$reponame"
278
279 gitscip-shell system . . git. lfs track "*.dat"
280 echoscip-shell system . . echo. "foo" > "cached1.dat"
281 echoscip-shell system . . echo. "bar" > "cached2.dat"
282
283 gitscip-shell system . . git. add "cached1.dat" "cached2.dat" ".gitattributes"
284 gitscip-shell system . . git. commit -m "add files" | teescip-shell system . . tee. commit.log
285 grepscip-shell system . . grep. "3 files changed" commit.log
286 grepscip-shell system . . grep. "create mode 100644 cached1.dat" commit.log
287 grepscip-shell system . . grep. "create mode 100644 cached2.dat" commit.log
288 grepscip-shell system . . grep. "create mode 100644 .gitattributes" commit.log
289
290 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
291 grepscip-shell system . . grep. "main -> main" push.log
292
293 gitscip-shell system . . git. lfs lock --json "cached1.dat" | teescip-shell system . . tee. lock.log
294 assert_server_lock "$(assert_lock "lock.log" cached1.dat)"
295
296 gitscip-shell system . . git. lfs lock --json "cached2.dat" | teescip-shell system . . tee. lock.log
297 assert_server_lock "$(assert_lock "lock.log" cached2.dat)"
298
299 gitscip-shell system . . git. lfs locks --local | teescip-shell system . . tee. locks.log
300 [scip-shell system . . `[`. $(wcscip-shell system . . wc. -l < locks.log) -eq 2 ]
301
302 # delete the remote to prove we're using the local records
303 gitscip-shell system . . git. remote remove origin
304
305 gitscip-shell system . . git. lfs locks --local --path "cached1.dat" | teescip-shell system . . tee. locks.log
306 [scip-shell system . . `[`. $(wcscip-shell system . . wc. -l < locks.log) -eq 1 ]
307 grepscip-shell system . . grep. "cached1.dat" locks.log
308
309 gitscip-shell system . . git. lfs locks --local --limit 1 | teescip-shell system . . tee. locks.log
310 [scip-shell system . . `[`. $(wcscip-shell system . . wc. -l < locks.log) -eq 1 ]
311 )
312 end_test
313
314 begin_test "cached locks with failed lock"
315 (
316 set -e
317
318 reponame="cached-locks-failed-lock"
319 setup_remote_repo "remote_$reponame"
320 clone_repo "remote_$reponame" "clone_$reponame"
321
322 gitscip-shell system . . git. lfs track "*.dat"
323 echoscip-shell system . . echo. "foo" > "cached1.dat"
324 echoscip-shell system . . echo. "bar" > "cached2.dat"
325
326 gitscip-shell system . . git. add "cached1.dat" "cached2.dat" ".gitattributes"
327 gitscip-shell system . . git. commit -m "add files" | teescip-shell system . . tee. commit.log
328 grepscip-shell system . . grep. "3 files changed" commit.log
329 grepscip-shell system . . grep. "create mode 100644 cached1.dat" commit.log
330 grepscip-shell system . . grep. "create mode 100644 cached2.dat" commit.log
331 grepscip-shell system . . grep. "create mode 100644 .gitattributes" commit.log
332
333 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
334 grepscip-shell system . . grep. "main -> main" push.log
335
336 gitscip-shell system . . git. lfs lock --json "cached1.dat" | teescip-shell system . . tee. lock.log
337 assert_server_lock "$(assert_lock "lock.log" cached1.dat)"
338
339 gitscip-shell system . . git. lfs lock --json "cached1.dat" "cached2.dat" | teescip-shell system . . tee. lock.log
340 assert_server_lock "$(assert_lock "lock.log" cached2.dat)"
341
342 gitscip-shell system . . git. lfs locks --local | teescip-shell system . . tee. locks.log
343 [scip-shell system . . `[`. $(wcscip-shell system . . wc. -l < locks.log) -eq 2 ]
344
345 gitscip-shell system . . git. lfs unlock --json "cached1.dat"
346
347 gitscip-shell system . . git. lfs unlock --json "cached1.dat" "cached2.dat" || truescip-shell system . . true.
348
349 gitscip-shell system . . git. lfs locks --local | teescip-shell system . . tee. locks.log
350 [scip-shell system . . `[`. $(wcscip-shell system . . wc. -l < locks.log) -eq 0 ]
351 )
352 end_test