17

I've got a repo on Bitbucket that only I have write access to.

Someone forked that repo, made changes and issued a pull request to my repo from the fork.

How can I get that pull request as a git patch to apply temporarily to my repo for testing purposes?

The forked repo is private so I can't pull it down, and I wouldn't want to do that anyway.

On GitHub you can simply go to a pull request and add a .patch to the end of the url to download the patch. This doesn't work with Bitbucket.

Nick Spiers
  • 2,344
  • 2
  • 19
  • 31
  • Can you pull it into a branch other than master? – George Hilliard Oct 19 '13 at 21:01
  • No. I could ask him to edit the PR to target a different branch, but I'd still have to accept it to be able to pull it. – Nick Spiers Oct 20 '13 at 21:43
  • Create a throwaway branch and ask him to edit the PR to that branch. Merge it, and if you don't like it, just delete (`-D`) the branch. Alternatively, explain to him that you're not going to merge code that you can't view, and ask him for read access to that branch. (One of the things I don't like about BitBucket.) – George Hilliard Oct 20 '13 at 22:12
  • Not exactly ideal, but I guess if I have no other options... – Nick Spiers Oct 22 '13 at 15:11

3 Answers3

25

The Pull Request Patch is available through bitbucket API (despite there is no button to download it directly from the Pull Request page).

to access the Pull Request patch : https://bitbucket.org/api/2.0/repositories/GROUP/PROJECT/pullrequests/ID/diff

source: https://jira.atlassian.com/browse/BCLOUD-8323?focusedCommentId=2226612&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-2226612

Nick Spiers
  • 2,344
  • 2
  • 19
  • 31
Lythom
  • 298
  • 4
  • 4
8

For 7.x versions you might try these links based on info from https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-rest.wadl and https://docs.atlassian.com/bitbucket-server/rest/7.11.1/bitbucket-git-rest.html:

Pull requests: https://bitbucket.example.com/rest/api/1.0/projects/GROUP/repos/PROJECT/pull-requests/ID.patch

Commits: https://bitbucket.example.com/rest/api/1.0/projects/GROUP/repos/PROJECT/patch?until=COMMIT (the since= query parameter can also be tried for a starting commit).

Lekensteyn
  • 64,486
  • 22
  • 159
  • 192
0

Adding to Nick Spier's answer above:

You need to include an access token with your request otherwise you will get a permission error.

Hasan Akhtar
  • 251
  • 3
  • 8