Testing a pull request, then merging locally; and avoiding TOCTOU
source link: https://gist.github.com/adam-p/15413fabef6cffecd897
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Testing a pull request, then merging locally; and avoiding TOCTOU · GitHub
It's not immediately obvious how to pull down the code for a PR and test it locally. But it's pretty easy. (This assumes you have a remote for the main repo named upstream
.)
Getting the PR code
-
Make note of the PR number. For example, Rod's latest is PR #37: Psiphon-Labs/psiphon-tunnel-core#37
-
Fetch the PR's pseudo-branch (or bookmark or rev pointer whatever the word is), and give it a local branch name. Here we'll name it
pr37
:
$ git fetch upstream pull/37/head:pr37
- Switch to that branch:
$ git checkout pr37
- Compile and test.
If the PR code changes and you want to update:
# Do this while in the pr37 branch
$ git pull upstream pull/37/head
(I try to avoid pull
and instead use fetch
+merge
, but... I don't know how to do it for this.)
Merging the PR
You can use the Github web interface, but there's a TOCTOU problem: If the pull-requester changes their master (or whatever they're PRing from) between the time you test and the time you merge, then you'll be merging code that you haven't reviewed/tested. So let's do it on the command line.
First, checkout the upstream master code:
You'll only do this the first time -- it creates the local upstream_master
branch, tracks it to upstream_master
, and switches to the branch:
$ git checkout -t -b upstream_master upstream/master
After the first time you'll just do:
$ git checkout upstream_master
Now merge the PR:
$ git merge pr37
NOTE: You should edit the merge commit message to reference the PR (using, say #37
in it).
Now push:
$ git push upstream HEAD:master
(You can't just git push
because your local branch name is different than the remote.)
Done! Refresh the Github PR page and you'll see that the PR is now merged+closed.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK