PRs from forked repos failing to checkout on bitbucket.org
- Dominant language
- Go
- Stars
- 1.1k
- Forks
- 378
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 74
Description
I ran into an interesting shortcoming recently that may need some attention.
Part of the standard practice I have been using when working with git repositories is that I always fork a copy of the repo, make my changes there, keep it up to date using `git fetch remote` and then contribute back using a pull request.
Turns out that when I fork / update / raise a PR on `bitbucket.org`, the buildkite agent was unable to checkout the changes. Here is an example of from the logs:
```
$ cd /var/lib/buildkite-agent/builds/build-123/account/project
# Host "bitbucket.org" already in list of known hosts at "/var/lib/buildkite-agent/.ssh/known_hosts"
$ git clone -v -- git@bitbucket.org:account/project.git .
Cloning into '.'...
remote: Counting objects: 531, done.
remote: Compressing objects: 100% (238/238), done.
remote: Total 531 (delta 248), reused 436 (delta 204)
Receiving objects: 100% (531/531), 21.45 MiB | 5.89 MiB/s, done.
Resolving deltas: 100% (248/248), done.
$ git submodule foreach --recursive git clean -ffxdq
$ git clean -ffxdq
$ git fetch -v origin ABCDEF123456
fatal: Couldn't find remote ref ABCDEF123456
$ git fetch -v --prune origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
From bitbucket.org:account/project
= [up to date] master -> origin/master
$ git checkout -f ABCDEF123456
error: pathspec 'ABCDEF123456' did not match any file(s) known to git.
⚠️ Warning: Checkout failed! Error running `/usr/bin/git checkout -f ABCDEF123456`: exit status 1 (Attempt 1/3 Retrying in 2s)
```
Looking into this, turns out this is because unlike with github.com, `bitbucket.org`'s refspecs & branches for pull requests are internal only. To the best of my knowledge there are 3 options:
- Only merge PRs from branches 👎
- using `git clone --mirror` 😨
- or make code change to the build agent to create a remote back to the origin of the PR (using envionment var BUILDKITE_PULL_REQUEST_REPO) and then attempt checkout. ❓
If you are interested in the 3rd option, I written a possible solution and would be more than happy to raise a PR.
Cheers,
Ryan
Contributor guide
Assessment
This issue has not been assessed yet.