Skip to content

Commit

Permalink
Add option to merge conflicts without opening the files
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Feb 20, 2024
1 parent ce6ed46 commit 787c213
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
18 changes: 13 additions & 5 deletions R/utils-git.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 787c213

Please sign in to comment.