Change Composer git source for a package

懵懂的女人 提交于 2019-12-18 11:47:32

问题


I pull in a package using Composer with this composer.json:

{
    "require": {
        "torophp/torophp": "dev-master",
    },
}

When I run composer install it seems to pull this package from GitHub directly.

I have created a fork of that repo on github with some small changes. Is there a way I can get composer to pull my version on GitHub instead of the original?


回答1:


If this is your composer.json

"require": {
  "torophp/torophp": "dev-master"
}

and you want to change it and use your fork instead, just add your repository into composer.json as follows:

"repositories": [
   {
     "type": "vcs",
     "url": "https://github.com/your-github-username/torophp"
   }
]

Important: Do not change the "require" part, it must continue using torophp/torophp!

After adding the "repositories" part, run a composer update (or composer.phar update) and composer will then download your fork (even though it echoes "installing torophp/torophp" during the operation).


Update (18.09.2014): As mentioned by @efesaid in the comments:

If your package is published on packagist, you need to add --prefer-source option to force installation from VCS.


Note: For those having issues with pulling from the HTTP(S) source (ie you get [RuntimeException] Failed to clone https://github.com/your-github-username/torophp, could not read packages from it when trying to update), you can change the composer.json to use the git protocol instead. To do so, change the composer.json as follows and run composer update again.
"repositories": [
   {
     "type": "git",
     "url": "git://github.com/your-github-username/torophp.git"
   }
]

Now go into vendor/torophp/torophp and run git remote -v for a double check that you use the desired source for the repository.

From there you can commit the changes to your fork and update it from origin (git pull origin master).


Update: To work with private repositories at GitHub, you must use git protocol and also must have installed SSH keys for a git client.

Composer reference: Loading a package from a VCS repository



来源:https://stackoverflow.com/questions/14636936/change-composer-git-source-for-a-package

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