git ignore vendor directory in Zend Framework 2 - php

All,
I have a module in "vendor" directory. I don't want to check in any contents in the vendor directory. So, I changed my .gitIgnore file like this:
nbproject
._*
.~lock.*
.buildpath
.DS_Store
.idea
.project
.settings
composer.lock
vendor
But, git is still recognizing the vendor directory as modified and asking me to check it in.
How do I fix this?
Thanks

You should add directories to your .gitignore directory followed by a "/".
tim#roflcopter ~/htdocs/laravel $ cat .gitignore | grep vendor/
vendor/

Related

How to configure "Directories" when using a Symfony project in PhpStorm

I use PhpStorm to work on a Symfony project.
In the File > Settings > Project … > Directories configuration, I defined the vendor/ directory as a Resource root in order to have auto-completion and as an Excluded folder because I want to ignore vendors when performing a search in my project's code.
But my problem is that vendors are still shown in search results.
Here is my current configuration:
Here is what I'm trying to avoid: results from vendor/ are shown:
Here is the PHP configuration:
I can restrict search by selecting Scope = Custom but sometimes I forget to change this. I'm looking for some settings that I can use in my different Symfony2/3 projects.
How should I mark the vendor/ directory in order to allow PhpStorm to use it as a resource root and ignore it when performing a search?
And what is the correct configuration for the default directories structure of a Symfony2 project? Here are the default directories after a Symfony 2.8 installation with composer create-project symfony/framework-standard-edition symfony-2.8 "~2.8":
app/
├ config
├ cache
├ logs
└ Resources
src/
└ AppBundle/
vendor/
web/
Here is how I marked the directories at this moment:
.idea [excluded]
app/
├ config
├ cache [excluded]
├ logs [excluded]
└ Resources
src/ [source]
└ AppBundle/
└ Tests/ [test source folders]
vendor/ [excluded]
web/
Note: I installed the Symfony plugin for PhpStorm, I don't know if this change the IDE behaviour.
The vendor folder is not a resource root. A resource root is a folder where resources such as images and scripts will be served from by the web server.
In your case the only folder that should be marked as a resource root is probably the web folder, but ironically, is almost the only one you haven't selected as a resource root. Marking web as the resource root means that the absolute URLs /css/foo.css and /images/foo.jpg could be valid resources served by the web server; you probably want to remove all other folders from resource roots.
It is correct to exclude the vendor folder because it is not part of your first-party project code. In order for code completion to work for third-party code you must add the vendor folder as an external library. This can be done by navigating to Languages & Frameworks > PHP in the options and specifying the vendor folder as an include path.
After having used advices from Quolonel Questions's answer, here is a summary of my configuration for Symfony2 (see Symfony3 at the end of this answer):
For auto-completion, use the vendor/ directory in Include path:
In order to avoid irrelevant results when searching in the project, the following directories have to be ignored:
.idea [excluded]
app/
├ cache [excluded]
└ logs [excluded]
vendor/ [excluded]
Here is my full configuration:
.idea [excluded]
app/
├ cache [excluded]
└ logs [excluded]
src/ [source]
└ AppBundle/
└ */Tests/ [test source folders]
vendor/ [excluded]
web/ [resources root]
Test Source Folders are optional, if they are defined the will appear in the toolbar:
With the default configuration for Symfony3, the directories are slightly different:
.idea [excluded]
src/ [source]
tests/ [test source folders]
var/
├ cache [excluded]
└ logs [excluded]
vendor/ [excluded]
web/ [resources root]
Update: after updating my dependencies with composer update, PhpStorm perform searches in the vendor/ directory, even if these directories are ignored. The solution is to remove all the vendor/* directories from Include path and keep only vendor/ directory, as on the first screenshot.
I'll have to test if marking all the vendor/* directories as ignored can work and avoid to repeat this after each time composer update is used.
Another option which is easier than manually excluding vendor and then including it again in php settings, is to tell PhpStorm about composer.json and composer.phar in the composer settings as showin in this question.
I use PhpStorm 10 as my primary IDE for Symfony2. You don't need to install any Symfony plugins, because PhpStorm support Symfony2 by default.
Your should mark your public_html directory as a Resource Root, or whatever you have that is going to be public
Sources - your app/ directory
If you don't want vendors/ in search, that's what I exclude also, you press on vendor and "Excluded" button on the top. You also want to exclude, tmp/ and app/cache/ directories
As you already know, you can define scope and search there.
When you exclude directory, it also helps performance since PhpStorm not indexing and watching files there, something you don't want anyway.
As for directory structure of Symfony2, it's pretty flexible, I use my own. Here is Symfony 2.8 directory structure from the docs.
Excluded folders for me are:
app/DoctrineMigrations
app/cache
app/logs/
tmp/

How can i change to location where composer creates the vendor folder

I have project's folder dummyProject and inside of it two folders, src and test, and composer.json file. Problem is when i run the composer install command the vendor folder being created in the dummyProject folder. How can i tell composer to create the vendor folder inside src?? thx..
According to the following: https://groups.google.com/forum/#!topic/composer-dev/CS_I0FNMHwY
You can set a Vendor Path like so:
{
"config": {
"vendor-dir": "libs/"
}
}
Looking at this question How to get multiple vendor directories with composer?, it appears you cannot set two different paths for vendor files (not sure if you will need to do this also), but the questions shows that with a symlnk this can be achieved.
Also see the following regarding changing the vendor location:
How to specify Composer install path?

Does Laravel 4 have to be in the root directory?

I'm just playing around with Laravel and Composer, and I wanted to know if I can change where Laravel is located, but still be able to run composer in the root? The root folder is getting really busy with node_modules, bower_components, docs, bin, all my .*rc files, compass.rb, gruntfile.js, bower.js, composer.json, and package.json.
I was hoping I could dump Laravel into its own folder, but still be able to use composer.json to handle dependencies without having to change directories, so I can do all my CLI commands for grunt, bower, and composer at the same level.
Thinking of something very similar to .bowerrc where I can dictate where bower.json and bower components get stored.
Something like, but allow CLI in root for everything:
/root
.git
/bin
/bower
/components
bower.json
/config
/docs
/laravel
everything laravel instead of in root
composer.json? or out in root?
/node_modules
/sql
db.sql
gruntfile.js
package.json
.gitignore
.gitattributes
all .*rc files x 6, such as: .bowerrc, .jshintrc, etc
README.md
LICENSE.md
Yes. Just change the path of the auto-loader in bootstrap/autoload.php.

Remove files when downloading a dependency with composer

I am sure I once read it somewhere but I cannot find it anymore anywhere, DAMN!
So basically what I am trying to do is to specify some exclusion criteria in my composer.json file for a certain library of mine so that, when used as a dependency of a project, the importing project does not get test files, .git folders, READ.md files and all that stuff (totally useless when you only want a library as a dependency and not for development).
So basically I am trying to lighten up my libs when they are downloaded as dependencies. Anyone on that?
Ta
You can add a .gitattributes file to your project root, looking something like this:
/Tests export-ignore
READ.md export-ignore
When someone installs your dependency this files will be excluded from the distribution zip.
There are some prerequisites for your lib to be downloaded as a zip by composer
You need to have a stable tagged version. dev-master will always be cloned by composer.
If the user installs with composer install --prefer-source composer will also clone from your git repo.
In all other cases composer will download the zip and all the files in .gitattributes will be excluded from it.
Hope this helps.
If you're on a unix-like system, you can do this in one cmd, simply cd to vendor dir and :
find . -type d -regextype posix-egrep -regex ".*\/(tests?|docs?|\.git)" -exec rm -rf {} \;
adapt the regex to your needs
find cmd:
http://unixhelp.ed.ac.uk/CGI/man-cgi?find
regards

Using Git with your CakePHP Project

I use git as my primary version control system, and have recently started using git on my CakePHP projects. This is my current .gitignore file:
app/tmp
vendors/
As used in the cakephp git repo, but this causes a bit more work for me when deploying the project to a server, because I have to go in and create all the app/tmp/ sub-directories by hand before they will work correctly. Is there a way to set it up to ignore the contents on these folders, but to still have them under git control so they appear when I clone the repo into the hoted directory?
I also have been having an issue with my git index being reset while I am working on it, which is causing me to have to do a lot more commits than should be necessary, any ideas on that also?
Git stores only files, not directories, so you can for example add a hidden file into that directory and commit it.
Remove app/tmp/ from .gitignore
touch app/tmp/.keep
git add app/tmp/.keep
git commit
Add app/tmp/ to .gitignore
As mentioned git only stores files, not directories. By default cake's .gitignore file ignores all contents in the tmp folder to prevent tmp files being added to your repository.
You can (and should) however do this after you create a project:
cd /my/app
git add -f tmp
which will do this:
$ git status
# On branch master
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: tmp/cache/models/empty
# new file: tmp/cache/persistent/empty
# new file: tmp/cache/views/empty
# new file: tmp/logs/empty
# new file: tmp/sessions/empty
# new file: tmp/tests/empty
As such your tmp folder structure is ready to be committed, but all other files in your tmp dir will (continue to) be ignored.
My .gitignore file.
tmp/*
[Cc]onfig/core.php
[Cc]onfig/database.php
webroot/files/
webroot/img/photos/
!empty
.DS_Store
If you'll notice I have !empty which saves me from creating .keep files all over which is so SVN ago. Lastly you'll also see that I use this config for both cakePHP 1.x and 2.x projects noted by the [Cc]. I have some folders setup that I store user files in so I always ignore them as well. Finally the .DS_Store ignores my MAC created thumbnail views for my project.

Categories