6

I've searched Atlassian docs and found this ref/pull-requests/$PR_NO/from and when I try to fetch that, I encounter this error Couldn't find remote ref refs/pull-requests/1/from. Is there a way to enable this ref? Or are webhooks the only option? I am trying a CI setup with Bitbucket.

(We're on the 10-user paid plan)

yowmamasita
  • 4,810
  • 3
  • 17
  • 17

3 Answers3

6

This is now possible. You just need to add a line like this to your <repo_root>/.git/config:

[remote "origin"]
    url = ...
    fetch = ...
    fetch = +refs/pull-requests/*:refs/pull-requests/*

When you fetch, you'll see a whole new set of refs appear:

$ git fetch origin
remote: Counting objects: 252, done.
remote: Compressing objects: 100% (48/48), done.
remote: Total 82 (delta 20), reused 0 (delta 0)
Unpacking objects: 100% (82/82), done.
From ...
 * [new ref]           refs/pull-requests/300/from  -> refs/pull-requests/300/from
 * [new ref]           refs/pull-requests/300/merge -> refs/pull-requests/300/merge
 * [new ref]           refs/pull-requests/302/from  -> refs/pull-requests/302/from
 * [new ref]           refs/pull-requests/323/from  -> refs/pull-requests/323/from
 * [new ref]           refs/pull-requests/323/merge -> refs/pull-requests/323/merge
 * [new ref]           refs/pull-requests/344/from  -> refs/pull-requests/344/from
 * [new ref]           refs/pull-requests/344/merge -> refs/pull-requests/344/merge
 * [new ref]           refs/pull-requests/350/from  -> refs/pull-requests/350/from
 * [new ref]           refs/pull-requests/350/merge -> refs/pull-requests/350/merge
 * [new ref]           refs/pull-requests/355/from  -> refs/pull-requests/355/from
 * [new ref]           refs/pull-requests/355/merge -> refs/pull-requests/355/merge

*/from gives you PR branch heads; */merge gives you the result of merging the PR with your target branch.

For more details, see Pull request proficiency: Fetching abilities unlocked!

Leponzo
  • 624
  • 1
  • 8
  • 20
user2248785
  • 385
  • 3
  • 12
  • See [this](https://stackoverflow.com/questions/48806891/bitbucket-does-not-update-refspec-for-pr-causing-jenkins-to-build-old-commits/48823808#48823808) for why it may be a bad idea. – Leponzo May 10 '21 at 15:48
3

This is unsupported by Bitbucket: https://bitbucket.org/site/master/issues/5814/reify-pull-requests-by-making-them-a-ref

imanuelcostigan
  • 3,459
  • 3
  • 17
  • 19
1

Supported by Bitbucket Server (Stash) (Self-hosted)

Stash supports refspecs and is available thru the following command

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

You can check against your .git/config file to see if it's setup properly

[remote "upstream"]
url = git@stash.atlassian.com:docker/libswarm.git
fetch = +refs/heads/*:refs/remotes/upstream/*
fetch = +refs/pull-requests/*/from:refs/remotes/upstream/pr/*

https://www.atlassian.com/blog/archives/how-to-fetch-pull-requests

Unsupported by Bitbucket Cloud (bitbucket.com)

Bitbucket Cloud currently do not support PR on refspec, available option would be to either Poll Bitbucket's Git or API Endpoint

https://jira.atlassian.com/browse/BCLOUD-5814

Given that the request have been on hold for 7 years it would be wise to not wait for the refspec implementation (as of Nov 2019)

puayhiang
  • 43
  • 1
  • 5
  • See [this](https://stackoverflow.com/questions/48806891/bitbucket-does-not-update-refspec-for-pr-causing-jenkins-to-build-old-commits/48823808#48823808) for why it may be a bad idea. – Leponzo May 10 '21 at 15:51