Skip to content

Commit

Permalink
Merge pull request #2642 from git-lfs/fix-unlock-by-id
Browse files Browse the repository at this point in the history
ensure files are marked readonly after unlocking by ID
  • Loading branch information
technoweenie committed Oct 3, 2017
2 parents 12a5c5b + 1ba0d3c commit 4fe2667
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
1 change: 0 additions & 1 deletion locking/lockable.go
Expand Up @@ -39,7 +39,6 @@ func (c *Client) ensureLockablesLoaded() {
// Internal function to repopulate lockable patterns
// You must have locked the c.lockableMutex in the caller
func (c *Client) refreshLockablePatterns() {

paths := git.GetAttributePaths(c.LocalWorkingDir, c.LocalGitDir)
// Always make non-nil even if empty
c.lockablePatterns = make([]string, 0, len(paths))
Expand Down
29 changes: 13 additions & 16 deletions locking/locks.go
Expand Up @@ -144,22 +144,7 @@ func (c *Client) UnlockFile(path string, force bool) error {
return fmt.Errorf("Unable to get lock id: %v", err)
}

err = c.UnlockFileById(id, force)
if err != nil {
return err
}

abs, err := getAbsolutePath(path)
if err != nil {
return errors.Wrap(err, "make lockpath absolute")
}

// Make non-writeable if required
if c.SetLockableFilesReadOnly && c.IsFileLockable(path) {
return tools.SetFileWriteFlag(abs, false)
}
return nil

return c.UnlockFileById(id, force)
}

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

if unlockRes.Lock != nil {
abs, err := getAbsolutePath(unlockRes.Lock.Path)
if err != nil {
return errors.Wrap(err, "make lockpath absolute")
}

// Make non-writeable if required
if c.SetLockableFilesReadOnly && c.IsFileLockable(unlockRes.Lock.Path) {
return tools.SetFileWriteFlag(abs, false)
}
}

return nil
}

Expand Down
7 changes: 4 additions & 3 deletions test/test-unlock.sh
Expand Up @@ -34,7 +34,7 @@ begin_test "unlocking a file makes it readonly"
)
end_test

begin_test "unlocking a file makes ignores readonly"
begin_test "unlocking a file ignores readonly"
(
set -e

Expand Down Expand Up @@ -99,15 +99,16 @@ begin_test "unlocking a lock by id"
set -e

reponame="unlock_by_id"
setup_remote_repo_with_file "unlock_by_id" "d.dat"
setup_remote_repo_with_file "$reponame" "d.dat"

git lfs lock --json "d.dat" | tee lock.log
assert_file_writeable d.dat

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

git lfs unlock --id="$id"
refute_server_lock "$reponame" "$id"
refute_file_writeable d.dat
)
end_test

Expand Down

0 comments on commit 4fe2667

Please sign in to comment.