bitbucket - BitBucket:如何通过 API 更新文件
问题描述
我正在努力了解如何实现以下 API 来更新存储库中的文件:
GitLab 和 GitHub 有一个简单的 api - 传递文件内容 + 提交 SHA,如果提交 SHA 仍然是最新的,它将更新。
我试过这个,当然它很高兴地覆盖了已经存在的任何东西:
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'
如何指定文件提交 SHA,以便在更新时不会覆盖内容?谢谢
解决方案
在您的问题中已有的文档中指出:
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".
这并没有真正说明预防,但在branch
参数的描述中指出:
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.
因此,听起来您只需要将该参数添加到您的数据有效负载中,并且如果提供的哈希不是当前提交,它应该可以防止更改。然后,您将收到带有 http 状态 409 的响应。
-d 'src%2Flocale%2Fen.js=test&message=Test%20commit&parents=sha-hash'
推荐阅读
- php - Google API Analytics - 为什么 URI 中的 View ID 不是我的 ViewID?
- python - 无法在 Python 中将 csv 文件转换为文本制表符分隔文件
- autodesk-forge - 在 Forge Design Automation API 中更改打印机支持文件路径
- javascript - 期望 spy 函数以一定长度的数组被调用
- mongodb - MongoDB函数以及如何调用它?
- c# - 如何使用 C# 在 UWP 中进行延迟
- php - php中文件的相对路径
- css - 使用 React 开发游戏时发现错误
- wordpress - Wordpress 中 do_action() 和 add_action() 的区别
- python - 我的不和谐机器人,没有得到任何视频代码