Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add support for alternative default branches in GitHub #508

@ha0ye

Description

@ha0ye

remotes::install_github() assumes that the default branch is named "master", which is not always the case, e.g.

remotes::install_github("elizagrames/litsearchr")
#> Using github PAT from envvar GITHUB_PAT
#> Downloading GitHub repo elizagrames/litsearchr@master
#> Error in utils::download.file(url, path, method = method, quiet = quiet,  : 
#>   cannot open URL 'https://api.github.com/repos/elizagrames/litsearchr/tarball/master'

Created on 2020-06-13 by the reprex package (v0.3.0)

The GitHub API notes a default_branch field that could provide this information, e.g.:

remotes:::github_GET("repos/elizagrames/litsearchr")$default_branch
#> [1] "main"

Created on 2020-06-13 by the reprex package (v0.3.0)

So, I think this can be a drop-in for the default value for the ref argument in install_github. Some additional re-factoring might be needed if we wanted to bundle the GitHub API calls.

Note, to my knowledge, this issue was first reported by @elizagrames on twitter, and we chatted about a potential fix before writing up this issue. We're happy to work on a PR to this, and look into propagating the solution to other install_* functions, if so desired.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions