• Our product teams collect and evaluate feedback from a number of different sources. To learn more about how we use customer feedback in the planning process, check out our new feature policy.

      Is there any API to make a commit?
      I mean some way to send a repo a diff using rest api to apply it on the top of some branch.

            [BCLOUD-8672] Is there any API to make a commit? (BB-9954)

            Katherine Yabut made changes -
            Workflow Original: JAC Suggestion Workflow [ 3534346 ] New: JAC Suggestion Workflow 3 [ 3588857 ]
            Status Original: RESOLVED [ 5 ] New: Closed [ 6 ]

            gur_singh added a comment -

            api throwing an error with 500 status

            gur_singh added a comment - api throwing an error with 500 status

            evzijst added a comment -

            It looks like we forgot to document the branch parameter. @ggbt_sync already discovered it and it is there. I've created PR that adds it. Until that time, here's the missing fragment:

            The name of the branch that the new commit should be created on. When
            omitted, the commit will be created on top of the main branch and will become
            the main branch's new HEAD/tip.
            
            When a branch name is provided that already exists in the repo, then the
            commit will be created on top of that branch. In this case, *if* a parent
            SHA1 was also provided, then it is asserted that the parent is the branch's
            tip/HEAD at the time the request is made. When this is not the case, a 409
            is returned.
            
            This API cannot be used to create new anonymous heads in Mercurial repos.
            
            When a new branch name is specified (that does not already exist in the
            repo), and no parent SHA1s are provided, then the new commit will inherit
            from the current main branch's tip/HEAD commit, but not advance the main
            branch. The new commit will be the new branch. When the request *also*
            specifies a parent SHA1, then the new commit and branch branch are created
            directly on top of the parent commit, regardless of the state of the main
            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.
            
            When a branch name is not specified and the repo is empty, the new commit
            will become the repo's root commit and will be on the main branch.
            
            When a branch name is specified and the repo is empty, the new commit will
            become the repo's root commit and also define the repo's main branch going
            forward.
            
            This API cannot be used to create additional root commits in non-empty
            repos.
            
            The branch field cannot be repeated.
            
            As a side effect, this API can be used to create a new branch without
            modifying any files, by specifying a new branch name in this field,
            together with `parents`, but omitting the `files` fields, while not sending
            any files. This will create a new commit and branch with the same contents as
            the first parent. The diff of this commit against its first parent will be
            empty.
            

            evzijst added a comment - It looks like we forgot to document the branch parameter. @ggbt_sync already discovered it and it is there. I've created PR that adds it. Until that time, here's the missing fragment: The name of the branch that the new commit should be created on. When omitted, the commit will be created on top of the main branch and will become the main branch's new HEAD/tip. When a branch name is provided that already exists in the repo, then the commit will be created on top of that branch. In this case , * if * a parent SHA1 was also provided, then it is asserted that the parent is the branch's tip/HEAD at the time the request is made. When this is not the case , a 409 is returned. This API cannot be used to create new anonymous heads in Mercurial repos. When a new branch name is specified (that does not already exist in the repo), and no parent SHA1s are provided, then the new commit will inherit from the current main branch's tip/HEAD commit, but not advance the main branch. The new commit will be the new branch. When the request *also* specifies a parent SHA1, then the new commit and branch branch are created directly on top of the parent commit, regardless of the state of the main 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. When a branch name is not specified and the repo is empty, the new commit will become the repo's root commit and will be on the main branch. When a branch name is specified and the repo is empty, the new commit will become the repo's root commit and also define the repo's main branch going forward. This API cannot be used to create additional root commits in non-empty repos. The branch field cannot be repeated. As a side effect, this API can be used to create a new branch without modifying any files, by specifying a new branch name in this field, together with `parents`, but omitting the `files` fields, while not sending any files. This will create a new commit and branch with the same contents as the first parent. The diff of this commit against its first parent will be empty.

            Hi everyone,

            Please check out the documentation here:
            https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/

            {username}

            /

            {repo_slug}

            /src#post

            If you have would like to report feedback or a bug with the new endpoint, please file a new issue with the component API to avoid spamming the many watchers on this issue. If you have any questions about how to use the commit API, feel free to post them on the Atlassian Community or in the Bitbucket Integrators HipChat room.

            Thanks!

            Eric

            Development Team Lead

            Eric Henry (Inactive) added a comment - Hi everyone, Please check out the documentation here: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/ {username} / {repo_slug} /src#post If you have would like to report feedback or a bug with the new endpoint, please file a new issue with the component API to avoid spamming the many watchers on this issue. If you have any questions about how to use the commit API, feel free to post them on the Atlassian Community or in the Bitbucket Integrators HipChat room . Thanks! Eric Development Team Lead

            Nice find

            charlieduong94 added a comment - Nice find

            Gabriel T added a comment -

            It turns out that the API can target a branch but it is not documented.

            We can specify a branch like this:

            curl https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/
            --data-urlencode "/path/to/me.txt=Lorem ipsum."
            --data-urlencode "message=Initial commit"
            --data-urlencode "author=Erik van Zijst [erik.van.zijst%40gmail.com]"
            --data-urlencode "branch=DESIRED_BRANCH"

            Gabriel T added a comment - It turns out that the API can target a branch but it is not documented. We can specify a branch like this: curl https://api.bitbucket.org/2.0/repositories/atlassian/bbql/src/ --data-urlencode "/path/to/me.txt=Lorem ipsum." --data-urlencode "message=Initial commit" --data-urlencode "author=Erik van Zijst [erik.van.zijst%40gmail.com] " --data-urlencode "branch=DESIRED_BRANCH"

            I really need this. It's preventing me from using Bitbucket for one of my projects at the moment. Are there any plans to get this implemented?

            austinkelleher added a comment - I really need this. It's preventing me from using Bitbucket for one of my projects at the moment. Are there any plans to get this implemented?

            +1 support for targeting branches would be awesome.

            charlieduong94 added a comment - +1 support for targeting branches would be awesome.

            Gabriel T added a comment -

            Is there any way of committing a file to a chosen branch? I need to commit to a branch different from the main branch.

            Gabriel T added a comment - Is there any way of committing a file to a chosen branch? I need to commit to a branch different from the main branch.

            @awbb Can you please direct me to some links where I could find some examples to use this commit api?

            I read the documentation about commit on the API page, but when I tried, I couldn't get it to work.

            Any example would be helpful.

            amruta_dalbhanjan added a comment - @awbb Can you please direct me to some links where I could find some examples to use this commit api? I read the documentation about commit on the API page, but when I tried, I couldn't get it to work. Any example would be helpful.

              Unassigned Unassigned
              a9e91bdd8814 KOLANICH
              Votes:
              76 Vote for this issue
              Watchers:
              78 Start watching this issue

                Created:
                Updated:
                Resolved: