3

I'm trying to develop a PHP library (called foo/bar) using Composer in dir /work/a with the composer.json contents:

{
    "name": "foo/bar",
    "require": {
        "php": ">=7.2"
    }
}

/work/a is a git project and I'm on the branch mybranch

I'm trying to use this lib in another project locally (called testing/foobar) using Composer in dir work/b with the composer.json contents:

{
    "name": "testing/foobar",
    "type": "project",
    "repositories": [
        {
            "type": "vcs",
            "url": "/work/a"
        }
    ],
    "require": {
        "php": "^7.4",
        "foo/bar": "mybranch"
    }
}

When running $ composer install in /work/b I get the error:

[UnexpectedValueException]                                            
  Could not parse version constraint mybranch: Invalid version string "mybranch"  
Catfish
  • 18,876
  • 54
  • 209
  • 353
  • I think that the error message shown does not match the composer.json that you provide... – yivi Mar 19 '20 at 09:02
  • You're right. I updated for a simple example, but forgot to update the error message. Updated now. – Catfish Mar 19 '20 at 15:35

1 Answers1

7

You have to prefix your branch name with dev-, so your branch name will have to be dev-mybranch.

Loading a package from a VCS repository

...
In composer.json, you should prefix your custom branch name with "dev-".
...

Also check this Q/A "Composer require branch name".

Change branch name to have dev- prefix, add it to /work/b project:

{
    "name": "testing/foobar",
    "type": "project",
    "repositories": [
        {
          "type": "vcs",
          "url": "/work/a"
        }
    ],
    "require": {
        "php": "^7.4",
        "foo/bar": "dev-mybranch"
    }
}

Run composer install:

❯ composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing foo/bar (dev-mybranch 85c97b7): Cloning 85c97b7b23 from cache
Writing lock file
Generating autoload files
Community
  • 1
  • 1
Christos Lytras
  • 36,310
  • 4
  • 80
  • 113
  • 1
    Doh! I completely missed the part that the branch name HAS to specifically be `dev-`. I'm coming from rubygems/maven/npm where testing libs locally is similar, but different. – Catfish Mar 23 '20 at 17:59