Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer won't use my fork

I'm trying to get composer to use my own fork of a library.

Original: https://github.com/KnpLabs/php-github-api My Fork: https://github.com/TransitScreen/php-github-api

I was able to install the original with composer simply by adding this to composer.json:

{
    "require": {
        "knplabs/github-api": "~1.4"
    }
}

I followed the instructions in the documentation, and changed it to this:

{
    "repositories": [
        {
            "type": "git",
            "url": "https://github.com/TransitScreen/php-github-api.git"
        }
    ],
    "require": {
        "knplabs/github-api": "dev-master"
    },
    "minimum-stabilitiy": "dev"
}

In my forked repository I have both a master and dev-master branch created. It's not clear to me which is correct, so I made both. I've also tried by using "type" : "vcs" and removing the .git from the URL. Neither one works. I run composer update and then the composer.lock file still points to the original repo URL, not mine. So I never get my changes when I run composer install.

What am I doing wrong??

PS: I've noticed that the library I'm trying to fork has this in it's composer.json file:

"extra": {
    "branch-alias": {
        "dev-master": "1.4.x-dev"
    }
}

I haven't found any documentation to explain what effect the alias might have. For example, should my forked repository have a 1.4.x branch??

Update 1 By the way, I know some of my configurations must be correct because I when run composer update after deleting the cache, there is a moment when I see that it's reading the composer.json of my (the correct) repository. But then afterwards composer.lock still points to the original (incorrect).

Update 2 I've also tried using composer update --prefer-source but it still doesn't work.

like image 418
emersonthis Avatar asked Aug 04 '15 19:08

emersonthis


People also ask

Why is composer not working?

Make sure you have no problems with your setup by running the installer's checks via curl -sS https://getcomposer.org/installer | php -- --check . Try clearing Composer's cache by running composer clear-cache . Ensure you're installing vendors straight from your composer.

How do I update my composer lock file?

lock file prevents you from automatically getting the latest versions of your dependencies. To update to the latest versions, use the update command. This will fetch the latest matching versions (according to your composer. json file) and update the lock file with the new versions.


1 Answers

I figured out the problem!

I had edited the composer.json file inside my forked repository... It looked like this:

{
    "name": "knplabs/github-api",
    "type": "library",
    "description": "GitHub API v3 client",
    "homepage": "https://github.com/TransitScreen/php-github-api",
    "keywords": ["github", "gh", "api", "gist"],
    "license": "MIT",

But I changed it to this:

{
    "name": "transitscreen/php-github-api",
    "type": "library",
    "description": "GitHub API v3 client",
    "homepage": "https://github.com/TransitScreen/php-github-api",
    "keywords": ["github", "gh", "api", "gist"],
    "license": "MIT",

I thought that the name needed to match the new repository, but I was wrong. When I changed it back to the original name, everything works!

Many thanks to @Tomas for offering useful troubleshooting tips.

I didn't see any documentation about this anywhere, so I PRed an update to the composer docs: https://github.com/composer/composer/pull/4329

like image 99
emersonthis Avatar answered Sep 22 '22 14:09

emersonthis