23
votes

I've created two git repositories that we need to install in one of our web applications by using PHP's composer. There are two branches on each repository, master and dev-master.

Inside the project I want the package to install, I've created the following composer.json package configuration:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "proprietary",
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "impression-works/pdf-generator",
                "version": "dev-master",
                "source": {
                    "url": "git@github.com:...",
                    "type": "git",
                    "reference": "dev-master"
                }
            }
        },
        {
            "type": "package",
            "package": {
                "name": "impression-works/psd-templates",
                "version": "dev-master",
                "source": {
                    "url": "git@github.com:...",
                    "type": "git",
                    "reference": "dev-master"
                }
            }
        }
    ],
    "require": {
        // ...
        "impression-works/psd-templates": "dev-master",
        "impression-works/pdf-generator": "dev-master"
    },
    "autoload": {
        // ...
        "psr-0": {
            "ImpressionWorks\\PsdTemplates": "vendor/impression-works/psd-templates/src",
            "ImpressionWorks\\PdfGenerator": "vendor/impression-works/pdf-generator/src"
        }
    },
    // ...
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "stable"
}

When I initially run composer update or composer install, the impression-works packages install perfectly, however, if I make changes to these repositories, and push them to dev-master, any successive calls to composer update simply reports:

Nothing to install or update

How do I force composer to update to the latest commit on these two custom packages of ours?

6

6 Answers

20
votes

I come to this page multiple times a week from a Google search, only to see that it doesn't answer my problem. So here goes.

I'm using packagist.org, not VCS. I do not want to use VCS as it slows Composer even more, and it's already painfully slow.

Consider the following scenario. Application in early development depends on a package I'm building. The package is also early in dev, so dev-master as version to get the latest master every time.

I fix a critical bug in the package, commit & push it, mash the update button in packagist.org, and then run composer update, and absolutely nothing happens.

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files

At this point you might try clearing the cache. It doesn't help.

Some point in time you'll stumble upon this open issue from 2012. After that you'll find out that the only way to get the latest version installed is to use the commit hash in the require.


composer require vendor/package dev-master#0d7d6c88

This requires that you manually get the commit hash and update the version to composer.json, and then run composer update again. Not exactly what you'd expect from a dependency manager. Looks like the issue is never going away, so unless someone writes a better Composer, we're stuck with this behavior.

The alternative is tagging every single commit that you want to download using Composer. Beware of confusing minimum stability rules & errors, which Composer throws by default.

19
votes

You should rather use custom repositories of type VCS. The package repo you used has a few limitations as highlighted in the docs:

  • Composer will not update the package unless you change the version field.
  • Composer will not update the commit references, so if you use master as reference you will have to delete the package to force an update, and will have to deal with an unstable lock file.
6
votes

I just have had the same problem. After figuring it out, the solution is fairly simple: clean the cache.

What Josef and Christian are looking for can be accomplished with this two lines:

composer clearcache
composer upgrade

That loads the last repository master for me. Hope it helps the next one, reading this thread.

Important Note:

You have to wait for the GitHub service hook to kick in and update the composer package on packagist.org or use the 'Update' button manually on the site.

This is not a matter of seconds... you have to wait for some time (normally one to five minutes) to give packagist a chance to distribute the changes.

So for constant, rapid development, I would just manually cd vendor/base/package and git update. And from time to time try the above clearcache and upgrade.

4
votes

A simpler version than the answer of @Bitclaw, for me the following works flawlessly:

composer update --prefer-source developer/package
-1
votes

Running composer upgrade is a bit dangerous since it may update all the other dependencies you have. In this case I would run the following:

composer clearcache;composer update --lock;composer install --prefer-source -vvv
-1
votes

Try this

composer clear-cache
composer update