Drupal-project: Remove .git folder from modules and themes development branches

Created on 30 Nov 2016  ·  10Comments  ·  Source: drupal-composer/drupal-project

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?

Most helpful comment

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.

All 10 comments

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.

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.

@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?

Quick question what workflow is 'ideal' in regards custom modules /
themes. most shops / projects in the past just keep everything in one
huge repo. With divesting of contrib libraries / projects, is it better
to keep those custom projects in smaller repos with a central one that
references them via composer or ?

On 12/1/16 4:43 PM, Niels de Feyter wrote:
>

@PatrickBauer https://github.com/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 https://github.com/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 https://github.com/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?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/drupal-composer/drupal-project/issues/223#issuecomment-264112780,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACA0jSPElbfgBwzb0OWCQixCReIJzd6Wks5rDoiYgaJpZM4LAMOE.

@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.

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.

The snippet looks good, thanks for sharing. 👍

Thank you :) :+1: using ....

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.

:+1:

Was this page helpful?
0 / 5 - 0 ratings