Skip to content

Commit 4fe2667

Browse files
authored
Merge pull request #2642 from git-lfs/fix-unlock-by-id
ensure files are marked readonly after unlocking by ID
2 parents 12a5c5b + 1ba0d3c commit 4fe2667

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

locking/lockable.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func (c *Client) ensureLockablesLoaded() {
3939
// Internal function to repopulate lockable patterns
4040
// You must have locked the c.lockableMutex in the caller
4141
func (c *Client) refreshLockablePatterns() {
42-
4342
paths := git.GetAttributePaths(c.LocalWorkingDir, c.LocalGitDir)
4443
// Always make non-nil even if empty
4544
c.lockablePatterns = make([]string, 0, len(paths))

locking/locks.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -144,22 +144,7 @@ func (c *Client) UnlockFile(path string, force bool) error {
144144
return fmt.Errorf("Unable to get lock id: %v", err)
145145
}
146146

147-
err = c.UnlockFileById(id, force)
148-
if err != nil {
149-
return err
150-
}
151-
152-
abs, err := getAbsolutePath(path)
153-
if err != nil {
154-
return errors.Wrap(err, "make lockpath absolute")
155-
}
156-
157-
// Make non-writeable if required
158-
if c.SetLockableFilesReadOnly && c.IsFileLockable(path) {
159-
return tools.SetFileWriteFlag(abs, false)
160-
}
161-
return nil
162-
147+
return c.UnlockFileById(id, force)
163148
}
164149

165150
// UnlockFileById attempts to unlock a lock with a given id on the current remote
@@ -181,6 +166,18 @@ func (c *Client) UnlockFileById(id string, force bool) error {
181166
return fmt.Errorf("Error caching unlock information: %v", err)
182167
}
183168

169+
if unlockRes.Lock != nil {
170+
abs, err := getAbsolutePath(unlockRes.Lock.Path)
171+
if err != nil {
172+
return errors.Wrap(err, "make lockpath absolute")
173+
}
174+
175+
// Make non-writeable if required
176+
if c.SetLockableFilesReadOnly && c.IsFileLockable(unlockRes.Lock.Path) {
177+
return tools.SetFileWriteFlag(abs, false)
178+
}
179+
}
180+
184181
return nil
185182
}
186183

test/test-unlock.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ begin_test "unlocking a file makes it readonly"
3434
)
3535
end_test
3636

37-
begin_test "unlocking a file makes ignores readonly"
37+
begin_test "unlocking a file ignores readonly"
3838
(
3939
set -e
4040

@@ -99,15 +99,16 @@ begin_test "unlocking a lock by id"
9999
set -e
100100

101101
reponame="unlock_by_id"
102-
setup_remote_repo_with_file "unlock_by_id" "d.dat"
102+
setup_remote_repo_with_file "$reponame" "d.dat"
103103

104104
git lfs lock --json "d.dat" | tee lock.log
105+
assert_file_writeable d.dat
105106

106107
id=$(assert_lock lock.log d.dat)
107108
assert_server_lock "$reponame" "$id"
108109

109110
git lfs unlock --id="$id"
110-
refute_server_lock "$reponame" "$id"
111+
refute_file_writeable d.dat
111112
)
112113
end_test
113114

0 commit comments

Comments
 (0)