Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make composer NOT create a .git directory for a package

Tags:

I found a couple related posts, but those don't really answer my question. Let's say I want to install this package: https://github.com/pear/Net_Socket

an excerpt from my composer.json:

{     "config": {         "preferred-install": "dist"     },     "repositories": [         {             "type": "vcs",             "url": "https://github.com/pear/Net_Socket.git"         }     ],     "require": {         "pear/net_socket": "*",     } } 

So I need it to be installed without the .git directory so it is not seen as a submodule in my project. How do I make it download a "dist" version, like others said? Do I have to tag a commit?

like image 654
A. Sallai Avatar asked Sep 22 '14 18:09

A. Sallai


People also ask

Can I remove the .GIT folder?

Command line Git repository delete Just run the rm command with the -f and -r switch to recursively remove the . git folder and all of the files and folders it contains.

Is .GIT folder necessary?

A . git folder is required to log every commit history and every other information required for your remote repository, version control, commits etc. These things are saved in different folders which have different meanings. Once the folder is created, open it and see the contents of the folder.

How do I change my Git repository to normal folder?

Just delete . git directory and it will be all. Actually, as far as a file manager (windows file explorer or nautilus etc) is concerned, a git repo is just a directory.


2 Answers

If a package is seen as a git submodule, you haven't excluded the vendor folder from being committed to your own repository. It is recommended to add the vendor folder to .gitignore, and not commit these files, only commit composer.lock (and composer.json of course).

Apart from that, running composer install --prefer-dist should do the job. Note that Composer seems to not change the download method used first if you change your mind later. If Composer detects a cloned repo, it is faster to just update that instead of downloading a ZIP and unpacking it. If you want to change that, delete the whole vendor folder and run composer update --prefer-dist.

like image 153
Sven Avatar answered Sep 24 '22 05:09

Sven


Using --prefer-dist is the only native solution, but there will be situations where there is simply no packaged version available, and in those cases Composer will still fall back to git clones.

The only workaround I know of is to run a cleanup script after composer install that removes Git directories. Maybe a command like this:

find . -type d | grep .git | xargs rm -rf 

Be careful to run this in your vendor directory, not your root directory.

like image 23
Dane Powell Avatar answered Sep 22 '22 05:09

Dane Powell