简体   繁体   中英

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

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

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" }

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.

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.

I think the best answer is to leave minimum-stability at stable.

"minimum-stability" : "stable"

Then in "require" section, specify "dev-master@dev"

"require" : {
  "ResistFascism" : "dev-master@dev"
}

Or you can do what I do and don't use master, but rather create my own branches. So instead of running the ResistFascism package from the master branch, specify a dev branch in your composer.json.

"require" : {
  "ResistFascism" : "~1.2.1@dev"
}

I like to keep all of my external packages on stable versions, because that's what I run in production, but I manage my own packages often on dev versions. But you can use master too. It's personal preference.

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

To download the latest version of a repo, I usually use:

composer update behat/mink-selenium2-driver

This will update your composer.lock with the last available commit reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM