From b10b76cc4f663338736e0b90760fb0bf4f5c2383 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 20 Sep 2024 16:48:42 -0500 Subject: [PATCH] Specifically handle offline case in `pr_init()` I realised that we're checking whether or not the host is online further down, so we might as well use that a little earlier to give a more informative message. --- R/pr.R | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/R/pr.R b/R/pr.R index c486d37b7..0995f3870 100644 --- a/R/pr.R +++ b/R/pr.R @@ -167,30 +167,41 @@ pr_init <- function(branch) { cfg <- github_remote_config(github_get = NA) check_for_bad_config(cfg) tr <- target_repo(cfg, ask = FALSE) + online <- is_online(tr$host) - maybe_good_configs <- c("maybe_ours_or_theirs", "maybe_fork") - if (cfg$type %in% maybe_good_configs) { + if (!online) { ui_bullets(c( - "x" = 'Unable to confirm the GitHub remote configuration is - "pull request ready".', - "i" = "You probably need to configure a personal access token for - {.val {tr$host}}.", - "i" = "See {.run usethis::gh_token_help()} for help with that.", - "i" = "(Or maybe we're just offline?)" + "x" = "You are not currently online.", + "i" = "You can still create a local branch, but you won't be able to setup + or push to the remote branch." )) - if (ui_github_remote_config_wat(cfg)) { + if (ui_nah("Do you want to continue?")) { ui_bullets(c("x" = "Cancelling.")) return(invisible()) } + } else { + maybe_good_configs <- c("maybe_ours_or_theirs", "maybe_fork") + if (cfg$type %in% maybe_good_configs) { + ui_bullets(c( + "x" = 'Unable to confirm the GitHub remote configuration is + "pull request ready".', + "i" = "You probably need to configure a personal access token for + {.val {tr$host}}.", + "i" = "See {.run usethis::gh_token_help()} for help with that.", + )) + if (ui_github_remote_config_wat(cfg)) { + ui_bullets(c("x" = "Cancelling.")) + return(invisible()) + } + } } - default_branch <- git_default_branch() + default_branch <- if (online) git_default_branch() else guess_local_default_branch() challenge_non_default_branch( "Are you sure you want to create a PR branch based on a non-default branch?", default_branch = default_branch ) - online <- is_online(tr$host) if (online) { # this is not pr_pull_source_override() because: # a) we may NOT be on default branch (although we probably are) @@ -213,10 +224,6 @@ pr_init <- function(branch) { ui_bullets(c("v" = "Pulling changes from {.val {remref}}.")) git_pull(remref = remref, verbose = FALSE) } - } else { - ui_bullets(c( - "!" = "Unable to pull changes for current branch, since we are offline." - )) } ui_bullets(c("v" = "Creating and switching to local branch {.val {branch}}."))