Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • G gitlabhq1
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 21
    • Issues 21
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • gpt
  • large_projects
  • gitlabhq1
  • Issues
  • #6260

Closed
Open
Created Feb 06, 2014 by Administrator@rootOwner

REST API - How to avoid concurrent updates

Created by: robertjchristian

The REST API looks like this

Update existing file in repository

PUT /projects/:id/repository/files
Parameters:

file_path (required) - Full path to file. Ex. lib/class.rb
branch_name (required) - The name of branch
encoding (optional) - 'text' or 'base64'. Text is default.
content (required) - New file content
commit_message (required) - Commit message

It would be nice if PUT took a sha or tag for an individual file update, and used it to prevent overwrites due to concurrent edits.

Use case:

- Application thread A hits GitLab REST to GET resource Foo
- Foo is returned, along with the SHA for Foo (12345)
- Application thread B hits GitLab REST to GET resource Foo
- Foo is returned, along with the SHA for Foo (12345)
- At this point, two separate "threads" have the same resource
- Application thread A makes changes to Foo and POSTS to GitLab REST API
- Application thread B makes changes to Foo and POSTS to GitLab REST API

Expected:

- When B makes POST, GitLab REST API should say "cannot push, not in sync with repository", just like it would if this were to occur in a local sandbox.

Suggested:

- In order to accomplish this, GET requests could return sha.  The sha can be used in the POST request.  If the sha sent in the post request is not the most recent version of the file resource, then the POST should return (ie) 409 Conflict.

Is there another way to accomplish this?

Assignee
Assign to
Time tracking