Force composer to download git repo instead of zip - php

I have some problem with composer.
"require": {
"php": ">=5.3.2",
"kriswallsmith/buzz": "0.7"
},
Repo https://github.com/kriswallsmith/Buzz/tree/v0.7
Unfortunately github returns 502 for this request https://github.com/kriswallsmith/Buzz/zipball/v0.7
Request URL:https://nodeload.github.com/kriswallsmith/Buzz/zipball/v0.7
Status Code: 502 Bad Gateway
Luckily git clone still works ;)
Is it possible to tell/ask composer to user git clone instead of downloading zipball for this one dependency?

The quickest solution is to run install or update with the option --prefer-source
php composer.phar install --prefer-source
In this way git clone will be used for all dependencies, I don't know if there's a setting to limit to one dependency only.

As explained in preferred-install order matters. I've tested on Composer version 1.8.3 2019-01-30 08:31:33
"config": {
"preferred-install": {
"drupal/external_entities": "source",
"*": "dist"
}
}
Next ran
composer require drupal/external_entities
and the git repo appeared.

There's another way than prefer source, you can set repository with type 'VCS' it means that that package will be search in your VCS for example GIT instead of packagist
your composer.json
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/kriswallsmith/Buzz"
}
],
"require": {
"kriswallsmith/buzz": "dev-0.17.x"
}
}
More info here

Related

Package a forked composer through packagist

I want to fork this Git repo and submit a private package through Packagist.
I forked the package, cloned it on my local machine, and changed a couple of lines without adding or installing any extra dependencies. Super vanilla.
Now comes the confusing part: I’m not sure what to do with composer.json.
I edit my package name at the top of composer.json and submit it to Packagist. However, when I try to build it, it says that the build is not a stable version.
Here's my forked git repo
The composer.json from the Git repo have the following.
(Just a shorten version of the composer.json.)
"require": {
"php": "^7.3.0",
"ext-json": "*"
},
"require-dev": {
"cboden/ratchet": "^0.4.2",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/seankndy/reactphp-sqlite"
}
From the guide in a YouTube video that I saw, usually, they have the Git repo in the require dictionary.
Which steps am I missing? Thank you so much for your time.

composer install --prefer-source does not work

I have a problem.I want to tell you with code.
Problem : composer install --prefer-source
Official Definition :will install the packages from their source which is usually a GitHub or a Subversion repository. In other words, it clones the package's source. In the case where the repository is not found on the vcs, it falls back to the installation from dist.
it is okey.no problem.
my composer.json is
{
"name": "root/composer",
"require": {
"blabla/url": "dev-master",
"monolog/monolog": "^1.23"
},
"repositories" : [
{
"type" : "vcs",
"url" : "blabla/url"
}
]
}
this is my composer.json file.The following code is run on terminal
composer install
Cloning repository blabla/url on git is SUCCESSFULL!!!
Packagist for 'blabla/url' is available.
but is not same with git repository
the above code worked for git repository.
Now..I change my composer.json file.
{
"name": "root/composer",
"require": {
"blabla/url": "dev-master",
"monolog/monolog": "^1.23"
}
}
this is my composer.json file.The following code is run on terminal.
composer install --prefer-source
this code worked for packagist,does not work for git repository
but Do not you need to upload it via git repository?
What is problem?

Modify files in /vendor directory and commit changes to composer.lock?

I had to modify a vendor package (avatarguru/mustache-l5), which was not compatible with the latest version of Laravel 5 (dev) framework. But now when I do composer status in the project's root directory, it shows No local changes. I also tried to modify some other packages - same thing...
How do I commit that changes to composer.lock, so that other developers will not have to fix same packages again?
You should fork the package, create a custom repo with your changes - then include that in your composer.json.
{
"repositories": [ {
"type": "vcs",
"url": "https://github.com/YourGithubUsername/PackageName"
}
}],
"require": {
"laravel/framework": "4.0.*",
"OriginalVendor/PackageName": "1.0.*"
},
}
That way you can pull your custom changes in anytime, without having to commit it to your specific project.
You can read more about forking and loading packages here: https://getcomposer.org/doc/05-repositories.md#vcs

Change Composer git source for a package

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?
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

Composer does not fetch dependencies from local repository

I am trying to add a local project A as dependency to project B. Using git daemon I am able to fetch project A as dependency, but the dependencies defined with require in the composer.json in project A are not recognized. What am I missing?
project A:
{
"name": "project/a",
"require": {
"monolog/monolog": "dev-master"
}
}
project B:
"repositories": [
{
"type": "vcs",
"url": "git://localhost/home/user/project-a"
}
],
"require": {
"project/a": "dev-master"
}
result (in project B):
vendor/
project/a
expected:
vendor/
project/a
monolog/monolog
The most likely explanation is that you forgot to commit the changes to your composer.json in /home/user/project-a.
To debug this you can use composer show project-a dev-master -v. The -v will output more verbose info while it loads the repository, and then you will see details about the version you are installing, if it does not contain the monolog require, then I would say my guess above was correct. If it does contain it, we got a serious bug in composer and you should report it on github.
I encountered a similar issue and my issue was that I was running composer update instead of composer install and one of the libraries that I required defined some of its dependencies as zipballs from GitHub.

Categories