From 787c213febe57ea6686953de242fa654a736a7d3 Mon Sep 17 00:00:00 2001 From: Olivier Roy Date: Tue, 20 Feb 2024 10:05:32 -0500 Subject: [PATCH 1/3] Add option to merge conflicts without opening the files --- NEWS.md | 2 ++ R/utils-git.R | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 35cba70f6..336c65c47 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # usethis (development version) +* `pr_merge_main()` now offers a new way to resolve merge conflicts (if any). An option was added to resolve merge conflicts without opening all files (@olivroy, #1720). + # usethis 2.2.3 * Patch release with changes to `.Rd` files requested by CRAN. diff --git a/R/utils-git.R b/R/utils-git.R index 234c64444..351adca53 100644 --- a/R/utils-git.R +++ b/R/utils-git.R @@ -227,17 +227,25 @@ git_conflict_report <- function() { paste0("* ", conflicted_paths) )) - msg <- glue(" - Are you ready to sort this out? - If so, we will open the conflicted files for you to edit.") - yes <- "Yes, I'm ready to resolve the merge conflicts." + msg <- "Are you ready to sort this out?" + yes <- "Yes, open the files. I'm ready to resolve the merge conflicts." + yes_soft <- "Yes, but don't open the files. I will resolve the merge conflicts." no <- "No, I want to abort this merge." - if (ui_yeah(msg, yes = yes, no = no, shuffle = FALSE)) { + merge_strategy <- utils::menu( + choices = c(yes, yes_soft, no), + title = msg + ) + if (merge_strategy == 1) { ui_silence(purrr::walk(conflicted, edit_file)) ui_stop(" Please fix each conflict, save, stage, and commit. To back out of this merge, run {ui_code('gert::git_merge_abort()')} \\ (in R) or {ui_code('git merge --abort')} (in the shell).") + } else if (merge_strategy == 2) { + ui_stop(" + Please fix each conflict, save, stage, and commit. + To back out of this merge, run {ui_code('gert::git_merge_abort()')} \\ + (in R) or {ui_code('git merge --abort')} (in the shell).") } else { gert::git_merge_abort(repo = git_repo()) ui_stop("Abandoning the merge, since it will cause merge conflicts") From 27e343ddb73ade1866ed71b6bc8806fa9325346e Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Wed, 24 Jul 2024 14:21:14 -0700 Subject: [PATCH 2/3] Refactor --- R/utils-git.R | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/R/utils-git.R b/R/utils-git.R index bdc581b29..6248dd892 100644 --- a/R/utils-git.R +++ b/R/utils-git.R @@ -225,30 +225,27 @@ git_conflict_report <- function() { )) msg <- "Are you ready to sort this out?" - yes <- "Yes, open the files. I'm ready to resolve the merge conflicts." - yes_soft <- "Yes, but don't open the files. I will resolve the merge conflicts." + yes <- "Yes, open the conflicted files for editing." + yes_soft <- "Yes, but do not open the conflicted files." no <- "No, I want to abort this merge." - merge_strategy <- utils::menu( + choice <- utils::menu( choices = c(yes, yes_soft, no), title = msg ) - if (merge_strategy == 1) { - ui_silence(purrr::walk(conflicted, edit_file)) - ui_abort(c( - "Please fix each conflict, save, stage, and commit.", - "To back out of this merge, run {.code gert::git_merge_abort()} - (in R) or {.code git merge --abort} (in the shell)." - )) - } else if (merge_strategy == 2) { - ui_abort(c( - "Please fix each conflict, save, stage, and commit.", - "To back out of this merge, run {.code gert::git_merge_abort()} - (in R) or {.code git merge --abort} (in the shell)." - )) - } else { + + if (choice < 1 || choice > 2) { gert::git_merge_abort(repo = git_repo()) ui_abort("Abandoning the merge, since it will cause merge conflicts.") } + + if (choice == 1) { + ui_silence(purrr::walk(conflicted, edit_file)) + } + ui_abort(c( + "Please fix each conflict, save, stage, and commit.", + "To back out of this merge, run {.code gert::git_merge_abort()} + (in R) or {.code git merge --abort} (in the shell)." + )) } # Remotes ---------------------------------------------------------------------- From 150095f833ad32379ed27e23bce8a4fbb74c5de3 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Wed, 24 Jul 2024 14:28:41 -0700 Subject: [PATCH 3/3] Tweak the question --- R/utils-git.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils-git.R b/R/utils-git.R index 6248dd892..42ba7d770 100644 --- a/R/utils-git.R +++ b/R/utils-git.R @@ -224,11 +224,11 @@ git_conflict_report <- function() { bulletize(conflicted_paths, n_show = 10) )) - msg <- "Are you ready to sort this out?" yes <- "Yes, open the conflicted files for editing." yes_soft <- "Yes, but do not open the conflicted files." no <- "No, I want to abort this merge." choice <- utils::menu( + title = "Do you want to proceed with this merge?", choices = c(yes, yes_soft, no), title = msg )