composer install --prefer-source does not work - php

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?

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.

Installation via composer: multiple git remotes and pathspec error during feature branch checkout

I am installing our PHP application with composer and linked git repositories. After installation, the cloned repositories have two git remotes configured, 'composer' and 'origin'.
composer.json
"require": {
[...]
"mycompany/myrepository": "dev-master",
},
[...]
"repositories": [
{
"type": "vcs",
"url": "git#bitbucket.org:mycompany/myrepository.git"
},
Right after composer completed the installation:
$> git remote show
composer
origin
When I want to switch to any available feature branch on the repository, it fails with a git error.
$> git fetch && git checkout branchname
error: pathspec 'branchname' did not match any file(s) known to git.
When I delete the git remote 'composer', it works fine but that isn't very scalable/efficient.
$> git remote rm composer
What might be wrong in my composer.json or the way I want to achieve this?
Edit:
The composer.json has been created based on https://getcomposer.org/doc/01-basic-usage.md at the time - if I start fresh and only require a single module, no dependencies etc, and then do a compser create-project, the outcome is identical: both remotes "composer" and "origin" are available.
Update:
I tried doing the same with a single git public repo monolog/monolog based on composer documentation and it resulted in the same two remotes present.
Testcase from scratch:
{
"require": {
"monolog/monolog": "dev-master"
},
"require-dev": {
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/Seldaek/monolog"
}
]
}
$ composer create-project
$ cd vendor/monolog/monolog
$ git remote show
composer
origin
Run git branch -a to see which branches you have.
It should look something like
* master
remotes/origin/master
remotes/origin/branchname
remotes/composer/master
If there is no local branch branchname you can
git fetch origin
git checkout --track origin/branchname
to track the branchname from origin.

custom symfony2 bundle installation with composer from private bitbucket repository

I'm desperately trying to install my Symfony Bundle via composer. I did following things:
created a bitbucket git repo in the root folder of the bundle (SymfonyProject/src/My/Bundle)
created a composer.json file:
{
"name": "my/bundle",
"description": "my desc",
"type" : "symfony-bundle",
"require": {
"foreign/bundle": "dev-master"
},
"license": "proprietary",
"authors": [
{
"name": "Me",
"email": "me#mycompany.com"
}
],
"minimum-stability": "dev",
"autoload": {
"psr-0": { "My\\Bundle\\": "" }
},
"target-dir" : "My/Bundle"
}
then i've created a testproject and added following to composer.json in the symfony root:
"require" : {
"my/bundle" : "dev-master"
},
"repositories" : [
"type" : "vcs",
"url" : "https://myusername:password#bitbucket.org/mycompany/myrepo.git"
]
i call composer update my/bundle -vvv and get the following output (uninteresting stuff is removed):
Loading composer repositories with package information
Executing command (CWD): git clone --mirror 'https://username:****#bitbucket.org/mycompany/myrepo.git'
'/home/myname/.composer/cache/vcs/https---repocachedir/'
Executing command (/home/myname/.composer/cache/vcs/https---repocachedir/): git show-ref --tags
Executing command (/home/myname/.composer/cache/vcs/https---repocachedir/): git branch --no-color --no-abbrev -v
Executing command (/home/myname/.composer/cache/vcs/https---repocachedir/): git branch --no-color
Executing command (/home/myname/.composer/cache/vcs/https---repocachedir/): git show 'master':composer.json
Executing command (/home/myname/.composer/cache/vcs/https---repocachedir/): git log -1 --format=%at 'master'
Reading composer.json of my/bundle (master)
Reading /home/myname/.composer/cache/vcs/https---repocachedir/09esdfsdfdb74ce0998ddsdfsd59028969b8edef35f872 from cache
**Importing branch master (dev-master)**
Downloading https://packagist.org/packages.json
The last output is "importing branch master" which is right, isnt it? After that the packagist stuff is fetched. Composer install wont work either, package will not be installed. What am I doing wrong?
If somebody could enlighten me, i would be very pleased!!!
I have a similar setup working using type "git".
Also it looks like it using a cached version?
Could this be empty?
It can be found and removed from (from Composer docs):
"Defaults to $home/cache on unix systems and C:\Users\\AppData\Local\Composer on Windows."

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

Force composer to download git repo instead of zip

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

Categories