5 begin_test "unlocking a lock by path"
9 reponame="unlock_by_path"
10 setup_remote_repo_with_file "unlock_by_path" "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"
17 git lfs unlock "c.dat" 2>&1 | tee unlock.log
18 refute_server_lock "$reponame" "$id"
22 begin_test "unlocking a file makes it readonly"
26 reponame="unlock_set_readonly"
27 setup_remote_repo_with_file "$reponame" "c.dat"
29 git lfs lock --json "c.dat"
30 assert_file_writeable c.dat
32 git lfs unlock "c.dat"
33 refute_file_writeable c.dat
37 begin_test "unlocking a file makes ignores readonly"
41 reponame="unlock_set_readonly_ignore"
42 setup_remote_repo_with_file "$reponame" "c.dat"
44 git lfs lock --json "c.dat"
45 assert_file_writeable c.dat
47 git -c lfs.setlockablereadonly=false lfs unlock "c.dat"
48 assert_file_writeable c.dat
52 begin_test "force unlocking lock with missing file"
56 reponame="force-unlock-missing-file"
57 setup_remote_repo_with_file "$reponame" "a.dat"
59 git lfs lock --json "a.dat" | tee lock.log
60 id=$(assert_lock lock.log a.dat)
61 assert_server_lock "$reponame" "$id"
65 rm *.log *.json # ensure clean git status
68 git lfs unlock "a.dat" 2>&1 | tee unlock.log
69 grep "Unable to determine path" unlock.log
70 assert_server_lock "$reponame" "$id"
73 git lfs unlock --force "a.dat" 2>&1 | tee unlock.log
74 refute_server_lock "$reponame" "$id"
78 begin_test "unlocking a lock (--json)"
82 reponame="unlock_by_path_json"
83 setup_remote_repo_with_file "$reponame" "c_json.dat"
85 git lfs lock --json "c_json.dat" | tee lock.log
87 id=$(assert_lock lock.log c_json.dat)
88 assert_server_lock "$reponame" "$id"
90 git lfs unlock --json "c_json.dat" 2>&1 | tee unlock.log
91 grep "\"unlocked\":true" unlock.log
93 refute_server_lock "$reponame" "$id"
97 begin_test "unlocking a lock by id"
101 reponame="unlock_by_id"
102 setup_remote_repo_with_file "unlock_by_id" "d.dat"
104 git lfs lock --json "d.dat" | tee lock.log
106 id=$(assert_lock lock.log d.dat)
107 assert_server_lock "$reponame" "$id"
109 git lfs unlock --id="$id"
110 refute_server_lock "$reponame" "$id"
114 begin_test "unlocking a lock without sufficient info"
118 reponame="unlock_ambiguous"
119 setup_remote_repo_with_file "$reponame" "e.dat"
121 git lfs lock --json "e.dat" | tee lock.log
123 id=$(assert_lock lock.log e.dat)
124 assert_server_lock "$reponame" "$id"
126 git lfs unlock 2>&1 | tee unlock.log
127 grep "Usage: git lfs unlock" unlock.log
128 assert_server_lock "$reponame" "$id"
132 begin_test "unlocking a lock while uncommitted"
136 reponame="unlock_modified"
137 setup_remote_repo_with_file "$reponame" "mod.dat"
139 git lfs lock --json "mod.dat" | tee lock.log
141 id=$(assert_lock lock.log mod.dat)
142 assert_server_lock "$reponame" "$id"
144 echo "\nSomething" >> mod.dat
146 git lfs unlock "mod.dat" 2>&1 | tee unlock.log
147 [ ${PIPESTATUS[0]} -ne "0" ]
149 grep "Cannot unlock file with uncommitted changes" unlock.log
151 assert_server_lock "$reponame" "$id"
153 # should allow after discard
155 git lfs unlock "mod.dat" 2>&1 | tee unlock.log
156 refute_server_lock "$reponame" "$id"
160 begin_test "unlocking a lock with ambiguious arguments"
164 reponame="unlock_ambiguious_args"
165 setup_remote_repo_with_file "$reponame" "a.dat"
167 git lfs lock --json "a.dat" | tee lock.log
169 id=$(assert_lock lock.log a.dat)
170 assert_server_lock "$reponame" "$id"
172 git lfs unlock --id "$id" a.dat 2>&1 | tee unlock.log
173 if [ "0" -eq "${PIPESTATUS[0]}" ]; then
174 echo >&2 "expected ambiguous \`git lfs unlock\` command to exit, didn't"
178 grep "Usage:" unlock.log
179 assert_server_lock "$reponame" "$id"
183 begin_test "unlocking a lock while uncommitted with --force"
187 reponame="unlock_modified_force"
188 setup_remote_repo_with_file "$reponame" "modforce.dat"
190 git lfs lock --json "modforce.dat" | tee lock.log
192 id=$(assert_lock lock.log modforce.dat)
193 assert_server_lock "$reponame" "$id"
195 echo "\nSomething" >> modforce.dat
197 # should allow with --force
198 git lfs unlock --force "modforce.dat" 2>&1 | tee unlock.log
199 grep "Warning: unlocking with uncommitted changes" unlock.log
200 refute_server_lock "$reponame" "$id"
204 begin_test "unlocking a lock while untracked"
208 reponame="unlock_untracked"
209 setup_remote_repo_with_file "$reponame" "notrelevant.dat"
211 git lfs track "*.dat"
212 # Create file but don't add it to git
213 # Shouldn't be able to unlock it
214 echo "something" > untracked.dat
215 git lfs lock --json "untracked.dat" | tee lock.log
217 id=$(assert_lock lock.log untracked.dat)
218 assert_server_lock "$reponame" "$id"
220 git lfs unlock "untracked.dat" 2>&1 | tee unlock.log
221 [ ${PIPESTATUS[0]} -ne "0" ]
223 grep "Cannot unlock file with uncommitted changes" unlock.log
225 assert_server_lock "$reponame" "$id"
227 # should allow after add/commit
228 git add untracked.dat
229 git commit -m "Added untracked"
230 git lfs unlock "untracked.dat" 2>&1 | tee unlock.log
231 refute_server_lock "$reponame" "$id"