Working with Github pull requests on other people's repos

February 4th, 2013

Working with third party libraries, composer and github pull requests...

I'm using Composer for a ZF2 project.  I just upgraded to Zend Framework 2.1 from 2.0.6, and found that Ben Youngblood's bjyoungblood/BjyProfiler stopped working.  A quick query on Freenode's #zftalk channel (thanks Diemuzi) showed me that a fix  and subsequent pull request had been made, but the project's maintainer hadn't pulled it in yet.  So how can I make use of this fix?

  1. First step: fork the project on Github (dmakovec/BjyProfiler)
  2. Next, clone it down to my computer.  I used the OSX GitHub GUI to do this, but "git clone" would do the trick
  3. Locate the pull request (Diemuzi showed it to me, but you'll find it in the github page if you're not so lucky)
  4. Go into your clone and perform the pull:

    cd ~/dev/BjyProfiler && git pull https://github.com/internalsystemerror/BjyProfiler.git hotfix/issue-21
    
  5. Push it back up - git push origin master
  6. Alter your project's composer.json file to add your project repo in.
...
    "homepage": "http://www.example.com/",
# BEGIN INSERT #
    "repositories": [
        { 
            "type": "vcs", 
            "url": "https://github.com/dmakovec/BjyProfiler" 
        } 
    ], 
# END INSERT #
    "require": {
...
  1. Blow away the project's vendor folder (rm -rf vendor/bjyoungblood) - if you don't do this, composer may not update your repo and you'll be stuck scratching your head as to WTF went wrong for an hour.

What you're doing is telling composer to check the named repositories for any of the packages named in the "require" section before going off to packagist and doing the same. If it finds a match in the repo (in this case, the "BjyProfiler" repo will contain a clone of the "composer.json" file in the top level folder, advising composer that the repo is indeed "bjyoungblood/bjy-profiler"), then it will pull the package from that repo instead of Packagist. Then you just keep an eye on the project so that when the change is merged in, you can go back to the upstream project repo.


BjyProfiler

composer

git

github

php

zf2

pr

pull request