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

2

10

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?

Pisciculture answered 14/10, 2016 at 8:1 Comment(0)
R
7

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 [email protected] -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.

Ralfston answered 9/10, 2017 at 19:55 Comment(2)
question: how to commit multiple files in single commit using bitbucket api?Selfsacrifice
I am not aware if there is any API for supporting multiple files in single commit. Refers to atlassian developerRalfston
P
5

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.

Pisciculture answered 4/10, 2017 at 8:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.