I've got some packages host on the Gitlab of my company. I want to request a specific version of these packages but each time I try, composer download the latest commit of the master branch.
composer.json :
{ "name" : "MyProject", "require" : { "user/project" : "v0.5.0" }, "type" : "project", "repositories" : [ { "url" : "[email protected]:user/project.git", "type" : "vcs" } ], "config" : { "vendor-dir" : "private/class" } }
The structure of the repository of my package :
When I execute "composer install" :
Loading composer repositories with package information
Installing dependencies (including require-dev)
Analyzed 69 packages to resolve dependencies
Analyzed 67 rules to resolve dependencies
Installing user/project (dev-master f15600a)
Cloning f15600a1
It downloads the last commit only.
How can I configure the composer.json file of my project to use a specific tag ?
Create Git Tag. In order to create a new tag, you have to use the “git tag” command and specify the tag name that you want to create. As an example, let's say that you want to create a new tag on the latest commit of your master branch. To achieve that, execute the “git tag” command and specify the tagname.
You will have to explicitly push tags to a shared server after you have created them. This process is just like sharing remote branches — you can run git push origin <tagname> . If you have a lot of tags that you want to push up at once, you can also use the --tags option to the git push command.
Find Latest Git Tag Available In order to find the latest Git tag available on your repository, you have to use the “git describe” command with the “–tags” option. This way, you will be presented with the tag that is associated with the latest commit of your current checked out branch.
Technically you can tag the content of a single file without it's file name. But such tags are of limited use. Tags are expected to point to commits, and special tags to non-commits have very different behavior (you can't git checkout such a special tag). So I strongly suggest to never use non-commit tags.
How to require a specific Git tag?
Change the version requirement to dev-master
, followed by a hash #
and the Git tag name, e.g. v0.5.0
, like so:
"require": { "vendor/package": "dev-master#v0.5.0" }
How to require a specific Git commit?
Change the version requirement to dev-master
, followed by a hash #
and the Git commit reference, e.g. dd6ed3c8
, like so:
"require": { "vendor/package": "dev-master#dd6ed3c8" }
Referencing: https://getcomposer.org/doc/04-schema.md#package-links
Define your own package and set version and reference
An alternative to working with repositories of "type": "vcs"
is to define a custom package "type": "package"
inside repositories and work with a reference.
The reference is either a Git commit hash, or a tag or branch name, like origin/master
.
This will tie the version
to a specific commit reference
, in this case dd6ed3c8.
"repositories": [ # ... { "type": "package", "package": { "name": "vendor/package", "version": "v0.5.0", "source": { "url": "[email protected]:vendor/project.git", "type": "git", "reference": "dd6ed3c8" } } } ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With