3 . "$(dirname "$0")/testlib.sh"
5 begin_test "unlocking a lock by path with good ref"
9 reponame="unlock-by-path-master-branch-required"
10 setup_remote_repo_with_file "$reponame" "c.dat"
12 git lfs lock --json "c.dat" | tee lock.log
14 id=$(assert_lock lock.log c.dat)
15 assert_server_lock "$reponame" "$id" "refs/heads/master"
17 git lfs unlock --id="$id"
18 refute_server_lock "$reponame" "$id" "refs/heads/master"
22 begin_test "unlocking a lock by path with tracked ref"
26 reponame="unlock-by-path-tracked-branch-required"
27 setup_remote_repo "$reponame"
28 clone_repo "$reponame" "$reponame"
32 git add .gitattributes c.dat
33 git commit -m "add c.dat"
35 git config push.default upstream
36 git config branch.master.merge refs/heads/tracked
37 git push origin master
39 git lfs lock --json "c.dat" | tee lock.log
41 id=$(assert_lock lock.log c.dat)
42 assert_server_lock "$reponame" "$id" "refs/heads/tracked"
44 git lfs unlock --id="$id"
45 refute_server_lock "$reponame" "$id" "refs/heads/tracked"
49 begin_test "unlocking a lock by path with bad ref"
53 reponame="unlock-by-path-other-branch-required"
54 setup_remote_repo "$reponame"
55 clone_repo "$reponame" "$reponame"
59 git add .gitattributes c.dat
60 git commit -m "add c.dat"
61 git push origin master:other
64 git lfs lock --json "c.dat" | tee lock.log
66 id=$(assert_lock lock.log c.dat)
67 assert_server_lock "$reponame" "$id" "refs/heads/other"
70 git lfs unlock --id="$id" 2>&1 | tee unlock.log
71 if [ "0" -eq "${PIPESTATUS[0]}" ]; then
72 echo >&2 "fatal: expected 'git lfs lock \'a.dat\'' to fail"
76 assert_server_lock "$reponame" "$id" "refs/heads/other"
77 grep 'Expected ref "refs/heads/other", got "refs/heads/master"' unlock.log
81 begin_test "unlocking a lock by id with bad ref"
85 reponame="unlock-by-id-other-branch-required"
86 setup_remote_repo "$reponame"
87 clone_repo "$reponame" "$reponame"
91 git add .gitattributes c.dat
92 git commit -m "add c.dat"
93 git push origin master:other
96 git lfs lock --json "c.dat" | tee lock.log
98 id=$(assert_lock lock.log c.dat)
99 assert_server_lock "$reponame" "$id" "refs/heads/other"
102 git lfs unlock --id="$id" 2>&1 | tee unlock.log
103 if [ "0" -eq "${PIPESTATUS[0]}" ]; then
104 echo >&2 "fatal: expected 'git lfs lock \'a.dat\'' to fail"
108 assert_server_lock "$reponame" "$id" "refs/heads/other"
109 grep 'Expected ref "refs/heads/other", got "refs/heads/master"' unlock.log
113 begin_test "unlocking a file makes it readonly"
117 reponame="unlock_set_readonly"
118 setup_remote_repo_with_file "$reponame" "c.dat"
120 git lfs lock --json "c.dat"
121 assert_file_writeable c.dat
123 git lfs unlock "c.dat"
124 refute_file_writeable c.dat
128 begin_test "unlocking a file ignores readonly"
132 reponame="unlock_set_readonly_ignore"
133 setup_remote_repo_with_file "$reponame" "c.dat"
135 git lfs lock --json "c.dat"
136 assert_file_writeable c.dat
138 git -c lfs.setlockablereadonly=false lfs unlock "c.dat"
139 assert_file_writeable c.dat
143 begin_test "force unlocking lock with missing file"
147 reponame="force-unlock-missing-file"
148 setup_remote_repo_with_file "$reponame" "a.dat"
150 git lfs lock --json "a.dat" | tee lock.log
151 id=$(assert_lock lock.log a.dat)
152 assert_server_lock "$reponame" "$id"
155 git commit -m "a.dat"
156 rm *.log *.json # ensure clean git status
159 git lfs unlock "a.dat" 2>&1 | tee unlock.log
160 grep "Unable to determine path" unlock.log
161 assert_server_lock "$reponame" "$id"
164 git lfs unlock --force "a.dat" 2>&1 | tee unlock.log
165 refute_server_lock "$reponame" "$id"
169 begin_test "unlocking a lock (--json)"
173 reponame="unlock_by_path_json"
174 setup_remote_repo_with_file "$reponame" "c_json.dat"
176 git lfs lock --json "c_json.dat" | tee lock.log
178 id=$(assert_lock lock.log c_json.dat)
179 assert_server_lock "$reponame" "$id"
181 git lfs unlock --json "c_json.dat" 2>&1 | tee unlock.log
182 grep "\"unlocked\":true" unlock.log
184 refute_server_lock "$reponame" "$id"
188 begin_test "unlocking a lock by id"
192 reponame="unlock_by_id"
193 setup_remote_repo_with_file "$reponame" "d.dat"
195 git lfs lock --json "d.dat" | tee lock.log
196 assert_file_writeable d.dat
198 id=$(assert_lock lock.log d.dat)
199 assert_server_lock "$reponame" "$id"
201 git lfs unlock --id="$id"
202 refute_file_writeable d.dat
206 begin_test "unlocking a lock without sufficient info"
210 reponame="unlock_ambiguous"
211 setup_remote_repo_with_file "$reponame" "e.dat"
213 git lfs lock --json "e.dat" | tee lock.log
215 id=$(assert_lock lock.log e.dat)
216 assert_server_lock "$reponame" "$id"
218 git lfs unlock 2>&1 | tee unlock.log
219 grep "Usage: git lfs unlock" unlock.log
220 assert_server_lock "$reponame" "$id"
224 begin_test "unlocking a lock while uncommitted"
228 reponame="unlock_modified"
229 setup_remote_repo_with_file "$reponame" "mod.dat"
231 git lfs lock --json "mod.dat" | tee lock.log
233 id=$(assert_lock lock.log mod.dat)
234 assert_server_lock "$reponame" "$id"
236 echo "\nSomething" >> mod.dat
238 git lfs unlock "mod.dat" 2>&1 | tee unlock.log
239 [ ${PIPESTATUS[0]} -ne "0" ]
241 grep "Cannot unlock file with uncommitted changes" unlock.log
243 assert_server_lock "$reponame" "$id"
245 # should allow after discard
247 git lfs unlock "mod.dat" 2>&1 | tee unlock.log
248 refute_server_lock "$reponame" "$id"
252 begin_test "unlocking a lock with ambiguious arguments"
256 reponame="unlock_ambiguious_args"
257 setup_remote_repo_with_file "$reponame" "a.dat"
259 git lfs lock --json "a.dat" | tee lock.log
261 id=$(assert_lock lock.log a.dat)
262 assert_server_lock "$reponame" "$id"
264 git lfs unlock --id "$id" a.dat 2>&1 | tee unlock.log
265 if [ "0" -eq "${PIPESTATUS[0]}" ]; then
266 echo >&2 "expected ambiguous \`git lfs unlock\` command to exit, didn't"
270 grep "Usage:" unlock.log
271 assert_server_lock "$reponame" "$id"
275 begin_test "unlocking a lock while uncommitted with --force"
279 reponame="unlock_modified_force"
280 setup_remote_repo_with_file "$reponame" "modforce.dat"
282 git lfs lock --json "modforce.dat" | tee lock.log
284 id=$(assert_lock lock.log modforce.dat)
285 assert_server_lock "$reponame" "$id"
287 echo "\nSomething" >> modforce.dat
289 # should allow with --force
290 git lfs unlock --force "modforce.dat" 2>&1 | tee unlock.log
291 grep "Warning: unlocking with uncommitted changes" unlock.log
292 refute_server_lock "$reponame" "$id"
296 begin_test "unlocking a lock while untracked"
300 reponame="unlock_untracked"
301 setup_remote_repo_with_file "$reponame" "notrelevant.dat"
303 git lfs track "*.dat"
304 # Create file but don't add it to git
305 # Shouldn't be able to unlock it
306 echo "something" > untracked.dat
307 git lfs lock --json "untracked.dat" | tee lock.log
309 id=$(assert_lock lock.log untracked.dat)
310 assert_server_lock "$reponame" "$id"
312 git lfs unlock "untracked.dat" 2>&1 | tee unlock.log
313 [ ${PIPESTATUS[0]} -ne "0" ]
315 grep "Cannot unlock file with uncommitted changes" unlock.log
317 assert_server_lock "$reponame" "$id"
319 # should allow after add/commit
320 git add untracked.dat
321 git commit -m "Added untracked"
322 git lfs unlock "untracked.dat" 2>&1 | tee unlock.log
323 refute_server_lock "$reponame" "$id"