Article

Composer & Git Branch Names - A Doh! Moment

It was one of those moments of clarity followed quickly by a doh! from everyone.

We were trying to include a branch of one of our Symfony bundles in our project using composer but composer refused to see the branch.  We checked the repository and the branch was definitely there so we could not understand why composer was not able to check out the branch.

To include the branch were were trying:-

[digital@devserver devsite]$ php composer.phar require htg/pagination-bundle:v2

(any eagle-eyed people able to spot the issue yet?)

And the response we were getting was 

./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

 Problem 1
   - The requested package htg/pagination-bundle v2 could not be found.
 Problem 2
   - Installation request for symfony/framework-standard-edition 2.4.x-dev -> satisfiable by symfony/framework-standard-edition[2.4.x-dev].
   - symfony/framework-standard-edition 2.4.x-dev requires htg/pagination-bundle v2 -> no matching package found.

Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
  see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

Installation failed, reverting ./composer.json to its original content.

To try and isolate the problem we used added the verbose (-v) flag to get more information and we then got

[digital@devserver devsite]$ php composer.phar require htg/pagination-bundle:v2 -v
./composer.json has been updated
Loading composer repositories with package information
Reading composer.json of htg/pagination-bundle (master)
Importing branch master (dev-master)
Reading composer.json of htg/pagination-bundle (v2)
Importing branch v2 (2.x-dev)
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

 Problem 1
   - The requested package htg/pagination-bundle v2 could not be found.
 Problem 2
   - Installation request for symfony/framework-standard-edition 2.4.x-dev -> satisfiable by symfony/framework-standard-edition[2.4.x-dev].
   - symfony/framework-standard-edition 2.4.x-dev requires htg/pagination-bundle v2 -> no matching package found.

Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
  see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

Installation failed, reverting ./composer.json to its original content.

We then realise that v2 was getting interpreted as 2.x-dev but that wasn't our branch name.  When we updated our require to be 

[digital@devserver devsite]$ php composer.phar require htg/pagination-bundle:2.x-dev

we got 

Reading composer.json of htg/pagination-bundle (master)
Importing branch master (dev-master)
Reading composer.json of htg/pagination-bundle (v2)
Importing branch v2 (2.x-dev)
Updating dependencies (including require-dev)
 - Updating htg/pagination-bundle (dev-master 8a58d14 => 2.x-dev fc90e71)
   Checking out fc90e719c3e227fb20330d9dd80c2d5814772a63

children-593313_1280.jpg

Conclusion

You can have a branch name of v[number] but composer will treat it as a version number and try and checkout [number].x-dev instead.  Our bundle was not ready to be a 2.0 but was more like a 0.2 as we were trying out an experimental code change and more consideration should have been given to the branch name.

Lesson learned though!

 
me.jpeg

I am a web developer specialising in web driven applications using PHP, MySQL, Symfony and Zend and I am currently working for the The Drum in Glasgow, Scotland.

Most days I can be found frantically coding away with EuroDance in my ears and consuming what I hope to be a never ending supply of coffee... happy days!

Want more like this?

Keep up-to-date with latest news from Inside the Agency using any of the following services

Advertisement

Digital Ocean

Chris's Reading List

www.thoughtworks.com

BFF @ SoundCloud

Our friends at SoundCloud embarked on a journey a few years ago that changed their system and moved it from a monolithic Rails application towards an ecosystem of microservices. Read more

The Drum

The Drum

Google'€™s AMP is bringing some much needed speed to mobile but the transition won'€™t be easy for publishers

A week after launching, the Google-led Accelerated Mobile Pages (AMP) initiative has raised more questions than answers for publishers... Read more

SitePoint

SitePoint

Quick Tip: How to Permanently Change SQL Mode in MySQL

MySQL 5.7 introduced some awkward changes for older codebases and tends to break apps. Here's how to temporarily (or permanently) lower the strictness level Read more

SitePoint

SitePoint

How to Build Your Own Dependency Injection Container

Andrew Carter builds a Dependency Injection container from scratch, showing you how that rocket science is really just fireworks strapped to lego figures! Read more

AuthorityLabs

AuthorityLabs

13 Reasons Your Organic Traffic is in Decline | It's Not a Penalty

The landscape of search engine optimization has changed drastically in the last 3-4 years. Even as it changes, a lot stays the same. It has been very challenging to see a multitude of friends and colleagues approach me with problems that often seem beyond repair with clients that they have worked with for years. Read more

TechCrunch

TechCrunch

WordPress Sites Now Support Google’s AMP To Make Mobile Pages Load Much Faster

Google has some big plans when it comes to making the web faster on your mobile phone. The company just added AMP-enabled pages in its mobile search results... Read more