Home > Enterprise >  Avoiding .git folder in composer's vendor when installing from a custom Gitlab domain
Avoiding .git folder in composer's vendor when installing from a custom Gitlab domain

Time:01-21

I have a Symfony bundle on a git repository managed by GitLab. The bundle is added to Symfony using composer and pointing to the gitlab as an additionnal repository.

Everything works fine, the dependency is tracked perfectly and the bundle does work as expected however, in order to optimize my project sources I would like to avoid including the .git folder in the vendor/my-org/my-bundle directory.

Here is a sample of the composer.json of the Symfony project:

{
    [...]
    "require": {
        [...]
        "my-org/my-bundle": "dev-master"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://mygitlab.mysite.com/author/my-bundle.git"
        }
    ]
}

and the composer.json of the bundle :

{
    "name": "my-org/my-bundle",
    "type": "symfony-bundle",
    "description": "blabla",
    "keywords": ["symfony", "bundle"],
    "license": "MIT",
    "authors": [
        {
            "name": "ME Myself",
            "role": "Developper"
        }
    ],
    "readme": "README.md",
    "require": {
        "php": ">=7.1.3",
        "symfony/security-bundle": "4.4.*",
        "symfony/config": "4.4.*",
        "symfony/dependency-injection": "4.4.*",
        "symfony/http-foundation": "4.4.*",
        "symfony/http-kernel": "4.4.*",
        "symfony/routing": "4.4.*",
        "symfony/event-dispatcher": "4.4.*",
        "symfony/property-access": "4.4.*",
        "symfony/ldap": "4.4.*",
        "psr/log": "^1|^2|^3"
    },
    "require-dev": {
        "phpunit/phpunit": "^7"
    },
    "suggest": {
        "symfony/phpunit-bridge": "^5.2"
    },
    "autoload": {
        "psr-4": {
            "Foo\\Bar\\": "src/Foo/Bar/"
        }
    }
}

Additionnal informations :

  • I tried to set the repository type (in the project composer to gitlab/github) but both are missing the driver ; only git works.
  • I tried the command composer install --prefer-dist with no more success (.git still included).
  • composer version : 2.1.6
  • the user UI download zip/tar/... button of the gitlab provide an archive not including the .git/.gitignore.

CodePudding user response:

Your domain is not being recognized as a GitLab domain, and then the package is simply cloned out of the Git repository.

You should configure your domain as being a GitLab domain so Composer knows to use the Gtlab API.

Unless you configure other domains, only gitlab.com is considered a GitLab domain.

https://getcomposer.org/doc/06-config.md#gitlab-domains

The configuration should go within config.gitlab-domains, as far as I can see. Something like

{
    "config": {
       "gitlab-domains": [
         "mygitlab.mysite.com"
       ]
   }
}

  •  Tags:  
  • Related