26

Ideal Situation

Often while working on a Symfony2 project I will spot something I want to change in one of my dependencies. If I could find a way to simply change it in vendor and then easily push the changes as a pull request then I would probably contribute more often (rather than overriding the part with a local child bundle).

The Problem

I can't change a vendor directory without composer freaking out on the next update. If I submit a pull request then it may take quite some time before I can actually use the code in vendors, which is actually a deterrent from contributing my new functionality.

How I do it now

The way I typically contribute to a bundle is to make a fork, put the fork in a barebones symfony standard-edition app, make the change and then submit a pull request.

Put fork in composer.json?

The only solution I can think of, is removing the packagist dependency of the bundle I am editing, and then including my fork with composer (as a package) from github. That way I get my code immediately and can still contribute.

Is this the only solution? How do you do it?

Any tips/advice for contributing to a bundle while working on a different project at the same time would be appreciated!

2
  • 2
    I think you have it right. There's 2 parts: submitting the patch and using the patch. I usually fork/branch the package in my working project to make the fix. Commit it and push it to my own repo. Then if i want to keep using that fix i'll add that reference to my fork/branch to composer.
    – MDrollette
    Commented Nov 10, 2012 at 19:22
  • We use the same approach as @MDrollette. First we use the standard packages. If something needs fixing (like the DBAL QueryBuilder - github.com/doctrine/dbal/pull/175), we fork it, use our fork instead of the standard one, modify code, write tests and open a pull request hoping that the fix gets included.
    – wimvds
    Commented Nov 11, 2012 at 10:23

4 Answers 4

56

Nah... this is broken.

I've tried the official way to include a fork, here's an example (original:kitano, fork: jstoeffler) of the composer.json :

(For those who are in a hurry: THIS DOESNT WORK)

"repositories": [
//...
    {
        "type": "vcs",
        "url": "https://github.com/jstoeffler/KitanoConnectionBundle",

    },
//...
],

It keeps using the original bundle. Don't know what the problem is, and I don't get how everything works, but here's how I successfully add a fork to a project.

"repositories": [
//...
    {
        "type": "package",
        "package": {
            "name": "kitano/connection-bundle",
            "version": "dev-master",
            "source": {
                "url": "https://github.com/jstoeffler/KitanoConnectionBundle.git",
                "type": "git",
                "reference": "master"
            },
            "autoload": {
                "classmap": [""]
            }
        }
    },
//...
],
9
  • 1
    Thanks for this alternate method. Commented Jan 16, 2015 at 14:26
  • 10
    Just want to add that it is nice to have an alternate method, but the official method does work (I've just use it today with an up-to-date composer installation). I've just needed to append the dev- prefix in front of my forked branch name and it worked like a charm.
    – mTorres
    Commented Jan 17, 2015 at 11:03
  • 5
    @mTorres that did not work for me, unfortunately. Julien's did. Commented Sep 16, 2015 at 8:50
  • 2
    From what Im understanding, if your branch is out of date with the master branch and that other modules require the up to date original, the official method doesn't work.
    – delmalki
    Commented Feb 9, 2016 at 1:07
  • 1
    Just to clarify for others (since this slipped me up), the reference value should be the name of your branch excluding the dev- prefix.
    – Pete
    Commented Sep 23, 2016 at 23:41
9

As of 2017 the proper way to do it is:

  1. Add your GitHub branch link to the repositories

    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/crimson-med/yii2-link-preview"
        }
    ],
    
  2. Add the source to the require of your composer.json

    "require": {
        "yii2mod/yii2-link-preview": "dev-master"
    },
    
7

[UPDATE: Answer Not Valid Anymore]

As pointed out in one of the comments, this answer is a couple years old and not correct anymore. See answers below for the correct way to proceed.

[Original answer below]

This is the approach recommended by Jordi Boggiano (@Seldaek), creator of composer. See from his talk at Symfony Live San Francisco earlier this year (at the 2 minutes mark): http://www.youtube.com/watch?list=PLo7mBDsRHu11ChvScWUE7MN1Qo5QVHQEz&feature=player_detailpage&v=P3NwF8RV1lY#t=120s

2
  • Thanks for sharing. This is the only way I've tried that retrieves the fork and works with dependencies. Rather than using the https form for the repository as shown in the video I use this form. It doesn't require a password- [email protected]:<user>/<module-name>.git The key to satisfying dependencies is inline aliasing.
    – cmc
    Commented May 5, 2015 at 18:41
  • outdated information, see below for correct answer for this specific issue as of Oct 2016
    – Joey T
    Commented Oct 26, 2016 at 1:11
2

FYI, I just tried the very first option:

    "repositories": [{
    "type": "vcs",
    "url": "https://github.com/thujohn/twitter"
}],
"require": {
    "laravel/framework": "4.2.*",
    "thujohn/twitter": "dev-master",
    "anahkiasen/flickering": "^0.1.2",
    "fairholm/elasticquent": "dev-master",
    "facebook/php-sdk-v4" : "~5.0"
},

An it worked fine.

vagrant@dev:/var/www$ sudo php composer.phar update
Loading composer repositories with package information                                                                                                                                                         Updating dependencies (including require-dev)         
  - Removing thujohn/twitter (2.0.4)
  - Installing thujohn/twitter (dev-master 7a92118)
    Downloading: 100%         

Writing lock file
Generating autoload files
> php artisan clear-compiled
> php artisan optimize
Generating optimized class loader

I just needed to specify the "master" branch name as "dev-master".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.