| 1 | # Git LFS File Locking API |
| 2 | |
| 3 | Added: v2.0 |
| 4 | |
| 5 | The File Locking API is used to create, list, and delete locks, as well as |
| 6 | verify that locks are respected in Git pushes. The locking URLs are built |
| 7 | by adding a suffix to the LFS Server URL. |
| 8 | |
| 9 | Git remote: https://git-server.com/foo/bar<br> |
| 10 | LFS server: https://git-server.com/foo/bar.git/info/lfs<br> |
| 11 | Locks API: https://git-server.com/foo/bar.git/info/lfs/locks<br> |
| 12 | |
| 13 | See the [Server Discovery doc](./server-discovery.md) for more info on how LFS |
| 14 | builds the LFS server URL. |
| 15 | |
| 16 | All File Locking requests require the following HTTP headers: |
| 17 | |
| 18 | Accept: application/vnd.git-lfs+json |
| 19 | Content-Type: application/vnd.git-lfs+json |
| 20 | |
| 21 | The client may also include a `charset=utf-8` parameter in the |
| 22 | `Content-Type` header, which servers should be prepared to accept. |
| 23 | |
| 24 | See the [Authentication doc](./authentication.md) for more info on how LFS |
| 25 | gets authorizes Batch API requests. |
| 26 | |
| 27 | Note: This is the first version of the File Locking API, supporting only the |
| 28 | simplest use case: single branch locking. The API is designed to be extensible |
| 29 | as we experiment with more advanced locking scenarios, as defined in the |
| 30 | [original proposal](/docs/proposals/locking.md). |
| 31 | |
| 32 | The [Batch API's `ref` property docs](./batch.md#ref-property) describe how the `ref` property can be used to support auth schemes that include the server ref. Locking API implementations should also only use it for authentication, until advanced locking scenarios have been developed. |
| 33 | |
| 34 | ## Create Lock |
| 35 | |
| 36 | The client sends the following to create a lock by sending a `POST` to `/locks` |
| 37 | (appended to the LFS server url, as described above). Servers should ensure that |
| 38 | users have push access to the repository, and that files are locked exclusively |
| 39 | to one user. |
| 40 | |
| 41 | * `path` - String path name of the file that is locked. This should be |
| 42 | relative to the root of the repository working directory. |
| 43 | * `ref` - Optional object describing the server ref that the locks belong to. Note: Added in v2.4. |
| 44 | * `name` - Fully-qualified server refspec. |
| 45 | |
| 46 | ```json5 |
| 47 | // POST https://lfs-server.com/locks |
| 48 | // Accept: application/vnd.git-lfs+json |
| 49 | // Content-Type: application/vnd.git-lfs+json |
| 50 | // Authorization: Basic ... |
| 51 | { |
| 52 | "path": "foo/bar.zip", |
| 53 | "ref": { |
| 54 | "name": "refs/heads/my-feature" |
| 55 | } |
| 56 | } |
| 57 | ``` |
| 58 | |
| 59 | ### Successful Response |
| 60 | |
| 61 | Successful responses return the created lock: |
| 62 | |
| 63 | * `id` - String ID of the Lock. Git LFS doesn't enforce what type of ID is used, |
| 64 | as long as it's returned as a string. |
| 65 | * `path` - String path name of the locked file. This should be relative to the |
| 66 | root of the repository working directory. |
| 67 | * `locked_at` - The timestamp the lock was created, as an uppercase |
| 68 | RFC 3339-formatted string with second precision. |
| 69 | * `owner` - Optional name of the user that created the Lock. This should be set from |
| 70 | the user credentials posted when creating the lock. |
| 71 | |
| 72 | ```json5 |
| 73 | // HTTP/1.1 201 Created |
| 74 | // Content-Type: application/vnd.git-lfs+json |
| 75 | { |
| 76 | "lock": { |
| 77 | "id": "some-uuid", |
| 78 | "path": "foo/bar.zip", |
| 79 | "locked_at": "2016-05-17T15:49:06+00:00", |
| 80 | "owner": { |
| 81 | "name": "Jane Doe" |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | ``` |
| 86 | |
| 87 | ### Bad Response: Lock Exists |
| 88 | |
| 89 | Lock services should reject lock creations if one already exists for the given |
| 90 | path on the current repository. |
| 91 | |
| 92 | * `lock` - The existing Lock that clashes with the request. |
| 93 | * `message` - String error message. |
| 94 | * `request_id` - Optional String unique identifier for the request. Useful for |
| 95 | debugging. |
| 96 | * `documentation_url` - Optional String to give the user a place to report |
| 97 | errors. |
| 98 | |
| 99 | ```json5 |
| 100 | // HTTP/1.1 409 Conflict |
| 101 | // Content-Type: application/vnd.git-lfs+json |
| 102 | { |
| 103 | "lock": { |
| 104 | // details of existing lock |
| 105 | }, |
| 106 | "message": "already created lock", |
| 107 | "documentation_url": "https://lfs-server.com/docs/errors", |
| 108 | "request_id": "123" |
| 109 | } |
| 110 | ``` |
| 111 | |
| 112 | ### Unauthorized Response |
| 113 | |
| 114 | Lock servers should require that users have push access to the repository before |
| 115 | they can create locks. |
| 116 | |
| 117 | * `message` - String error message. |
| 118 | * `request_id` - Optional String unique identifier for the request. Useful for |
| 119 | debugging. |
| 120 | * `documentation_url` - Optional String to give the user a place to report |
| 121 | errors. |
| 122 | |
| 123 | ```json5 |
| 124 | // HTTP/1.1 403 Forbidden |
| 125 | // Content-Type: application/vnd.git-lfs+json |
| 126 | { |
| 127 | "message": "You must have push access to create a lock", |
| 128 | "documentation_url": "https://lfs-server.com/docs/errors", |
| 129 | "request_id": "123" |
| 130 | } |
| 131 | ``` |
| 132 | |
| 133 | ### Error Response |
| 134 | |
| 135 | * `message` - String error message. |
| 136 | * `request_id` - Optional String unique identifier for the request. Useful for |
| 137 | debugging. |
| 138 | * `documentation_url` - Optional String to give the user a place to report |
| 139 | errors. |
| 140 | |
| 141 | ```json5 |
| 142 | // HTTP/1.1 500 Internal server error |
| 143 | // Content-Type: application/vnd.git-lfs+json |
| 144 | { |
| 145 | "message": "internal server error", |
| 146 | "documentation_url": "https://lfs-server.com/docs/errors", |
| 147 | "request_id": "123" |
| 148 | } |
| 149 | ``` |
| 150 | |
| 151 | ## List Locks |
| 152 | |
| 153 | The client can request the current active locks for a repository by sending a |
| 154 | `GET` to `/locks` (appended to the LFS server url, as described above). LFS |
| 155 | Servers should ensure that users have at least pull access to the repository. |
| 156 | |
| 157 | The properties are sent as URI query values, instead of through a JSON body: |
| 158 | |
| 159 | * `path` - Optional string path to match against locks on the server. |
| 160 | * `id` - Optional string ID to match against a lock on the server. |
| 161 | * `cursor` - The optional string value to continue listing locks. This value |
| 162 | should be the `next_cursor` from a previous request. |
| 163 | * `limit` - The integer limit of the number of locks to return. The server |
| 164 | should have its own upper and lower bounds on the supported limits. |
| 165 | * `refspec` - Optional fully qualified server refspec |
| 166 | from which to search for locks. |
| 167 | |
| 168 | ```json5 |
| 169 | // GET https://lfs-server.com/locks?path=&id=&cursor=&limit=&refspec= |
| 170 | // Accept: application/vnd.git-lfs+json |
| 171 | // Authorization: Basic ... (if needed) |
| 172 | ``` |
| 173 | |
| 174 | ### Successful Response |
| 175 | |
| 176 | A successful response will list the matching locks: |
| 177 | |
| 178 | * `locks` - Array of matching Lock objects. See the "Create Lock" successful |
| 179 | response section to see what Lock properties are possible. |
| 180 | * `next_cursor` - Optional string cursor that the server can return if there |
| 181 | are more locks matching the given filters. The client will re-do the request, |
| 182 | setting the `?cursor` query value with this `next_cursor` value. |
| 183 | |
| 184 | Note: If the server has no locks, it must return an empty `locks` array. |
| 185 | |
| 186 | ```json5 |
| 187 | // HTTP/1.1 200 Ok |
| 188 | // Content-Type: application/vnd.git-lfs+json |
| 189 | { |
| 190 | "locks": [ |
| 191 | { |
| 192 | "id": "some-uuid", |
| 193 | "path": "/path/to/file", |
| 194 | "locked_at": "2016-05-17T15:49:06+00:00", |
| 195 | "owner": { |
| 196 | "name": "Jane Doe" |
| 197 | } |
| 198 | } |
| 199 | ], |
| 200 | "next_cursor": "optional next ID" |
| 201 | } |
| 202 | ``` |
| 203 | |
| 204 | ### Unauthorized Response |
| 205 | |
| 206 | Lock servers should require that users have pull access to the repository before |
| 207 | they can list locks. |
| 208 | |
| 209 | * `message` - String error message. |
| 210 | * `request_id` - Optional String unique identifier for the request. Useful for |
| 211 | debugging. |
| 212 | * `documentation_url` - Optional String to give the user a place to report |
| 213 | errors. |
| 214 | |
| 215 | ```json5 |
| 216 | // HTTP/1.1 403 Forbidden |
| 217 | // Content-Type: application/vnd.git-lfs+json |
| 218 | { |
| 219 | "message": "You must have pull access to list locks", |
| 220 | "documentation_url": "https://lfs-server.com/docs/errors", |
| 221 | "request_id": "123" |
| 222 | } |
| 223 | ``` |
| 224 | |
| 225 | ### Error Response |
| 226 | |
| 227 | * `message` - String error message. |
| 228 | * `request_id` - Optional String unique identifier for the request. Useful for |
| 229 | debugging. |
| 230 | * `documentation_url` - Optional String to give the user a place to report |
| 231 | errors. |
| 232 | |
| 233 | ```json5 |
| 234 | // HTTP/1.1 500 Internal server error |
| 235 | // Content-Type: application/vnd.git-lfs+json |
| 236 | { |
| 237 | "message": "unable to list locks", |
| 238 | "documentation_url": "https://lfs-server.com/docs/errors", |
| 239 | "request_id": "123" |
| 240 | } |
| 241 | ``` |
| 242 | |
| 243 | ## List Locks for Verification |
| 244 | |
| 245 | The client can use the Lock Verification endpoint to check for active locks |
| 246 | that can affect a Git push. For a caller, this endpoint is very similar to the |
| 247 | "List Locks" endpoint above, except: |
| 248 | |
| 249 | * Verification requires a `POST` request. |
| 250 | * The `cursor`, `ref` and `limit` values are sent as properties in the json |
| 251 | request body. |
| 252 | * The response includes locks partitioned into `ours` and `theirs` properties. |
| 253 | |
| 254 | LFS Servers should ensure that users have push access to the repository. |
| 255 | |
| 256 | Clients send the following to list locks for verification by sending a `POST` |
| 257 | to `/locks/verify` (appended to the LFS server url, as described above): |
| 258 | |
| 259 | * `ref` - Optional object describing the server ref that the locks belong to. Note: Added in v2.4. |
| 260 | * `name` - Fully-qualified server refspec. |
| 261 | * `cursor` - Optional cursor to allow pagination. Servers can determine how cursors are formatted based on how they are stored internally. |
| 262 | * `limit` - Optional limit to how many locks to |
| 263 | return. |
| 264 | |
| 265 | ```json5 |
| 266 | // POST https://lfs-server.com/locks/verify |
| 267 | // Accept: application/vnd.git-lfs+json |
| 268 | // Content-Type: application/vnd.git-lfs+json |
| 269 | // Authorization: Basic ... |
| 270 | { |
| 271 | "cursor": "optional cursor", |
| 272 | "limit": 100, // also optional |
| 273 | "ref": { |
| 274 | "name": "refs/heads/my-feature" |
| 275 | } |
| 276 | } |
| 277 | ``` |
| 278 | |
| 279 | Note: As more advanced locking workflows are implemented, more details will |
| 280 | likely be added to this request body in future iterations. |
| 281 | |
| 282 | ### Successful Response |
| 283 | |
| 284 | A successful response will list the relevant locks: |
| 285 | |
| 286 | * `ours` - Array of Lock objects currently owned by the authenticated user. |
| 287 | modify. |
| 288 | * `theirs` - Array of Lock objects currently owned by other users. |
| 289 | * `next_cursor` - Optional string cursor that the server can return if there |
| 290 | are more locks matching the given filters. The client will re-do the request, |
| 291 | setting the `cursor` property with this `next_cursor` value. |
| 292 | |
| 293 | If a Git push updates any files matching any of "our" locks, Git LFS will list |
| 294 | them in the push output, in case the user will want to unlock them after the |
| 295 | push. However, any updated files matching one of "their" locks will halt the |
| 296 | push. At this point, it is up to the user to resolve the lock conflict with |
| 297 | their team. |
| 298 | |
| 299 | Note: If the server has no locks, it must return an empty array in the `ours` or |
| 300 | `theirs` properties. |
| 301 | |
| 302 | ```json5 |
| 303 | // HTTP/1.1 200 Ok |
| 304 | // Content-Type: application/vnd.git-lfs+json |
| 305 | { |
| 306 | "ours": [ |
| 307 | { |
| 308 | "id": "some-uuid", |
| 309 | "path": "/path/to/file", |
| 310 | "locked_at": "2016-05-17T15:49:06+00:00", |
| 311 | "owner": { |
| 312 | "name": "Jane Doe" |
| 313 | } |
| 314 | } |
| 315 | ], |
| 316 | "theirs": [], |
| 317 | "next_cursor": "optional next ID" |
| 318 | } |
| 319 | ``` |
| 320 | |
| 321 | ### Not Found Response |
| 322 | |
| 323 | By default, an LFS server that doesn't implement any locking endpoints should |
| 324 | return 404. This response will not halt any Git pushes. |
| 325 | |
| 326 | Any 404 will do, but Git LFS will show a better error message with a json |
| 327 | response. |
| 328 | |
| 329 | * `message` - String error message. |
| 330 | * `request_id` - Optional String unique identifier for the request. Useful for |
| 331 | debugging. |
| 332 | * `documentation_url` - Optional String to give the user a place to report |
| 333 | errors. |
| 334 | |
| 335 | ```json5 |
| 336 | // HTTP/1.1 404 Not found |
| 337 | // Content-Type: application/vnd.git-lfs+json |
| 338 | { |
| 339 | "message": "Not found", |
| 340 | "documentation_url": "https://lfs-server.com/docs/errors", |
| 341 | "request_id": "123" |
| 342 | } |
| 343 | ``` |
| 344 | |
| 345 | ### Unauthorized Response |
| 346 | |
| 347 | Lock servers should require that users have push access to the repository before |
| 348 | they can get a list of locks to verify a Git push. |
| 349 | |
| 350 | * `message` - String error message. |
| 351 | * `request_id` - Optional String unique identifier for the request. Useful for |
| 352 | debugging. |
| 353 | * `documentation_url` - Optional String to give the user a place to report |
| 354 | errors. |
| 355 | |
| 356 | ```json5 |
| 357 | // HTTP/1.1 403 Forbidden |
| 358 | // Content-Type: application/vnd.git-lfs+json |
| 359 | { |
| 360 | "message": "You must have push access to verify locks", |
| 361 | "documentation_url": "https://lfs-server.com/docs/errors", |
| 362 | "request_id": "123" |
| 363 | } |
| 364 | ``` |
| 365 | |
| 366 | ### Error Response |
| 367 | |
| 368 | * `message` - String error message. |
| 369 | * `request_id` - Optional String unique identifier for the request. Useful for |
| 370 | debugging. |
| 371 | * `documentation_url` - Optional String to give the user a place to report |
| 372 | errors. |
| 373 | |
| 374 | ```json5 |
| 375 | // HTTP/1.1 500 Internal server error |
| 376 | // Content-Type: application/vnd.git-lfs+json |
| 377 | { |
| 378 | "message": "unable to list locks", |
| 379 | "documentation_url": "https://lfs-server.com/docs/errors", |
| 380 | "request_id": "123" |
| 381 | } |
| 382 | ``` |
| 383 | |
| 384 | ## Delete Lock |
| 385 | |
| 386 | The client can delete a lock, given its ID, by sending a `POST` to |
| 387 | `/locks/:id/unlock` (appended to the LFS server url, as described above). LFS |
| 388 | servers should ensure that callers have push access to the repository. They |
| 389 | should also prevent a user from deleting another user's lock, unless the `force` |
| 390 | property is given. |
| 391 | |
| 392 | Properties: |
| 393 | |
| 394 | * `force` - Optional boolean specifying that the user is deleting another user's |
| 395 | lock. |
| 396 | * `ref` - Optional object describing the server ref that the locks belong to. Note: Added in v2.4. |
| 397 | * `name` - Fully-qualified server refspec. |
| 398 | |
| 399 | ```json5 |
| 400 | // POST https://lfs-server.com/locks/:id/unlock |
| 401 | // Accept: application/vnd.git-lfs+json |
| 402 | // Content-Type: application/vnd.git-lfs+json |
| 403 | // Authorization: Basic ... |
| 404 | |
| 405 | { |
| 406 | "force": true, |
| 407 | "ref": { |
| 408 | "name": "refs/heads/my-feature" |
| 409 | } |
| 410 | } |
| 411 | ``` |
| 412 | |
| 413 | ### Successful Response |
| 414 | |
| 415 | Successful deletions return the deleted lock. See the "Create Lock" successful |
| 416 | response section to see what Lock properties are possible. |
| 417 | |
| 418 | ```json5 |
| 419 | // HTTP/1.1 200 Ok |
| 420 | // Content-Type: application/vnd.git-lfs+json |
| 421 | { |
| 422 | "lock": { |
| 423 | "id": "some-uuid", |
| 424 | "path": "/path/to/file", |
| 425 | "locked_at": "2016-05-17T15:49:06+00:00", |
| 426 | "owner": { |
| 427 | "name": "Jane Doe" |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | ``` |
| 432 | |
| 433 | ### Unauthorized Response |
| 434 | |
| 435 | Lock servers should require that users have push access to the repository before |
| 436 | they can delete locks. Also, if the `force` parameter is omitted, or false, |
| 437 | the user should only be allowed to delete locks that they created. |
| 438 | |
| 439 | * `message` - String error message. |
| 440 | * `request_id` - Optional String unique identifier for the request. Useful for |
| 441 | debugging. |
| 442 | * `documentation_url` - Optional String to give the user a place to report |
| 443 | errors. |
| 444 | |
| 445 | ```json5 |
| 446 | // HTTP/1.1 403 Forbidden |
| 447 | // Content-Type: application/vnd.git-lfs+json |
| 448 | { |
| 449 | "message": "You must have push access to delete locks", |
| 450 | "documentation_url": "https://lfs-server.com/docs/errors", |
| 451 | "request_id": "123" |
| 452 | } |
| 453 | ``` |
| 454 | |
| 455 | ### Error response |
| 456 | |
| 457 | * `message` - String error message. |
| 458 | * `request_id` - Optional String unique identifier for the request. Useful for |
| 459 | debugging. |
| 460 | * `documentation_url` - Optional String to give the user a place to report |
| 461 | errors. |
| 462 | |
| 463 | ```json5 |
| 464 | // HTTP/1.1 500 Internal server error |
| 465 | // Content-Type: application/vnd.git-lfs+json |
| 466 | { |
| 467 | "message": "unable to delete lock", |
| 468 | "documentation_url": "https://lfs-server.com/docs/errors", |
| 469 | "request_id": "123" |
| 470 | } |
| 471 | ``` |