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
451 views
in Technique[技术] by (71.8m points)

php - Composer and multiple branches

I have a git project with 2 branches:

  • Master: Currently the "stable branch" but subjected to changed. Releases are tagged from there.
  • Devel: A development branch for the next version. This is merged into master when we think some features from here are quite stable.

In master, I have a requirement in my composer.json that uses a specific version:

"require" : {
    "triagens/arangodb" : "1.2.1",
    "php" : ">=5.4.0"
},

In my devel branch, I would like to use the development version of the dependency:

"require" : {
    "triagens/arangodb" : "dev-devel",
    "php" : ">=5.4.0"
},

Effectively, when branches are switched, and composer install or composer update is run I would like to have composer update/change the dependencies to the appropriate versions.

Since composer install --dev does not support having a different version of a dependency in require-dev, I cannot set the different version in the require-dev section.

I would also prefer to not have a separate composer.json for each branch as merge would be quite painful.

If you have multiple branches and each branch uses some version of a dependency, what's the best way to do this?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You can maintain multiple versions of composer.json under different names:

  • composer.master.json
  • composer.dev.json

Then when you call composer.phar install or composer.phar update, you can preface the desired composer file to use:

  • COMPOSER=composer.master.json php composer.phar update
  • COMPOSER=composer.dev.json php composer.phar update

See the CLI docs.


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

...