When I run composer install --prefer-source or try to update this one particular bundle ( others work well ) I get this error:
Failed to download some-bundle from source: Failed to execute git checkout 'xx' -- && git reset --hard 'xx' --
error: The following untracked working tree files would be overwritten by checkout:
...
[ list of all files in repo on a branch that interests me ]
...
Please move or remove them before you can switch branches.
Aborting
I'm assuming I messed up something on the bundle repository, but have no idea what.
I clone brand new project repository
I try "composer install --prefer source" and still get that error.
What is interesting - the error occurs only on docker on MAC. On other pc with linux it works fine.
It looks like you have manually updated the sources in your vendor directory of this bundle.
If so, try to commit/push or reset them directly in the vendor directory before updating the package.
If not, it may relates to this issue: https://github.com/composer/composer/issues/2896
The author writes:
"This can be fixed in two ways:
when stashing, add --include-untracked flag which will stash newly added files as well.
when checking out, add --force flag which will overwrite files instead of aborting."
If nothing helps you can manually delete the vendor directory to force composer to newly install the package.
Edit Please take also a look at https://getcomposer.org/doc/03-cli.md#clear-cache, maybe composer has cached the git repository somewhere and cannot update it.
Related
I am trying to ask the question as precisely as possible but I myself have lots of confusion about this. So please bear with me
Problem - We have a third party API (Recurly) installed in our site. That site was built with Laravel. The version of that API is now outdated and I want to update the version via composer.
From the Recurly I have got the following instruction to upgrade the version
In composer.json file update the line of code from "recurly/recurly-client": "2.8." to "recurly/recurly-client": "2.12. . And this will upgrade your client library AND your API version.
Once you do this, please run a composer update in your terminal->active directory w/ Recurly and it will update you:
I have updated the line inside composer.json file. But I dont understand the second part of the instruction. How to run a composer update. Shall I update the composer itself? But I want to update the Recurly API version. is it necessary to update the composer itself?
I have found this link: https://getcomposer.org/doc/03-cli.md#update-u
In this link its written
In order to get the latest versions of the dependencies and to update the composer.lock file, you should use the update command. This command is also aliased as upgrade as it does the same as upgrade does if you are thinking of apt-get or similar package managers.
php composer.phar update
I am not sure Is this the command I need?
Our webserver is with AWS. And we have WHM and cPanel installed to manage the web server.
I understand my question is not not precise as expected . but I cant figure out where to start actually. Please suggest me accordingly
As composer update command can create additional problem to the server hence i have run composer update only for Recurly as a root
composer update recurly/recurly-client
It is important to run the command from the directory where the composer.lock and composer.json files are
for an example if you have several sites under your server and if you run the command as root it may affect other sites as well.
To prevent that first you have to run
cd /home/websitefolder
then
composer update recurly/recurly-client
This way you can update only single package and it will not affect the rest of your site
There are two approaches to solving your problem,
Option A
as was stated, go to your composer.json and update the line
go to Terminal at the cpanel, should you not have terminal, use option 2
cd into your directory and run php composer update, (please before doing this, make sure to have a copy of your composer.json and the lock files.
Option B (No Terminal at cpanel)
Zip your directory and download
copy the file after unzipping to your wamp/xamp directory
edit the composer.json
and run php composer update (things can break here, I think the best is to run composer install rather than update)
zip and upload the file back.
I believe that should solve the problem
There are some frameworks like laravel which recommend installation using create-project.
It would be hard to update projects like this through composer, because
The composer create-project creates the skeleton with all initial
routes in your configuration etc.
From the very very first moment you are starting to change the default
routes, removing the default controllers and changing the default
views, your project would be out of sync. because meanwhile laravel
changes the skeleton to newer versions with some new default routes
etc or event changes directory structure.
However, I've recently seen that phpmyadmin recommends composer create-project as a possible installation method.
As phpmyadmin does not simply provide some skeleton files to be modified by the user, but a complete, finished web-app, I'd like to know what's the best way to update a phpmyadmin installation created like that?
I don't know whether there is an official way to do this.
According to the docs, create-project is the equivalent of:
doing a git clone/svn checkout followed by a composer install of the vendors.
If you haven't modified any of the files, I think the easiest way would be to just delete the directory and run composer create-project again.
If you have modified some of the files, you could do a git merge (if the project uses git) and run composer update again.
If you haven't yet created the project, you could run create-project with the --keep-vcs flag and then every time you want to update it, you can cd to the project and run:
git pull origin <version>
composer update
If you have already installed the project without --keep-vcs, then you'll have to make the directory a git repository and then add the project's repository as remote. To find the project's repository, search for it on Packagist. For example, for phpmyadmin:
cd phpmyadmin
git init
git add .
git commit -m "Add initial files"
git remote add git#github.com:phpmyadmin/composer.git
git pull origin <version> --allow-unrelated-histories -Xtheirs
composer update
Some of your changes might be lost with the above git pull though so make a backup (and maybe research other ways to merge unrelated histories).
I have two PC: A laptop and a desktop computer.
I was working two weeks on my Symfony 3 project with the desktop computer, and I defined some new parameters on my parameters.yml.dist
Today, I need to use my laptop, so I did a pull from my origin branch, and then I executed the following command to update my project:
php composer.phar update
This command updated successfully my project (parameters and vendor directory). With this, I can now run my project.
The problem is that now when I run:
git status
Lots of modified files appear in the vendor directory. Also composer.lockfile apperars, and I think that this is correct, but not the vendor files.
My .gitignorecontains, among others, the following line:
vendor/*
What I did wrong? And how can I solve it?
The problem is probably twofold.
You probably have checked in files from the vendor directory before adding it to the gitignore or maybe you accidentally added them with the --force flag which ignores the gitignore.
The other big problem is that you ran composer update this will not only install the dependencies in your composer.lock it will actually update them, meaning you might get different versions then the ones you were developing with before. Next time you should probably run composer install (even on a system where you already have vendors installed). This will do as advertised it will install all dependencies as defined in the composer.lock. Whenever you checkout a newer version of that file the install command will automatically update your local vendors to the versions defined there. This ensures that you always work with the same dependency versions.
Should you want to update your dependencies you might want to do it one by one using composer update <dependency-name> this will then again update your composer.lock which you should have checked into git.
In your case you might want to remove the vendor folder, but make sure you keep your composer.lock. Now you can commit this change to make sure you remove all checked in files vendor/. After that, your .gitignore should work again and running composer install should re-install everything as defined in the composer.lock and you should not see any changes in your work dir when running git status. If there are you might have to tweak your .gitignore, e.g. try /vendor instead of vendor/*.
I need to discus a very important thing for me (probably for all users who uses composer in their projects). I am working on laravel. Whenever i work on my local machine, i run composer update after adding new library in vendor.
Now it works fine on local machine. But when i upload these files on my server, it shoots error like "Undefine class ....". I dont know how to run composer update command on server (Also it might be not safe).
So may i just know which files are updated by using composer update on cmd. What other files needed to go live to avoid this error??
You may:
Run composer update on your local server only, whenever you want.
Commit/push every files (including composer.lock) but the vendor directory
Deliver to your production server (without vendor, with composer.lock)
Then run composer install on your production server. It will update all your dependencies according to your composer.lock(so the exact same versions as your last update on your local server).
So in other words: you should not run composer update on your server, just composer install on every delivery (and you will need to keep your composer.lock)
Hope it will help you.
run composer dump-autoload before composer update. If still doesn't work then try to clear composer cache using composer clear-cache
composer update will update the version of every package from you vendor folder.
normally if you can not ensure you need update all the version of every package, you should use composer install
the reason of error "undefined class" is normally caused from app.php.Because service provider is defined in app.php, but the class(package) not been installed.
in order to solve your problem, try do this in three ways:
composer install --no-scripts;
comment the service providers which not been installed already from app.php, then composer install
composer dump-autoload
When creating sites using a framework like Silverstripe I often want to use helper modules like gridfieldextensions and lumberjack.
I therefore use composer require to add the dependencies.
However when I follow my regular development work flow and use git add -A to add the module to the repo rather than the code being added to the repo I get a reference to it.
This causes problems when I then try to clone the site elsewhere (using Jenkins or another developer). The git clone or git pull leaves an empty directory.
I solve this by deleting the .git dir of the module and adding all the files.
Is there a better way to do this? Is using git submodule an option?
Somewhere i found a good .gitignore file that ignores everything and i have to tell it to include the custom modules for my project. It's like:
# ignore everything...
/*
# ...but
!/.htaccess
!/.gitignore
!/composer.json
!/composer.lock
!/Capfile
!/Gemfile
!/favicon.ico
!/touch-icon-*
!/mysite
!/some-module
#...other modules
# theme stuff
!/themes/
**/.sass-cache
**/node_modules
!**/node_modules/_manifest_exclude
#no assets in general, but /assets/.htaccess
!/assets
/assets/*
!assets/.htaccess
As FinBoWa already said you need the composer.json and composer.lock file in your project and running
composer install
on another machine it'll install the packages in the versions saved in the composer.lock file on that machine
composer install --no-dev
will only install the "normal" requirements, no dev-requirements like phpunit or other stuff you only need for developing or testing but not live
composer install --no-dev -o
will also optimize (-o) the auto loader, so it'll be a bit faster.
composer update
will update your packages, which might have funny side effects and break your site. So use it carefully and test afterwards.
composer update silverstripe/framework
will just update that package and finally
composer update silverstripe/*
will update all packages by the vendor silverstripe (e.g. framework and cms package)
See also:
gitignore documentation
composer documentation