Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove .git folder from modules and themes development branches #223

Closed
ndf opened this issue Nov 30, 2016 · 11 comments
Closed

Remove .git folder from modules and themes development branches #223

ndf opened this issue Nov 30, 2016 · 11 comments

Comments

@ndf
Copy link

ndf commented Nov 30, 2016

When requiring a development branch of a Drupal module or theme, the repository will be downloaded as git repository.

Example
composer require drupal/paragraphs:1.x-dev
composer install
Result
web/modules/contrib/paragraphs/.git/...
web/modules/contrib/paragraphs/paragraphs.info.yml

Can we add a post-install-cmd and post-update-cmd event that removes these .git folders?

@PatrickBauer
Copy link

Actually you shouldn't commit these contrib modules (thats why they are inside the .gitignore). If you really need them, you could implement a post-update-command for your project, but I don't think it should be the default.

@fafnirical
Copy link

fafnirical commented Nov 30, 2016

Unfortunately, some hosting providers (like Acquia) seem to require git deployments. Because of the git metadata, those packages can't be added for the deployment, even with git add --force.

For our Composer-managed, Acquia-hosted projects, we're removing the folders only on our CI server.

@ndf
Copy link
Author

ndf commented Dec 1, 2016

@PatrickBauer Ah your right. I noticed this in a project where we deviated from the default behaviour and actually committed all composer dependencies.

That case looks like @fafnirical with Acquia, because a Composer deployment isn't supported.
We remove the .git directories for submodules manually before committing.

So I am with @PatrickBauer that this feature-request should not be default.
Additionally; if we do create this feature, I guess it should be extended to all composer dependencies, not limited the drupal modules/themes.

How do you think about this?

@cmcintosh
Copy link

cmcintosh commented Dec 1, 2016 via email

@ndf
Copy link
Author

ndf commented Dec 6, 2016

@cmcintosh Hard to say if there is an 'ideal' workflow. But I guess it is safe to say that a lot of projects are moving from 'one big file dump' (ftp) to 'big file dump in version control' (git) to 'only saving meta-data about dependencies'.

In Drupal-land the latter was previously managed with 'drush make', and that is going towards 'composer'.
In JS-land this is done with NPM and in Ruby-land with Bundler.

A big plus for this workflow is that the dependency-management tool (composer, npm, bundler) takes care of updating your dependencies and patches. It makes maintenance easier when a project evolves.

In reality, as @fafnirical said, not all hosting providers support all workflows. So that is something to consider too.

@tanc
Copy link

tanc commented Dec 12, 2016

We're currently wedded to a monolithic repo method so to handle development modules with git directories we just remove them with an additional function in scripts/composer/ScriptHandler.php

  public static function removeGitDirectories() {
    $root = static::getDrupalRoot(getcwd());
    exec('find ' . $root . ' -name \'.git\' | xargs rm -rf');
  }

This gets called in our composer.json in post-install-cmd and post-update-cmd

"post-install-cmd": [
    "DrupalProject\\composer\\ScriptHandler::createRequiredFiles",
    "DrupalProject\\composer\\ScriptHandler::removeGitDirectories"
],
"post-update-cmd": [
    "DrupalProject\\composer\\ScriptHandler::createRequiredFiles",
    "DrupalProject\\composer\\ScriptHandler::removeGitDirectories"
]

It's a bit brutal but it works. One side effect is that when you composer update a development module it will complain but you can just hit return to force update it.

@webflo
Copy link
Member

webflo commented Jan 30, 2017

The snippet looks good, thanks for sharing. 👍

@webflo webflo closed this as completed Jan 30, 2017
@Natshah
Copy link

Natshah commented Aug 8, 2017

Thank you :) 👍 using ....

@weitzman
Copy link
Contributor

weitzman commented Aug 8, 2017

One side effect is that when you composer update a development module it will complain but you can just hit return to force update it.

Another way to bypass that warning is to add --no-interaction option.

@mqanneh
Copy link

mqanneh commented Nov 22, 2017

👍

@mohammadzo
Copy link

You do not need to create a function and call it to remove the .git folder.
simply add the following

  "scripts": {
            "post-install-cmd": [
                "@composer drupal-scaffold",
                "find docroot vendor -name '.git' | xargs rm -rf",
                "find docroot vendor -name '.github' | xargs rm -rf"
            ],
            "post-update-cmd": [
                "@composer drupal-scaffold",
                "find docroot vendor -name '.git' | xargs rm -rf",
                "find docroot vendor -name '.github' | xargs rm -rf"
            ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants