How to correctly require a specific commit in Composer so that it would be available for dependent packages?

Maciej Sz picture Maciej Sz · Jan 23, 2014 · Viewed 60.3k times · Source

I have a library foo/foo-lib which requires a specific commit from GitHub:

{
    "name": "foo/foo-lib",
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/KnpLabs/Gaufrette.git"
        }
    ],
    "require": {
        "knplabs/gaufrette": "dev-master#2633721877cae79ad461f3ca06f3f77fb4fce02e"
    }
}

and it works fine:

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)                                 
  - Updating knplabs/gaufrette dev-master (2633721 => 2633721)
    Checking out 2633721877cae79ad461f3ca06f3f77fb4fce02e

Generating autoload files

but when I require that library in other project:

{
    "name": "bar/bar-app",
    "repositories": [
        {
            "type": "vcs",
            "url": "ssh://git.example.com/foo-lib"
        }
    ],
    "require-dev": {
        "foo/foo-lib": "dev-master"
    }
}

it yields dependency error:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for foo/foo-lib dev-master -> satisfiable by foo/foo-lib[dev-master].
    - foo/foo-lib dev-master requires knplabs/gaufrette dev-master#2633721877cae79ad461f3ca06f3f77fb4fce02e -> no matching package found.

So my question is: how to correctly require the specific commit from GitHub in my library, so that it would be available in dependent packages?

Answer

Chris picture Chris · Jan 23, 2014

You'll have to explicitly require the Gaufrette library at that hash, with a dev flag, in both your library and your application. Something like this should work in the application composer.json:

{
    "name": "bar/bar-app",
    "repositories": [
        {
            "type": "vcs",
            "url": "ssh://git.example.com/foo-lib"
        }
    ],
    "require-dev": {
        "foo/foo-lib": "dev-master",
        "knplabs/gaufrette": "dev-master#2633721877cae79ad461f3ca06f3f77fb4fce02e"
    }
}

From the documentation:

If one of your dependencies has a dependency on an unstable package you need to explicitly require it as well, along with its sufficient stability flag.

The documentation also suggests that you'll need to include the repository for Gaufrette in your bar/bar-app Composer file, though it sounds like this wasn't necessary in this case. I'm not sure why.