Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to merge conflicts without opening the files #1949

Merged
merged 7 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading