neubert
neubert

Reputation: 16792

how to install the latest version in a branch with composer?

Say I'm trying to install a package that has a 1.0 branch and a master branch. The 1.0 branch has tags like 1.0.1, 1.0.2, etc.

What I want to be able to do is to install the latest version in the branch. I don't want to install a tagged release - I want to install the latest branch version.

Here's what I tried:

composer require package/package:1.0

composer require package/package:~1.0

Both of those got the most recent 1.0.* tag but not the latest in the 1.0 branch.

Is what I'm trying to do even possible?

For that matter what even is the difference between 1.0 and ~1.0?

Upvotes: 6

Views: 7365

Answers (1)

jbafford
jbafford

Reputation: 5668

You can require dev-master as the version name (or dev-branchName), and it will pull in the most recent commit from the specified branch. For versioned branch names, use e.g. 2.0.x-dev as the version name instead.

(More details are available on the Schema - package links section of the Composer documentation.)

The difference between 1.0 and ~1.0 is that 1.0 specifies a specific version number, and ~1.0 specifies that any version "compatible" (according to semantic versioning) with 1.0 is allowed. From the Composer documentation:

The ~ operator is best explained by example: ~1.2 is equivalent to >=1.2 <2.0.0, while ~1.2.3 is equivalent to >=1.2.3 <1.3.0.

There is also the similar ^ operator: ^1.2.3 is equivalent to >=1.2.3 <2.0.0.

Upvotes: 6

Related Questions