If I want to create a module inside the vendor folder, what are the git commands to create a subtree (or somehting else)?
Scenario:
I update the module
Push it to github
My colleague wants the update too, should he pull from github, or just update composer?
Then he has to make his own changes and push them too github
I tried some solutions but I felt like they where not the best, how does everybody else do this?
Scenario:
I want to override some view files from an existing module and create my own module for this (yes it has to be a module), extending from the original module
Do I need extra steps for this? And a separate composer package?
How can my colleague install this module and make some changes?
If you want the module to be accessible to everybody the easiest way to do this is to create a composer package for it. Then you just add it to the composer.json file and you can both use the package just by doing a composer update.
Remember to tie the git repository to packagist (through webhooks, when you create the packagist package you will see instructions), so each time you update git, an update to packagist will be available.
To push an update the module just browse to that particular path and do a commit / push to git like any other package.
If you do not want to create a packagist package, then you can always create a repository like this in composer.json Use PHP composer to clone git repo.
Related
I've added a third party library to my application using composer and it is a submodule. I want this submodule to be available to my parent git repository so that I can push it to my git repo. How can this be done? I want to preserver the current submodule so that I can continue to stay updated with that library.
You should add the vendor folder to your .gitignore file:
echo "vendor/" >> .gitignore
I do not completely understand why you want to use submodules, but my educated guess is that you don't need them for anything you want to do with your application and the library you are importing with Composer. Ignoring the vendor folder will make git to not mention any repositories checked out inside it as possible submodules.
Do commit your composer.lock file, and also avoid depending on branches of any library: Use tagged versions.
I'm using Symfony2 and for my projects I normally do composer require name/repository which will install the repository in the vendor folder and add a line in the composer.json including the package and the installed version.
Supposing that I fork a project because I want to add something to it or fix a bug and use it in my Symfony app, I'd have to run composer require myname/repository, modify it, test it and then submit a pull request. Afterwards, after the pull has been commit to the original repository, I'll have to delete my own and remove it from composer.json and reinstall the original repository.
Is there a better workflow to this that doesn't have to change the json file that much?
I have a project here that's a large Symfony2 app, I'm looking to introduce git submodules to components we're building here in-house. The issue here is that each component also requires composer packages for itself to function properly and now I have composer packages for the symfony2 app and composer packages needed for the component and I'm unsure how to handle/setup these dependencies here.
At the moment I'm manually running 'composer install' for each component (git submodule) we add, implying that each component has its own 'vendor' folder, this is far from ideal so I'm coming to Stack to get come good advice on how to keep these 'symfony composer dependencies' and 'component composer dependencies' easily maintainable.
I don't need to make sure the version of the symfony2 app's deps are synchronised with the components deps, i just need to make it simple and maintainable without having to run 'composer update' with each git submodule we setup.
Thanks!
EDIT
I'm now using composer's repositories key to define URL's to my companies private github repos. I'm able to pull in a singular private repo, lets call it Repo A. However when I add Repo B and make Repo A require Repo B it doesn't resolve properly.
composer.json for Repo A (user-reporting-component): https://gist.github.com/dragoonis/6ea92e062762c516baea
Composer.json for Repo B (database-component): https://gist.github.com/dragoonis/e54b47b75a79b82ebaea
The following error message occurs: https://gist.github.com/dragoonis/d79cd2c2dd5cc50bcd2a
The package of opinurate/database-component does exist as it's one of the repos defined in the respositories key.
Conclusion
The end solution here was to use Satis to setup what is your own private version of 'packagist' what will work alongside packagist.
I setup Satis at 'http://packages.mydomain.com' and added a 'repositories' key in my main apps composer.json file to that URL. Now when evaluating package names it will use your own custom satis server to give you git URL's too.
I would say your best bet is to add those components via composer as opposed to git submodules. It makes coding and maintenance a bit more complex, but it ensures that your application is aware for all the actual dependencies.
If you don't want them to be public and want an easier way to handle them, then i would roll out a Satis deploy locally and register them all there, adding that satis repo to your composer.json.
Satis is a simpler version of Packagist, as long as the server with it, and the machines that run composer install have access to your private repositories, nothing else will see them. There is documentation on the Composer website at: https://getcomposer.org/doc/articles/handling-private-packages-with-satis.md
You will then setup packages.yourcompany.com and add it to your composer.json as an alternate source of packages. Everything stays private.
Reply to Edit:
This is happening because composer compartimentalizes, which means the "repository" is only known to your project's composer.json, the one in Repo A does not know, so it cannot find it. You must re-define the repository in that one. Even using Satis the "satis" address must be added to all composer.json files involved.
Add the "repository" stuff you added in your app to the composer.json in Repo A and B, it should work it all out.
I think this maybe sounds a bit similar to what you want to do, so I thought I'd post the link in case was helpful and you hadn't already seen it How do I use a Git submodule with a Composer loaded library?
You should use a .gitignore file containing something like that:
web/bundles/
app/cache/*
app/logs/*
app/sessions/*
build/
vendor
When developing you should launch php composer.phar update from time to time. When your work is validated, you should commit the composer.lock file with your development.
When deploying, you can then just launch php composer.phar install.
I use composer to install FOSUserBundle in Symfony2, I can't add the bundle to my project git repository.
I found in FOSUserBundle there has a .git directory and has its own config.
When I use git add -A always get "commit or discard the untracked or modified content in submodules".
Can you help to show how to add this bundle to my repository?
Thanks in advance.
You could do something like this:
$ git add vendor/path/to/Bundle/*
You could also create a git submodule of the User Bundle in the src/FOS/UserBundle/ directory.
git submodule add <git#github ...> src/FOS/UserBundle
If you are going to do this you shouldn't use composer to install this dependency.
BUT Before you start adding third party bundles to your own repository ask the following questions:
Do you need to modify/extend the default functionality of the Bundle?
Do you need to fix a bug in the code?
Do you need to re-write big chunks of the original code to fit your specific use case?
If your answer to #1 is yes:
You want to take a look at these resources
How to use Bundle Inheritance to Override parts of a Bundle.
How to Override any Part of a Bundle.
The code you end up with will sit on top of the user bundle and it can go in your own repository.
If your answer to #2 is yes:
Make sure it is really a bug (read the docs).
Create an issue on github.
Create a fork from the original repo.
Fix the bug in your fork.
Submit a pull request.
See more information in the Contributing to a project section, and the Contribute Code for Symfony for general guidelines on how to contribute to projects.
If your answer to #3 is yes:
Create your own fork of the user bundle and work with that. Add the fork to your own project as a sub-module or create a packagist package that can be installed via composer.
The reason why the bundle is not added is because of .gitignore file that exempts 'vendor' folder , where all the bundles resides.
What you can do is push new 'composer.json' file with bundle information.
And from the server pull the new composer and do 'composer.phar update'
I want to reuse a bundle, eg: Company/CommonBundle
So what I need to know is how to turn a bundle created with 'php app/console generate:bundle', into a vendor bundle, installable through Composer, and versioned with git.
There seems to be a convention for vendors names, eg: 'monolog/monolog/src/Monolog'. Is there a guide for that?
You can use satis for that. I have never used it myself but I have been told by Stof (himself!) that it is the way to go if you want to have some sort of private composer repository.
All right I figured this out
1) uninstall the newly created bundle and move it somewhere else
2) create a git or hg repository for it, commit and push
3) add the dependency to your project, in composer.json
4) run 'composer update nothing'
That's it. Composer downloaded the repository, so you can modify it as needed, commit/push and make it available to all your other projects by following 3) and 4). If the bundle is already installed, you update it like this: 'composer update mybundle'. Enjoy.
Now all I need to figure out is how to have the bundle auto-added to AppKernel.php, etc. If you find how to do this, please share it.