Reputation: 66435
I'm struggling to understand how to implement the following API to update files in a repo:
GitLab and GitHub have a simple api - pass contents of a file + commit SHA, and it will update if the commit SHA is still current.
I tried this and of course it happily overwrites anything that was already there:
curl -X POST \
'https://api.bitbucket.org/2.0/repositories/%7B%7D/{uuid}/src' \
-H 'Authorization: Bearer ***' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'cache-control: no-cache' \
-d 'src%2Flocale%2Fen.js=test&message=Test%20commit'
How can I specify a file commit SHA so that it doesn't overwrite content if it's been updated? Thanks
Upvotes: 3
Views: 3287
Reputation: 710
In the documentation you already have in your question it is stated:
parents (string):
A comma-separated list of SHA1s of the commits that should be the parents of the newly created commit.
When omitted, the new commit will inherit from and become a child of the main branch's tip/HEAD commit.
When more than one SHA1 is provided, the first SHA1 identifies the commit from which the content will be inherited.
When more than 2 parents are provided on a Mercurial repo, a 400 is returned as Mercurial does not support "octopus merges".
That doesn't really say something about prevention, but in the description of the branch
parameter it is stated:
When a branch name is not specified, but a parent SHA1 is provided, then Bitbucket asserts that it represents the main branch's current HEAD/tip, or a 409 is returned.
So, sounds like you just need to add that parameter to your data payload and it should prevent changes if the provided hash is not the current commit. You would then get a response with a http status 409 back.
-d 'src%2Flocale%2Fen.js=test&message=Test%20commit&parents=sha-hash'
Upvotes: 1