How do I get Composer to download the latest commit in the master branch from GitHub for a package?

PhpGitGithubComposer Php

Php Problem Overview


I am trying to get Composer do download the latest commit for the Behat/MinkSelenium2Driver package. That particular repo only has a master branch. I have tried every method I can think of, including deleting the files and letting it pull them back in, to get it to work but it doesn't.

How would I get it to pull in latest committed files or at least those from the commit I list below?

Specifically I want to get this commit: https://github.com/Behat/MinkSelenium2Driver/commit/2e73d8134ec8526b6e742f05c146fec2d5e1b8d6

Thanks, Patrick

Php Solutions


Solution 1 - Php

There is only one way to grab the head of the repository:

"require": { "behat/mink-selenium2-driver" : "dev-master" }
"minimum-stability": "dev"

Oh well, at least two ways:

"require": { "behat/mink-selenium2-driver" : "dev-master as 1.1.x-dev" }
"minimum-stability": "dev"

Probably at least three ways:

"require": { "behat/mink-selenium2-driver" : "dev-master#2e73d8134ec8526b6e742f05c146fec2d5e1b8d6" }
"minimum-stability": "dev"

Because that repository actually aliased the master branch as 1.1.x-dev, this would also work without the minimum-stability affecting all other packages:

"require": { "behat/mink-selenium2-driver" : "1.1.*@dev" }

Solution 2 - Php

Simply specify the master branch:

composer require --dev behat/mink-selenium2-driver:dev-master

PS: the --dev is just to specify it's a test/development requirement, that's probably what you want.

Solution 3 - Php

In our case, none of the previous answers were working. It turned out to be something simple:

Composer only uses the repositories attribute of the ROOT composer.json

https://getcomposer.org/doc/04-schema.md#repositories

In our case, we were trying to get the latest commit from dev-master of one of our transitive dependencies. There was some problem with the hooks between github and packagist preventing it from working like normal and it took us a couple hours to realize that we were editing the wrong composer.json (the one from our library that carries the dependency) instead of the top-level composer.json that we were installing.

Solution 4 - Php

For my case, all the 03 suggested solutions above from @Sven didn't work. This was my solution in case someone still struggling on a similar context.

  • remove existing usage if you have it composer remove the_vendor/the_package_name

  • If you have access to the package repo, create a 1st tag for it (eg: 0.1.0)

git tag --annotate 0.1.0 --message "Initial version 0.1.0" 
git push origin 0.1.0

Note: Each time you update your package repo, pls attribute a new tag (eg: 0.1.1) & make composer update the_vendor/the_package_name on main app to update the composer.lock

  • If you don't have access to the package repo, pick existing tag version (not dev-master)

  • require it from main app composer require the_vendor/the_package_name:^0.1

from master

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
QuestionPatrickView Question on Stackoverflow
Solution 1 - PhpSvenView Answer on Stackoverflow
Solution 2 - PhpBerend de BoerView Answer on Stackoverflow
Solution 3 - PhplmsurprenantView Answer on Stackoverflow
Solution 4 - Php4givNView Answer on Stackoverflow