Skip to content

Return 409 on update file conflict and clarify last_commit_id usage

Dominic requested to merge dtobias/gitlab-ce:master into master

What does this MR do?

Hi, RE https://docs.gitlab.com/ee/api/repository_files.html#update-existing-file-in-repository

I found it unclear that the param to use to avoid overwriting other updates is last_commit_id.

I clarified the doc and also return a HTTP 409 Conflict if there is a conflict.

But what I really wanted to do was also return the updated SHA, so that we don't have to make another request just to get the updated SHA.

But I'm new to Ruby and this project, I traced the response:

update_service.rb->create_commit
respository.rb -> update_file
update_file -> multi_action
multi_action -> Gitlab::Git::OperationService::BranchUpdate.from_gitaly

def self.from_gitaly(branch_update)
  return if branch_update.nil?

  new(
    branch_update.commit_id,
    branch_update.repo_created,
    branch_update.branch_created
  )
end

But it's not obvious to me where the response is generated, current it's:

{
    "file_path": "src/locales/en.js",
    "branch": "master"
}

and I want to change it to:

{
    "file_path": "src/locales/en.js",
    "branch": "master",
    "sha": "new sha"
}

What are the relevant issue numbers?

https://gitlab.com/gitlab-org/gitlab-ce/issues/56885

Does this MR meet the acceptance criteria?

I will fill this/do it in if someone points me in the right direction of returning the new SHA

Edited by Dominic

Merge request reports