Reputation: 33368
I'm trying to get composer to use my own fork of a library.
Original: https://github.com/KnpLabs/php-github-api My Fork: https://github.com/TransitScreen/php-github-api
I was able to install the original with composer simply by adding this to composer.json:
{
"require": {
"knplabs/github-api": "~1.4"
}
}
I followed the instructions in the documentation, and changed it to this:
{
"repositories": [
{
"type": "git",
"url": "https://github.com/TransitScreen/php-github-api.git"
}
],
"require": {
"knplabs/github-api": "dev-master"
},
"minimum-stabilitiy": "dev"
}
In my forked repository I have both a master
and dev-master
branch created. It's not clear to me which is correct, so I made both. I've also tried by using "type" : "vcs"
and removing the .git
from the URL. Neither one works. I run composer update
and then the composer.lock
file still points to the original repo URL, not mine. So I never get my changes when I run composer install
.
What am I doing wrong??
PS: I've noticed that the library I'm trying to fork has this in it's composer.json file:
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
}
}
I haven't found any documentation to explain what effect the alias might have. For example, should my forked repository have a 1.4.x
branch??
Update 1
By the way, I know some of my configurations must be correct because I when run composer update
after deleting the cache, there is a moment when I see that it's reading the composer.json of my (the correct) repository. But then afterwards composer.lock still points to the original (incorrect).
Update 2
I've also tried using composer update --prefer-source
but it still doesn't work.
Upvotes: 5
Views: 690
Reputation: 33368
I figured out the problem!
I had edited the composer.json
file inside my forked repository... It looked like this:
{
"name": "knplabs/github-api",
"type": "library",
"description": "GitHub API v3 client",
"homepage": "https://github.com/TransitScreen/php-github-api",
"keywords": ["github", "gh", "api", "gist"],
"license": "MIT",
But I changed it to this:
{
"name": "transitscreen/php-github-api",
"type": "library",
"description": "GitHub API v3 client",
"homepage": "https://github.com/TransitScreen/php-github-api",
"keywords": ["github", "gh", "api", "gist"],
"license": "MIT",
I thought that the name needed to match the new repository, but I was wrong. When I changed it back to the original name, everything works!
Many thanks to @Tomas for offering useful troubleshooting tips.
I didn't see any documentation about this anywhere, so I PRed an update to the composer docs: https://github.com/composer/composer/pull/4329
Upvotes: 4
Reputation: 24280
First, try to rename your fork branch to something else (best unique and not available in the origin) and use that.
To be specific: https://github.com/TransitScreen/gh-api/tree/dev-master
dev-master
=> my-feature
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/TransitScreen/php-github-api"
}
],
"require": {
"knplabs/github-api": "newsearch"
},
"minimum-stability": "dev"
}
Upvotes: 1