How to require a fork with composer

穿精又带淫゛_ 提交于 2019-11-26 02:29:26

问题


here is my composer.json, i want to use Nodge\'s fork of lessphp project on Github

 \"repositories\": [{
    \"type\": \"package\",
    \"package\": {
        \"version\": \"dev-master\",
        \"name\": \"nodge/lessphp\",
        \"source\": {
            \"url\": \"https://github.com/Nodge/lessphp.git\",
            \"type\": \"git\",
            \"reference\": \"master\"
        },
        \"autoload\": {
            \"classmap\": [\"lessc.inc.php\"]
        }
    }
}],
\"require\": {
    \"php\": \">=5.3.3\",
    \"nodge/lessphp\": \"dev-master\"
},

But i have this error when i make update :

nodge/lessphp dev-master -> no matching package found.

I don\'t know how to require it correctly this fork...

Any suggestions ?


回答1:


The most common (and easier) way of doing it is using a VCS repository.

All you have to do is add your fork as a repository and update the version constraint to point to your custom branch. Your custom branch name must be prefixed with dev-.

Example assuming you patched monolog to fix a bug in the bugfix branch:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/igorw/monolog"
        }
    ],
    "require": {
        "monolog/monolog": "dev-bugfix"
    }
}

Note that you don't change the require statement except to specify your bugfix branch. You still reference the upstream package (monolog/monolog), not your personal fork (igorw/monolog). You can read details in the docs




回答2:


Using VCS works:

"name": "test/test",
"repositories": [{
    "type": "vcs",
    "url": "http://github.com/Nodge/lessphp"
}],
"require": {
    "leafo/lessphp": "dev-master"
},

But if I require a module that has this composer.json, it doesn't work. It installs the original project, not the fork.

Example

"name": "example/example",
"require": {
    "test/test": "dev-master"
},

I should mention again the repository. Is that normal?




回答3:


If you can't get @Neilime answer to work for you, make sure your fork uses a different branch.

For example push your changes to a branch on your fork called my-bugfix, do not added dev- prefix in your branch name but in your composer.json you have to add it. Your composer file will look like:

"repositories":
[
    {
        "type": "vcs",
        "url": "http://github.com/yourname/packageName"
    }
],
"require": {
    "owner/packageName": "dev-my-bugfix"
},



回答4:


According to the Composer documentation http://getcomposer.org/doc/05-repositories.md#vcs, it's enough to specify the original repository (not the fork) in the require ("nodge/lessphp" in your case). Composer will then install YOUR fork (look at the code in the vendors)




回答5:


I have tried many options but After I got this post I saw the light and it just worked perfect.

This is what you have to do:

1- Fork de repository

2- Create a branch and make the required modifications.

3- Add the repository label to your composer.json

"repositories": [

        {
            "type": "vcs",
            "url": "https://github.com/user/yourforkname"
        }
    ]

4- In the command line inside your project require your fork like this:

composer require vendor/packagename:dev-branchname

And Voilá!!

You have your fork version working




回答6:


I usually add a "dist" node to the package definition. I never had a problem using it this way.

I can't remember where I got this trick from, though, for any further explanations.

{
    "repositories": [
        {
            "type": "package",
            "package": {
                "version": "dev-master",
                "name": "nodge/lessphp",
                "source": {
                    "url": "https://github.com/Nodge/lessphp.git",
                    "type": "git",
                    "reference": "master"
                },
                "autoload": {
                    "classmap": ["lessc.inc.php"]
                },
                "dist": {
                    "url": "https://github.com/Nodge/lessphp/archive/master.zip",
                    "type": "zip"
                }
            }
        }
    ],
    "require": {
        "nodge/lessphp": "*"
    }
}



回答7:


So, this is 2019, and most of the answers here are already correct.

If you find yourself however, in a situation where you need to require a particular branch of your fork (that you created), have composer list the available versions/tags first. This saved me a lot of time.

A full example with spatie/laravel-backup package.

First, add repositories key to composer.json. With the url of your fork

"repositories": [{
   "type": "vcs",
   "url": "https://github.com/holymp2006/laravel-backup"
 }]

Get available versions/tags

composer show "spatie/laravel-backup" --all

Choose the version you want from versions in the terminal output, then require that version

composer require spatie/laravel-backup:v5.x-dev


来源:https://stackoverflow.com/questions/13498519/how-to-require-a-fork-with-composer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!