"master" branch is hard-wired into `bs4_book()`
https://github.com/rstudio/bookdown/blob/7ce6dc65b39ffe846e2ff88c160a69f2348a5a92/R/bs4_book.R#L401
This affects the links for "View source" and "Edit this page". In almost all cases, after a master --> main move, I expect the automatic redirects to kick in. But it would still be nice to correct the actual links.
There may very well be a way to override this (I haven't worked backwards from tweak_navbar() to see if I eventually get to some config file), but it would be nice if the default were either "main" or (harder) inferred from the repo.
The specific example I am staring at is https://r-pkgs.org. Update: I am now using config to specify that the underlying repo uses "main" as the default branch, ~but so far this has not had the desired effect. Still troubleshooting. I've invalidated the cache. At this point, I think it's a netlify problem, also related to master --> main.~ The bookdown config is working as advertised, I was overlooking a place where "master" was hard-wired into our GHA build and deploy job.
OK yeah I see that this is configurable, so I think the action item here might be to make "main" the fallback instead of "master".
Given the repo's URL it is, of course, possible to determine the default branch. But from a brief look around, I don't see dependencies that suggest bookdown already makes this sort of call to the GitHub API (or other Git host). So that is a bigger ask.
Reference: https://bookdown.org/yihui/bookdown/html.html#specifying-the-repository
As you found, since recently, it is configurable. if you are using main, you need to branch option in repo field.
so I think the action item here might be to make "main" the fallback instead of "master".
We could indeed change the default to main in
https://github.com/rstudio/bookdown/blob/7ce6dc65b39ffe846e2ff88c160a69f2348a5a92/R/bs4_book.R#L401
it makes sense as any new project on Github would use this. (but Git still use master as default right ?).
However, this would break all current book that build with bs4_book() and still use master as default branch. They would need to configure the branch option (or make the switch master --> main. Some we know about e.g mastering shiny but probably other we don't know about.
We could add a message to warn about the change for some time. But either way, some users would need to make the configuration: the current main users, or the previous master users if we make the change.
Given the repo's URL it is, of course, possible to determine the default branch. But from a brief look around, I don't see dependencies that suggest bookdown already makes this sort of call to the GitHub API (or other Git host). So that is a bigger ask.
bs4_book() already use specific dependencies that we use in Suggests and we could add more. However, I don't think there is anything else in bookdown requiring an access to Github. If we were to make a call to Github API or website, we would need to make sure that it does not error when the a book is build in an offline environment.
Another thoughts is that the call would be make at each build - that is maybe too much. It could be as easy to advice users to set the configuration once and for all. Something like: "We didn't see a branch configured, we are using main. Please set branch configuration to correct branch name."
Not sure there is a best solution as long as the too default branch exist. And also now that users / orgs can change default branch - but that must be rare.
I don't think it's worth the trouble to detect the current project's default branch. It's not something that changes often.
I think the only question is whether the baked-in default should be "master" or "main". Or perhaps nothing at all, i.e. this must be configured. Which is partially a matter of "what causes the least fuss now? how about in the long term?" and partially about the implicit opinion it expresses.
Is there a fix for this? Issue thread #1220 suggests that the problem was solved in a later release of bookdown but it's not working for me after adding branch: main to _output.yml
output:
bookdown::bs4_book:
repo:
base: https://github.com/[account]/[repo]
branch: main
and it's not currently working for R4DS either:
@jtr13 this has indeed been fixed in #1036.
R4DS modified the config 4 days ago: https://github.com/hadley/r4ds/commit/f795a9a584bb1c8ef3f489c020171884e1ca7376 as they have started working on the second edition. The edit link are correct in the new version https://r4ds.hadley.nz/
I think the first version (https://r4ds.had.co.nz/) has not been rebuild from some time.
it's not working for me after adding branch: main to _output.yml
Do you have a repo to share ? It is working in our tests, and on my side, as in R4DS as explain above. Probably something else interfering.
Regarding this specific issue, master is still the default and you need to configure main as you did.
Thanks a lot. Mine is working now (https://1201.info/). Maybe I didn't sufficiently wait for GitHub Pages to update. My apologies.