From a0835db41b057d2e0b8850cc44b5ce29110d68c8 Mon Sep 17 00:00:00 2001 From: olivroy Date: Sun, 9 Jun 2024 13:22:08 -0400 Subject: [PATCH 1/6] Make some git messages less wordy. --- R/pr.R | 12 ++++++------ R/utils-git.R | 9 ++++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/R/pr.R b/R/pr.R index 8e2e2933b..2af8a5dfb 100644 --- a/R/pr.R +++ b/R/pr.R @@ -258,7 +258,7 @@ pr_resume <- function(branch = NULL) { )) } - challenge_uncommitted_changes() + challenge_uncommitted_changes(which = "switch") ui_bullets(c("v" = "Switching to branch {.val {branch}}.")) gert::git_branch_checkout(branch, repo = repo) @@ -283,7 +283,7 @@ pr_resume <- function(branch = NULL) { pr_fetch <- function(number = NULL, target = c("source", "primary")) { repo <- git_repo() tr <- target_repo(github_get = NA, role = target, ask = FALSE) - challenge_uncommitted_changes() + challenge_uncommitted_changes(which = "switch") if (is.null(number)) { ui_bullets(c("i" = "No PR specified ... looking up open PRs.")) @@ -377,7 +377,7 @@ pr_push <- function() { check_for_config(cfg, ok_configs = c("ours", "fork")) default_branch <- git_default_branch() check_pr_branch(default_branch) - challenge_uncommitted_changes() + challenge_uncommitted_changes(which = "push") branch <- git_branch() remref <- git_branch_tracking(branch) @@ -425,7 +425,7 @@ pr_pull <- function() { check_for_config(cfg) default_branch <- git_default_branch() check_pr_branch(default_branch) - challenge_uncommitted_changes() + challenge_uncommitted_changes(which = "pull") git_pull() @@ -440,7 +440,7 @@ pr_pull <- function() { #' @rdname pull-requests pr_merge_main <- function() { tr <- target_repo(github_get = TRUE, ask = FALSE) - challenge_uncommitted_changes() + challenge_uncommitted_changes(which = "pull") remref <- glue("{tr$remote}/{tr$default_branch}") ui_bullets(c("v" = "Pulling changes from {.val {remref}}.")) git_pull(remref, verbose = FALSE) @@ -503,7 +503,7 @@ pr_pause <- function() { )) return(invisible()) } - challenge_uncommitted_changes() + challenge_uncommitted_changes(which = "switch") # TODO: what happens here if offline? check_branch_pulled(use = "pr_pull()") diff --git a/R/utils-git.R b/R/utils-git.R index c1716ffdc..f6ecfd8a8 100644 --- a/R/utils-git.R +++ b/R/utils-git.R @@ -181,7 +181,10 @@ git_uncommitted <- function(untracked = FALSE) { nrow(git_status(untracked)) > 0 } -challenge_uncommitted_changes <- function(untracked = FALSE, msg = NULL) { +challenge_uncommitted_changes <- function( + untracked = FALSE, + msg = NULL, + which = c("push", "pull", "switch", "compare branches")) { if (!uses_git()) { return(invisible()) } @@ -192,7 +195,7 @@ challenge_uncommitted_changes <- function(untracked = FALSE, msg = NULL) { default_msg <- " There are uncommitted changes, which may cause problems or be lost when \\ - we push, pull, switch, or compare branches" + we {.or {which}}" msg <- glue(msg %||% default_msg) if (git_uncommitted(untracked = untracked)) { if (ui_yep(c( @@ -201,7 +204,7 @@ challenge_uncommitted_changes <- function(untracked = FALSE, msg = NULL) { ))) { return(invisible()) } else { - ui_abort("Uncommitted changes. Please commit before continuing.") + ui_abort("Uncommitted changes. Please commit before continuing.", call = NULL) } } } From 70e17a247955f4cb7252833fd818a239baf5a8cd Mon Sep 17 00:00:00 2001 From: olivroy Date: Sun, 9 Jun 2024 13:36:47 -0400 Subject: [PATCH 2/6] Tweak message to make it shorter. --- R/utils-git.R | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/R/utils-git.R b/R/utils-git.R index f6ecfd8a8..4fdd315b7 100644 --- a/R/utils-git.R +++ b/R/utils-git.R @@ -193,15 +193,22 @@ challenge_uncommitted_changes <- function( rstudioapi::documentSaveAll() } - default_msg <- " - There are uncommitted changes, which may cause problems or be lost when \\ - we {.or {which}}" - msg <- glue(msg %||% default_msg) - if (git_uncommitted(untracked = untracked)) { - if (ui_yep(c( - "!" = msg, - " " = "Do you want to proceed anyway?" - ))) { + default_msg <- + "Uncommitted changes may cause problems or be lost when we {.or {which}}." + msg <- cli::format_inline(msg %||% default_msg) + + uncommited <- git_status(untracked) + if (nrow(uncommited) > 0) { + choice <- utils::menu( + c( + "I want to proceed anyway.", + cli::format_inline( + "I want to take a closer look at {.file {uncommited$file}} first." + ) + ), + title = msg + ) + if (choice == 1) { return(invisible()) } else { ui_abort("Uncommitted changes. Please commit before continuing.", call = NULL) From 386aec3ad1e6484063b5196e85a896537351c4ad Mon Sep 17 00:00:00 2001 From: olivroy Date: Sun, 9 Jun 2024 13:47:47 -0400 Subject: [PATCH 3/6] More tweaks --- R/utils-git.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/utils-git.R b/R/utils-git.R index 4fdd315b7..1fc0e49ff 100644 --- a/R/utils-git.R +++ b/R/utils-git.R @@ -211,7 +211,11 @@ challenge_uncommitted_changes <- function( if (choice == 1) { return(invisible()) } else { - ui_abort("Uncommitted changes. Please commit before continuing.", call = NULL) + ui_abort( + "Uncommitted changes. Please commit before continuing.", + call = caller_env() + ) + return(invisible()) } } } From 5958d4acb68d309e50592738e5b5ad380ead81b5 Mon Sep 17 00:00:00 2001 From: Olivier Roy Date: Thu, 25 Jul 2024 09:03:20 -0400 Subject: [PATCH 4/6] Use more precise wording. --- R/pr.R | 8 ++++---- R/utils-git.R | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/R/pr.R b/R/pr.R index 2af8a5dfb..79da47e89 100644 --- a/R/pr.R +++ b/R/pr.R @@ -208,7 +208,7 @@ pr_init <- function(branch) { if (!is.na(remref)) { comparison <- git_branch_compare(current_branch, remref) if (comparison$remote_only > 0) { - challenge_uncommitted_changes() + challenge_uncommitted_changes(which = c("pull", "switch branches")) } ui_bullets(c("v" = "Pulling changes from {.val {remref}}.")) git_pull(remref = remref, verbose = FALSE) @@ -258,7 +258,7 @@ pr_resume <- function(branch = NULL) { )) } - challenge_uncommitted_changes(which = "switch") + challenge_uncommitted_changes(which = c("pull", "switch", "compare branches")) ui_bullets(c("v" = "Switching to branch {.val {branch}}.")) gert::git_branch_checkout(branch, repo = repo) @@ -283,7 +283,7 @@ pr_resume <- function(branch = NULL) { pr_fetch <- function(number = NULL, target = c("source", "primary")) { repo <- git_repo() tr <- target_repo(github_get = NA, role = target, ask = FALSE) - challenge_uncommitted_changes(which = "switch") + challenge_uncommitted_changes(which = c("pull", "switch branches")) if (is.null(number)) { ui_bullets(c("i" = "No PR specified ... looking up open PRs.")) @@ -503,7 +503,7 @@ pr_pause <- function() { )) return(invisible()) } - challenge_uncommitted_changes(which = "switch") + challenge_uncommitted_changes(which = "switch branches") # TODO: what happens here if offline? check_branch_pulled(use = "pr_pull()") diff --git a/R/utils-git.R b/R/utils-git.R index 178994bd8..31287a79d 100644 --- a/R/utils-git.R +++ b/R/utils-git.R @@ -215,7 +215,6 @@ challenge_uncommitted_changes <- function( "Uncommitted changes. Please commit before continuing.", call = caller_env() ) - return(invisible()) } } } From 37def27c8b65c990977b1684447a96dbf15a8efb Mon Sep 17 00:00:00 2001 From: Olivier Roy Date: Wed, 2 Oct 2024 10:11:10 -0400 Subject: [PATCH 5/6] tweak + address test failures --- R/pr.R | 14 +++++------ R/utils-git.R | 37 ++++++++++++++++-------------- tests/testthat/test-rename-files.R | 2 +- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/R/pr.R b/R/pr.R index b568cf887..3961ed278 100644 --- a/R/pr.R +++ b/R/pr.R @@ -219,7 +219,7 @@ pr_init <- function(branch) { if (!is.na(remref)) { comparison <- git_branch_compare(current_branch, remref) if (comparison$remote_only > 0) { - challenge_uncommitted_changes(which = c("pull", "switch branches")) + challenge_uncommitted_changes(action = c("pull", "switch branches")) } ui_bullets(c("v" = "Pulling changes from {.val {remref}}.")) git_pull(remref = remref, verbose = FALSE) @@ -265,7 +265,7 @@ pr_resume <- function(branch = NULL) { )) } - challenge_uncommitted_changes(which = c("pull", "switch", "compare branches")) + challenge_uncommitted_changes(action = c("pull", "switch", "compare branches")) ui_bullets(c("v" = "Switching to branch {.val {branch}}.")) gert::git_branch_checkout(branch, repo = repo) @@ -290,7 +290,7 @@ pr_resume <- function(branch = NULL) { pr_fetch <- function(number = NULL, target = c("source", "primary")) { repo <- git_repo() tr <- target_repo(github_get = NA, role = target, ask = FALSE) - challenge_uncommitted_changes(which = c("pull", "switch branches")) + challenge_uncommitted_changes(action = c("pull", "switch branches")) if (is.null(number)) { ui_bullets(c("i" = "No PR specified ... looking up open PRs.")) @@ -384,7 +384,7 @@ pr_push <- function() { check_for_config(cfg, ok_configs = c("ours", "fork")) default_branch <- git_default_branch_(cfg) check_pr_branch(default_branch) - challenge_uncommitted_changes(which = "push") + challenge_uncommitted_changes(action = "push") branch <- git_branch() remref <- git_branch_tracking(branch) @@ -432,7 +432,7 @@ pr_pull <- function() { check_for_config(cfg) default_branch <- git_default_branch_(cfg) check_pr_branch(default_branch) - challenge_uncommitted_changes(which = "pull") + challenge_uncommitted_changes(action = "pull") git_pull() @@ -447,7 +447,7 @@ pr_pull <- function() { #' @rdname pull-requests pr_merge_main <- function() { tr <- target_repo(github_get = TRUE, ask = FALSE) - challenge_uncommitted_changes(which = "pull") + challenge_uncommitted_changes(action = "pull") remref <- glue("{tr$remote}/{tr$default_branch}") ui_bullets(c("v" = "Pulling changes from {.val {remref}}.")) git_pull(remref, verbose = FALSE) @@ -511,7 +511,7 @@ pr_pause <- function() { )) return(invisible()) } - challenge_uncommitted_changes(which = "switch branches") + challenge_uncommitted_changes(action = "switch branches") # TODO: what happens here if offline? check_branch_pulled(use = "pr_pull()") diff --git a/R/utils-git.R b/R/utils-git.R index d01fc06b7..beb0d03f9 100644 --- a/R/utils-git.R +++ b/R/utils-git.R @@ -184,7 +184,8 @@ git_uncommitted <- function(untracked = FALSE) { challenge_uncommitted_changes <- function( untracked = FALSE, msg = NULL, - which = c("push", "pull", "switch", "compare branches")) { + action = c("push", "pull", "switch", "compare branches") +) { if (!uses_git()) { return(invisible()) } @@ -194,28 +195,30 @@ challenge_uncommitted_changes <- function( } default_msg <- - "Uncommitted changes may cause problems or be lost when we {.or {which}}." + "Uncommitted changes may cause problems or be lost when we {.or {action}}." msg <- cli::format_inline(msg %||% default_msg) uncommited <- git_status(untracked) if (nrow(uncommited) > 0) { - choice <- utils::menu( - c( - "I want to proceed anyway.", - cli::format_inline( - "I want to take a closer look at {.file {uncommited$file}} first." - ) - ), - title = msg - ) - if (choice == 1) { - return(invisible()) - } else { - ui_abort( - "Uncommitted changes. Please commit before continuing.", - call = caller_env() + if (is_interactive()) { + choice <- utils::menu( + c( + "I want to proceed anyway.", + cli::format_inline( + "I want to take a closer look at {.file {uncommited$file}} first." + ) + ), + title = msg ) + if (choice == 1) { + return(invisible()) + } } + + ui_abort( + "Uncommitted changes. Please commit before continuing.", + call = caller_env() + ) } } diff --git a/tests/testthat/test-rename-files.R b/tests/testthat/test-rename-files.R index cdfef3906..58ebefee5 100644 --- a/tests/testthat/test-rename-files.R +++ b/tests/testthat/test-rename-files.R @@ -6,7 +6,7 @@ test_that("checks uncommitted files", { use_r("foo", open = FALSE) expect_error( rename_files("foo", "bar"), - "uncommitted changes", + "Uncommitted changes", class = "usethis_error" ) }) From 0e958115340f91344ed3358173b700d042407ae2 Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Sat, 5 Oct 2024 12:15:42 -0400 Subject: [PATCH 6/6] Fix trailing comma --- R/pr.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/pr.R b/R/pr.R index 3961ed278..3cf3ee70a 100644 --- a/R/pr.R +++ b/R/pr.R @@ -187,7 +187,7 @@ pr_init <- function(branch) { "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" = "See {.run usethis::gh_token_help()} for help with that." )) if (ui_github_remote_config_wat(cfg)) { ui_bullets(c("x" = "Cancelling."))