Checkout bitbucket pull requests locally

2019-01-22 18:40发布

I found this gist: https://gist.github.com/kennethreitz/3709868

Im using bitbucket and I'm looking for a similar function.

Can you help me? Thank you

标签: bitbucket
4条回答
Anthone
2楼-- · 2019-01-22 19:09

One may fetch the code from Bitbucket Server's pull requests using:

git fetch origin refs/pull-requests/$PR_NO/from:$LOCAL_BRANCH
查看更多
Summer. ? 凉城
3楼-- · 2019-01-22 19:16

It seems the easiest way to do this is still to get a patch of the pull request. Based on this question's answer, Alexandre's comment is still the only way to do this. It uses this BitBucket API call.

I used the following bash script:

USER=username
PASSWORD=password
REPO=repo-name
PULL_NO=42
OUTPUT_FILE=output.patch

# Add -i to include the HTTP-header in the output for debugging
curl -u $USER:$PASSWORD https://bitbucket.org/api/2.0/repositories/$USER/$REPO/pullrequests/$PULL_NO/patch -L -o $OUTPUT_FILE

Save that to a file called pull-patch.sh and fill in the environment variables with your account details. The script requires that you have curl installed (e.g. sudo apt install curl). Then run:

chmod +x pull-patch.sh
./pull-patch.sh

And a file called output.patch should be created from the pull request.

查看更多
Fickle 薄情
4楼-- · 2019-01-22 19:21

I followed this article Pull request Fetching.

It worked but I found out I just need add one line to the current repo, rather than create a folk repo and an upstream repo. Run this line

git config --add remote.origin.fetch '+refs/pull-requests/*/from:refs/remotes/origin/pr/*'

You can also add it manually to the file .git/config in your project.

Next run git pull you should see a list:

  • [new ref] refs/pull-requests/488/from -> origin/pr/488
  • [new ref] refs/pull-requests/666/from -> origin/pr/666

Then you can run git checkout origin/pr/666 to get the pull request changes.

查看更多
贪生不怕死
5楼-- · 2019-01-22 19:26

I found this answer and thought that it was actually possible to fetch refs for a pull request on bitbucket.

But it's not.

The answer for the OP's question is that it is NOT possible: there's been an open feature request issue about it that has been unanswered and unattended for four five SIX years.

The workaround?

You can get the PR as a downloadable .patch file you can download and apply to a new branch you create manually. But you won't easily be able to apply updates.

I figured another way out, which I've implemented in git-repo, so everybody can use it. What I'm doing is use the API to get the PR's remote and branch, and automatically create a new upstream and branch locally. That way you can get updates from the PR poster. The downside is the clutter of git remotes.

查看更多
登录 后发表回答