Skip to content
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

Where possible, use existing github config to determine default branch #2062

Merged
merged 2 commits into from
Oct 2, 2024

Conversation

hadley
Copy link
Member

@hadley hadley commented Sep 20, 2024

Fixes #2021

Copy link
Member Author

@hadley hadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a more surgical approach to getting the speed up that I'm looking for. Hopefully you agree!

Comment on lines -98 to -102
# TODO: often when we call git_default_branch(), we already have a GitHub
# configuration or target repo, as produced by github_remote_config() or
# target_repo(). In that case, we don't need to start from scratch as we do
# here. But I'm not sure it's worth adding complexity to allow passing this
# data in.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted because that's what I did 😄

Comment on lines -104 to -121
# TODO: this critique feels somewhat mis-placed, i.e. it brings up a general
# concern about a repo's config (or the user's permissions and creds)
# related to whether github_remotes() should be as silent as it is about
# 404s
critique_remote <- function(remote) {
if (remote$is_configured && is.na(remote$default_branch)) {
ui_bullets(c(
"x" = "The {.val {remote$name}} remote is configured, but we can't
determine its default branch.",
" " = "Possible reasons:",
"*" = "The remote repo no longer exists, suggesting the local remote
should be deleted.",
"*" = "We are offline or that specific Git server is down.",
"*" = "You don't have the necessary permission or something is wrong
with your credentials."
))
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted because I think it's now more clear that it's the responsibility of github_remote_config() to report such problems, and github_remote_config() is now more consistently called before git_default_branch() where it matters.

Copy link
Member Author

@hadley hadley Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also see this message in cases where it's not usage. For example, if you're offline, pr_resume() will emit this message even though you can still checkout the local branches that it lists.

@@ -61,7 +61,7 @@ use_github <- function(organisation = NULL,
visibility <- match.arg(visibility)
check_protocol(protocol)
check_uses_git()
default_branch <- git_default_branch()
default_branch <- guess_local_default_branch()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this a reasonable substitution because I can't see why origin or upstream would be setup before you're calling use_github(). Please let me know if I've forgotten some likely scenario.

@@ -237,7 +237,7 @@ pr_resume <- function(branch = NULL) {
ui_bullets(c(
"i" = "No branch specified ... looking up local branches and associated PRs."
))
default_branch <- git_default_branch()
default_branch <- guess_local_default_branch()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok to use a cheap check here because we're only using it to exclude branches, and this (along with the tweak below) allows pr_resume() to work offline.

@@ -491,11 +492,11 @@ pr_view <- function(number = NULL, target = c("source", "primary")) {
#' @export
#' @rdname pull-requests
pr_pause <- function() {
# intentionally naive selection of target repo
tr <- target_repo(github_get = FALSE, ask = FALSE)
cfg <- github_remote_config(github_get = NA)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a change, but isn't really because the call to git_default_branch() on line 498 would have used github_get = NA.

# naive selection of target repo; calling function should analyse the config
tr <- tr %||% target_repo(github_get = FALSE, ask = FALSE)

pr_pull_source_override <- function(tr, default_branch) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All callers of pr_pull_source_override() supply their arguments and I think we should continue to enforce that.

@hadley hadley changed the title Where possible use existing github config when determining default branch Where possible, use existing github config to determine default branch Sep 20, 2024
Copy link
Member

@jennybc jennybc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't spot any obvious problems, so LGTM. I think the main way we'll find out there's an issue is just through exercising it.

Comment on lines -633 to -634
# naive selection of target repo; calling function should analyse the config
tr <- tr %||% target_repo(github_get = FALSE, ask = FALSE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely remember that the only reason I had NULL default here and did this was for development convenience.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that it's worth a little development inconvenience in order to ensure that we get efficient code.

# TODO: why does this not use a check_*() function, i.e. shared helper?
# I guess to issue a specific error message?
current_branch <- git_branch()
default_branch <- default_branch %||% git_default_branch()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto for this

@hadley hadley merged commit cec49b6 into main Oct 2, 2024
13 of 14 checks passed
@hadley hadley deleted the default-branch-from-config branch October 2, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pr_ performance
2 participants