Skip to content

Commit

Permalink
Add option to merge conflicts without opening the files (#1949)
Browse files Browse the repository at this point in the history
* Add option to merge conflicts without opening the files

* Refactor

* Tweak the question

---------

Co-authored-by: Jennifer (Jenny) Bryan <[email protected]>
  • Loading branch information
olivroy and jennybc authored Jul 24, 2024
1 parent a919437 commit 3b6847f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 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 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
Expand Down
31 changes: 18 additions & 13 deletions R/utils-git.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------------------------------------------------------------------
Expand Down

0 comments on commit 3b6847f

Please sign in to comment.