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:-

[[email protected] 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 <https://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

[[email protected] 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 <https://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 

[[email protected] 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!

Chris's Reading List

Medium

Medium

How a single change boosted organic traffic by 40%

How a single change boosted organic traffic by 40%

The SEO world can sometimes be a confusing maze of contradictions. Read more

verraes.net

verraes.net

Sensible Interfaces

Sensible Interfaces

How did we get from 'Program to an interface, not to an implementation' to 'Just slap an interface on there, it's the fashionable thing to do'? Read more

Moz

Moz

The Linkbait Bump: How Viral Content Creates Long-Term Lift in Organic Traffic - Whiteboard Friday

The Linkbait Bump: How Viral Content Creates Long-Term Lift in Organic Traffic - Whiteboard Friday

A fantastic piece of content can lift your traffic curves to a "new normal." In today's Whiteboard Friday, Rand talks about exactly how that happens, and how you can create content that has that effect. Read more

Loige

Loige

6 Rules of thumb to build blazing fast web applications (server side)

6 Rules of thumb to build blazing fast web applications (server side)

In this post are described 6 extremely important rules you should take under consideration when writing your next web application Read more

SitePoint

SitePoint

Console Wars - PHP CLI Libraries

Console Wars - PHP CLI Libraries

Nicola Pietroluongo compares three popular PHP console libraries, building the same functionality in each. Wondering which one is right for you? Find out! Read more

TechCrunch

TechCrunch

Servers.com Brings Its Bare-Metal Servers To The US

Servers.com Brings Its Bare-Metal Servers To The US

Servers.com, a hosting company with a focus on dedicated bare-metal servers that launched in Europe in 2005, today announced the opening of its first U.S... Read more

Advertisement

Digital Ocean