Download Composer dependencies from version control

Problem to solve

When downloading Composer dependencies, you have two options. You can use source or dist. For stable versions, Composer will use the dist by default. The source is a version control repository, like your GitLab Project. If --prefer-source is enabled, Composer will install from source as a git clone instead of downloading a packaged zip file. This is useful if you want to make a bugfix to a project and get a local git clone of the dependency directly.

The problem is that until recently, you could not use the prefer-source and preferred-install commands and configurations when downloading Composer dependencies. This prevented many of you from using the GitLab Package Registry for your Composer dependencies.

Proposal

Add support for prefer-source and preferred-install so that PHP Developers can configure Composer to download packages from git instead of as a zip file.

Steps to reproduce

  1. Create a project in a group.
  2. Enable the Packages feature if not already enabled.
  3. Make sure the project has a valid composer.json:
{
  "name": "m4rw3r/composer-test-project",
  "description": "Composer test project for prefer-source install",
  "license": "MIT"
}
  1. Publish the package using curl: curl --data branch=master 'https://__token__:<token>@gitlab.com/api/v4/projects/21057249/packages/composer.
  2. Create a new folder and add the following to a composer.json:
{
  "repositories": [
    {"type":"composer","url":"https://gitlab.com/api/v4/group/9281167/-/packages/composer/packages.json"}
  ],
  "require": {
    "m4rw3r/composer-test-project": "dev-master"
  }
}
  1. Attempt to install the package using composer install -vvv --prefer-source.

The package will install successfully, but not from source. In the log produced it will list that it is downloading the package as a zip-file instead of checking out a clone, despite --prefer-source being specified.

Example Project

https://gitlab.com/test-group321/composer-test-project

Edited by Tim Rizzi