Composer require branch name

Google Cloud-PlatformComposer Php

Google Cloud-Platform Problem Overview


For example I want to require:

{
  "repositories": [
    {
      "type": "git",
      "url": "https://github.com/google/google-api-php-client.git"
    }
  ],

  "require": {
    "google/apiclient": "v1-master"
  }
}

In this example I try require google/apiclient on branch v1-master. I get error:

  [UnexpectedValueException]                                                        
  Could not parse version constraint v1-master: Invalid version string "v1-master"

Google Cloud-Platform Solutions


Solution 1 - Google Cloud-Platform

You need to prefix all dev branches (= non tagged) by dev-.

To install the branch you need, use:

composer require google/apiclient:dev-v1-master

See composer docs.

Solution 2 - Google Cloud-Platform

this will work :

{
  "repositories": [
	{
	  "type": "git",
	  "url": "https://github.com/google/google-api-php-client.git"
	}
  ],

  "require": {
	"google/apiclient": "dev-BRANCH_NAME"
  }
}

so pattern is "dev-*", if you branch name is "bug-fix" then "dev-bug-fix"

with command line :

composer require google/apiclient:dev-BRANCH_NAME

Solution 3 - Google Cloud-Platform

I was trying to the same for a different Google repository which contains several packages and it took me some time to figure it out. Therefore I am sharing my solution below.

My goal is to pull latest google/cloud-compute from https://github.com/googleapis/google-cloud-php.git within master branch.

Following steps worked for me:

  1. Clone the repository
git clone https://github.com/googleapis/google-cloud-php.git google-cloud-php
  1. Set composer.json to use the right package from local folder:
{
    "repositories": [
        {
            "type": "path",
            "url": "/Users/USERNAME/projects/google-cloud-php/Compute"
        }
    ],

    "require": {
        "google/cloud-compute": "dev-master"
    }
}

Please note that in step 2 the url is pointing to the Compute subfolder where the actual google/cloud-compute package exists.

My solution could be easily tweaked for any branch, you would just need to git checkout the appropriate branch in step 1 and then change 'dev-master' to 'dev-YOUR_BRANCH' in step 2.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWizardView Question on Stackoverflow
Solution 1 - Google Cloud-PlatformTomas VotrubaView Answer on Stackoverflow
Solution 2 - Google Cloud-Platformfico7489View Answer on Stackoverflow
Solution 3 - Google Cloud-PlatformRemigiusz SamborskiView Answer on Stackoverflow