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

前端 未结 5 1153
一个人的身影
一个人的身影 2021-01-31 01:47

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 c

相关标签:
5条回答
  • 2021-01-31 02:26

    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.

    0 讨论(0)
  • 2021-01-31 02:32

    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.

    0 讨论(0)
  • 2021-01-31 02:40

    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" }
    
    0 讨论(0)
  • 2021-01-31 02:41

    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.

    0 讨论(0)
  • 2021-01-31 02:46

    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

    0 讨论(0)
提交回复
热议问题