Commit a file to git repository using Stash (bitbucket server) REST API

守給你的承諾、 提交于 2020-12-02 07:18:48

问题


I am using Atlassian Stash (Bitbucket server) to manage my git repository. Recently I had a requirement to commit a file (a newly created .xml file) to my Git repository using the Stash REST API. I've gone through the documentation, but it seems like the REST API doesn't support that functionality.

Am I correct, or is this possible somehow?


回答1:


Probably you are looking for

PUT /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/browse/{path:.*}

From the documentation of API

PUT /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/browse/{path:.*}

Update the content of path, on the given repository and branch. This resource accepts PUT multipart form data, containing the file in a form-field named content. An example curl request to update 'README.md' would be:

curl -X PUT -u username:password -F content=@README.md -F 'message=Updated using file-edit REST API' -F branch=master -F sourceCommitId=5636641a50b http://example.com/rest/api/latest/projects/PROJECT_1/repos/repo_1/browse/README.md

  • branch: the branch on which the path should be modified or created
  • content: the full content of the file at path message: the message associated with this change, to be used as the commit message. Or null if the default message should be used.
  • sourceCommitId: the commit ID of the file before it was edited, used to identify if content has changed. Or null if this is a new file.

The file can be updated or created on a new branch. In this case, the sourceBranch parameter should be provided to identify the starting point for the new branch and the branch parameter identifies the branch to create the new commit on.




回答2:


This cannot be done via the Stash/Bitbucket Server REST API. I had to move to JGit, which is a Java wrapper for communication between GIT and Application.

The question Is it possible to commit a file to a remote base repository using JGit has more information.



来源:https://stackoverflow.com/questions/40037984/commit-a-file-to-git-repository-using-stash-bitbucket-server-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!