-
Notifications
You must be signed in to change notification settings - Fork 337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could pkgdown have a way to detect default branch? #2597
Comments
Hmmm, I don't think we can do this generally, but I think we could optimise for the common case, looking for a branch named either main or master, and using that if present. That would cover 99% of cases, I think. |
Maybe something like this: default_branch <- function(pkg) {
if (Sys.which("git") == "") {
return("HEAD")
}
if (has_branch(pkg$src_path, "main")) {
"main"
} else if (has_branch(pkg$src_path, "master")) {
"master"
} else {
"HEAD"
}
}
has_branch <- function(repo, branch) {
withr::local_dir(repo)
tryCatch(
{
git("show-ref", paste0("refs/heads/", branch), echo = FALSE, echo_cmd = FALSE)
TRUE
},
error = function(e) {
FALSE
}
)
} |
Sounds like a good idea! |
Alternatively, we could use the REST API: https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#get-a-repository |
@maelle FWIW that code is for determining what the default branch is for new repos |
For "source" links of documentation pages
Let's say I read documentation online and spot a typo.
In the vignette for example: https://pkgdown.r-lib.org/articles/pkgdown.html
I click on the link on top to go edit the vignette
This is the one: https://github.com/r-lib/pkgdown/blob/HEAD/vignettes/pkgdown.Rmd
However, I cannot edit it easily :
I have to select the main branch on the top left corner.
If the link were https://github.com/r-lib/pkgdown/blob/main/vignettes/pkgdown.Rmd, would remove one step from the process.
usethis has
usethis:::git_default_branch()
for this. So if something similar could be called once, to create all the links, it would be awesome.I understand pkgdown doesn't have git related dependencies, but it would be possible via a system call? This would have the biggest impact on the R pkgdown ecosystem.
Worst case scenario (opt-in), but the impact would be fairly minimal across pkgdown ecosytems would be to have a way to specify what is the default branch in config?
The text was updated successfully, but these errors were encountered: