Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

How to use a specific tag/version with composer and a private git repository?

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 :

  • tag v0.5.0 : commit dd6ed3c8...
  • commit X,Y,Z
  • tag v0.7.0 : commit 15293ac6...
  • last commit f15600a1...

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 ?

question from:https://stackoverflow.com/questions/34784809/how-to-use-a-specific-tag-version-with-composer-and-a-private-git-repository

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"
      }
    }
  }
]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...