06: Submitting a PR to php-src

Submitting a pull request to php-src :: Writing tests for PHP source

Jul 24, 2017

We found some untested lines of code and wrote a useful test that covered the lines so let's submit our new test to the main php-src repo.

Don't we need to create an RFC to send a pull request? Not for bug fixes and tests, so we're in the clear.

Getting setup on GitHub

If you've never contributed to open source via GitHub before, check out my post, How to contribute to an open source project on GitHub.

First you need to sign up for GitHub and get your SSH keys set up.

We made sure we got the, "You've successfully authenticated" message to verify that our SSH keys were set up properly.

$ ssh -T git@github.com
Hi SammyK! You've successfully authenticated, but GitHub does not provide shell access.

Then we made sure to set our name & email in the global git config. You should use the same email address that you use on GitHub.

$ git config --global user.name "Sammy Kaye Powers"
$ git config --global user.email "foo@example.com"

Forking the php-src repo

You'll need to create a fork of the main php-src repo to your account.

We listed our remotes to see the origin URL was set from the URL we used to clone the repo.

$ git remote -v
origin	https://github.com/php/php-src.git (fetch)
origin	https://github.com/php/php-src.git (push)

We need to change the origin URL to point to our fork we just created and then add a new remote called upstream that points to the php source repo.

Note: Make sure to replace {your-username} with your GitHub username.

$ git remote set-url origin git@github.com:{your-username}/php-src.git
$ git remote add upstream git@github.com:php/php-src.git

Pushing the changes to our fork

Before we committed our change, we switched to the master branch since we want to create a new branch for our change off of master. We named the new branch test-json-depth-error but you can name it whatever you like.

$ git checkout master
$ git checkout -b test-json-depth-error

Then we staged, committed and pushed our new branch up to our fork on GitHub.

$ git add ext/json/tests/json_decode_error001.phpt
$ git commit -m "Add test for json_decode() depth error case"
$ git push origin test-json-depth-error

Send a pull request (PR)

We opened our fork up in GitHub and saw a message asking if we'd like to submit the new branch we created as a pull request back to the main php-src repo. So we clicked the button and created a pull request.

In order to keep our fork and local copy of the repo up to date, we made use of git fetch and git rebase.

$ git fetch upstream
$ git checkout master
$ git rebase upstream/master master
$ git push origin master

Congrats! You're now an official PHP internals contributor!

Congrats!

Resources


All posts in this series


If you found this guide helpful, say, "Hi" on twitter! I'd love to hear from you. :)