From 3b6847f4b325670bdcb67b5ada741d1da43908c1 Mon Sep 17 00:00:00 2001 From: olivroy <52606734+olivroy@users.noreply.github.com> Date: Wed, 24 Jul 2024 17:30:11 -0400 Subject: [PATCH] Add option to merge conflicts without opening the files (#1949) * Add option to merge conflicts without opening the files * Refactor * Tweak the question --------- Co-authored-by: Jennifer (Jenny) Bryan --- NEWS.md | 2 ++ R/utils-git.R | 31 ++++++++++++++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/NEWS.md b/NEWS.md index d908e7e7c..955620fb9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # usethis (development version) +* `pr_merge_main()` now offers the choice to not open the files with merge conflicts (@olivroy, #1720). + * `edit_rstudio_snippets()` now accepts yaml snippets (@olivroy, #1941). * `use_standalone()` inserts an improved header that includes the code needed to diff --git a/R/utils-git.R b/R/utils-git.R index c1716ffdc..42ba7d770 100644 --- a/R/utils-git.R +++ b/R/utils-git.R @@ -224,23 +224,28 @@ git_conflict_report <- function() { bulletize(conflicted_paths, n_show = 10) )) - msg <- c( - "!" = "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." + 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." - if (ui_yep(msg, yes = yes, no = no, shuffle = FALSE)) { - 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 { + choice <- utils::menu( + title = "Do you want to proceed with this merge?", + choices = c(yes, yes_soft, no), + title = msg + ) + + 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 ----------------------------------------------------------------------