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

Questions regarding "The .git directory is missing" #8840

Closed
zomorod opened this issue Apr 27, 2020 · 13 comments
Closed

Questions regarding "The .git directory is missing" #8840

zomorod opened this issue Apr 27, 2020 · 13 comments
Labels

Comments

@zomorod
Copy link

zomorod commented Apr 27, 2020

Hi there,

I am running to the issue like the following and I like ignore or pass yes to this. I also followed the doc but did not help.

  - Updating drupal/lightning_media (3.16.0 => dev-3.x 6201bcd):     Update failed (The .git directory is missing from docroot/modules/contrib/lightning_media, see https://getcomposer.org/commit-deps for more information)
    Would you like to try reinstalling the package instead [yes]?

if I go with --no-interaction it does not pass yes and I will get the following error:

Updating drupal/lightning_media (3.16.0 => dev-3.x 6201bcd):
[RuntimeException]
The .git directory is missing from docroot/modules/contrib/lightning_media, see https://getcomposer.org/commit-deps for more information

Base on the information on https://getcomposer.org/commit-deps here is My composer.json.

My composer.json:

{
    "name": "myproject/myproject",
    "description": "My project Composer builds",
    "type": "project",
    "license": "proprietary",
    "repositories": {
        "drupal": {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        },
        "asset-packagist": {
            "type": "composer",
            "url": "https://asset-packagist.org"
        }
    },
    "require": {
        "composer/installers": "^1.2.0",
        "cweagans/composer-patches": "^1.6.5",
        "drupal-composer/drupal-scaffold": "^2.5.4",
  },
    "require-dev": {},
    "config": {
        "sort-packages": true,
        "vendor-dir": "vendor"
    },
    "conflict": {
        "drupal/core": "7.*"
    },
    "extra": {
        "enable-patching": true,
        "patches": {
        },
        "installer-types": [
            "bower-asset",
            "npm-asset"
        ],
        "installer-paths": {
            "docroot/core": [
                "type:drupal-core"
            ],
            "docroot/modules/contrib/{$name}": [
                "type:drupal-module"
            ],
            "docroot/modules/custom/{$name}": [
                "type:drupal-custom-module"
            ],
            "docroot/profiles/contrib/{$name}": [
                "type:drupal-profile"
            ],
            "docroot/profiles/custom/{$name}": [
                "type:drupal-custom-profile"
            ],
            "docroot/themes/contrib/{$name}": [
                "type:drupal-theme"
            ],
            "docroot/themes/custom/{$name}": [
                "type:drupal-custom-theme"
            ],
            "docroot/libraries/{$name}": [
                "type:drupal-library",
                "type:bower-asset",
                "type:npm-asset"
            ]
        },
        "merge-plugin": {
            "include": [
                "docroot/modules/custom/*/composer.json"
            ],
            "replace": false,
            "ignore-duplicates": true
        },
        "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"
            ],
            "drupal-scaffold": [
                "DrupalComposer\\DrupalScaffold\\Plugin::scaffold"
            ]
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

When I run this command:

composer update package/project --with-all-dependencies
@stof
Copy link
Contributor

stof commented Apr 27, 2020

This issue is caused by your post-*-cmd commands deleting .git repo. When composer installs a package from source and is then asked to update it to a different version, it expects the package to still be installed from source as a VCS repo. But here, you deleted the repo.

If you want to avoid getting such .git folders, you should configure composer to install from dist archives instead (there is no guarantee that no source install will ever happen, as it is possible for packages not to provide a dist archives, but packages hosted on github, gitlab and bitbucket have these dist archives at least).

@zomorod
Copy link
Author

zomorod commented Apr 27, 2020

Thank you,

So, Is there anyway to at lease ignore the dialogue. Like passing --yes to the command?

    Would you like to try reinstalling the package instead [yes]?

@Seldaek
Copy link
Member

Seldaek commented Apr 27, 2020

--no-interaction / -n will make it reinstall automatically by default I believe.

@zomorod
Copy link
Author

zomorod commented Apr 27, 2020

Unfortunately --no-interaction will out put it as error:

[RuntimeException]
The .git directory is missing from docroot/modules/contrib/lightning_media, see https://getcomposer.org/commit-deps for more information

It it possible to have a solution or have --yes flag?

@Seldaek
Copy link
Member

Seldaek commented Apr 27, 2020

The real solution is to install packages as dist if you don't want .git directories in them, or to just stop deleting .git directories..

@Seldaek Seldaek closed this as completed Oct 15, 2020
@klausi
Copy link

klausi commented Oct 23, 2020

The problem is that when you have a dev dependency pointing to git and then update to a dist release without git then composer install will fail with this error in Drupal projects. Even if you have --no-interaction.

This breaks production deployments and can bring sites down that have a simple composer install deploy strategy.

I think composer should self-heal in --no-interaction mode. If there is not git repository then yes of course please reinstall the package. A human would always say yes in that case.

We are still discussing if we should fix this in the Drupal .git remover script or simply make Composer more robust. Would you be willing to accept such a contribution?

@Seldaek
Copy link
Member

Seldaek commented Oct 23, 2020

Sure if it can be done reasonably and with enough safeguards in place so that it doesn't misbehave and wipe dirs when it shouldn't, I'm open to it.

@klausi
Copy link

klausi commented Nov 10, 2020

We found a solution in our case, so I think we don't need to fix Composer. We had drupal-composer/drupal-project#223 active as composer script, which removes .git folder automatically for people that want to commit the vendor folder into their own git.

We removed DrupalProject\\composer\\ScriptHandler::removeGitDirectories from our composer.json, because we don't commit the vendor folder anyway and this fixes the problem for us.

@mohammadzo
Copy link

The above does not resolve the issue. I think since the is happening in the composer update command, It should handle by composer.

I want to not have human interaction but there is not any good solution.

@stof
Copy link
Contributor

stof commented Oct 3, 2022

@mohammadzo composer never removes a .git folder after installing from source. If you remove it with another tool, it is not composer's fault. The expectation of Composer is that a package that was installed from source using composer is not partially removed from the disk when trying to use composer again to update it.

@mohammadzo
Copy link

mohammadzo commented Oct 3, 2022

@stof Correct, but the expectation is to let composer to reinstall it without human interaction.

@YahyaAhmad
Copy link

Composer should automatically hit yes, I have never answered 'no'

@YahyaAhmad
Copy link

YahyaAhmad commented Jun 19, 2023

There is another dirty solution that involves removing the entire vendor folder and then installing. But yeah, the only correct solution, for now, is to keep the '.git' folder, which is a problem because we have so many projects with the '.git removal' script which needs to be manually edited.

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

No branches or pull requests

6 participants