MCPcopy
hub / github.com/git-lfs/git-lfs / LockFile

Method LockFile

locking/locks.go:104–138  ·  view source on GitHub ↗

LockFile attempts to lock a file on the current remote path must be relative to the root of the repository Returns the lock id if successful, or an error

(path string)

Source from the content-addressed store, hash-verified

102// path must be relative to the root of the repository
103// Returns the lock id if successful, or an error
104func (c *Client) LockFile(path string) (Lock, error) {
105 lockRes, _, err := c.client.Lock(c.Remote, &lockRequest{
106 Path: path,
107 Ref: &lockRef{Name: c.RemoteRef.Refspec()},
108 })
109 if err != nil {
110 return Lock{}, errors.Wrap(err, tr.Tr.Get("locking API"))
111 }
112
113 if len(lockRes.Message) > 0 {
114 if len(lockRes.RequestID) > 0 {
115 tracerx.Printf("Server Request ID: %s", lockRes.RequestID)
116 }
117 return Lock{}, errors.New(tr.Tr.Get("server unable to create lock: %s", lockRes.Message))
118 }
119
120 lock := *lockRes.Lock
121 if err := c.cache.Add(lock); err != nil {
122 return Lock{}, errors.Wrap(err, tr.Tr.Get("lock cache"))
123 }
124
125 abs, err := c.getAbsolutePath(path)
126 if err != nil {
127 return Lock{}, errors.Wrap(err, tr.Tr.Get("make lock path absolute"))
128 }
129
130 // If the file exists, ensure that it's writeable on return
131 if tools.FileExists(abs) {
132 if err := tools.SetFileWriteFlag(abs, true); err != nil {
133 return Lock{}, errors.Wrap(err, tr.Tr.Get("set file write flag"))
134 }
135 }
136
137 return lock, nil
138}
139
140// getAbsolutePath takes a repository-relative path and makes it absolute.
141//

Callers 1

lockCommandFunction · 0.80

Calls 9

getAbsolutePathMethod · 0.95
WrapFunction · 0.92
NewFunction · 0.92
FileExistsFunction · 0.92
SetFileWriteFlagFunction · 0.92
RefspecMethod · 0.80
LockMethod · 0.65
GetMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected