Skip to content

Commit

Permalink
tweak + address test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Oct 2, 2024
1 parent eec87e6 commit 37def27
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
14 changes: 7 additions & 7 deletions R/pr.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ pr_init <- function(branch) {
if (!is.na(remref)) {
comparison <- git_branch_compare(current_branch, remref)
if (comparison$remote_only > 0) {
challenge_uncommitted_changes(which = c("pull", "switch branches"))
challenge_uncommitted_changes(action = c("pull", "switch branches"))

Check warning on line 222 in R/pr.R

View check run for this annotation

Codecov / codecov/patch

R/pr.R#L222

Added line #L222 was not covered by tests
}
ui_bullets(c("v" = "Pulling changes from {.val {remref}}."))
git_pull(remref = remref, verbose = FALSE)
Expand Down Expand Up @@ -265,7 +265,7 @@ pr_resume <- function(branch = NULL) {
))
}

challenge_uncommitted_changes(which = c("pull", "switch", "compare branches"))
challenge_uncommitted_changes(action = c("pull", "switch", "compare branches"))

Check warning on line 268 in R/pr.R

View check run for this annotation

Codecov / codecov/patch

R/pr.R#L268

Added line #L268 was not covered by tests

ui_bullets(c("v" = "Switching to branch {.val {branch}}."))
gert::git_branch_checkout(branch, repo = repo)
Expand All @@ -290,7 +290,7 @@ pr_resume <- function(branch = NULL) {
pr_fetch <- function(number = NULL, target = c("source", "primary")) {
repo <- git_repo()
tr <- target_repo(github_get = NA, role = target, ask = FALSE)
challenge_uncommitted_changes(which = c("pull", "switch branches"))
challenge_uncommitted_changes(action = c("pull", "switch branches"))

Check warning on line 293 in R/pr.R

View check run for this annotation

Codecov / codecov/patch

R/pr.R#L293

Added line #L293 was not covered by tests

if (is.null(number)) {
ui_bullets(c("i" = "No PR specified ... looking up open PRs."))
Expand Down Expand Up @@ -384,7 +384,7 @@ pr_push <- function() {
check_for_config(cfg, ok_configs = c("ours", "fork"))
default_branch <- git_default_branch_(cfg)
check_pr_branch(default_branch)
challenge_uncommitted_changes(which = "push")
challenge_uncommitted_changes(action = "push")

Check warning on line 387 in R/pr.R

View check run for this annotation

Codecov / codecov/patch

R/pr.R#L387

Added line #L387 was not covered by tests

branch <- git_branch()
remref <- git_branch_tracking(branch)
Expand Down Expand Up @@ -432,7 +432,7 @@ pr_pull <- function() {
check_for_config(cfg)
default_branch <- git_default_branch_(cfg)
check_pr_branch(default_branch)
challenge_uncommitted_changes(which = "pull")
challenge_uncommitted_changes(action = "pull")

Check warning on line 435 in R/pr.R

View check run for this annotation

Codecov / codecov/patch

R/pr.R#L435

Added line #L435 was not covered by tests

git_pull()

Expand All @@ -447,7 +447,7 @@ pr_pull <- function() {
#' @rdname pull-requests
pr_merge_main <- function() {
tr <- target_repo(github_get = TRUE, ask = FALSE)
challenge_uncommitted_changes(which = "pull")
challenge_uncommitted_changes(action = "pull")

Check warning on line 450 in R/pr.R

View check run for this annotation

Codecov / codecov/patch

R/pr.R#L450

Added line #L450 was not covered by tests
remref <- glue("{tr$remote}/{tr$default_branch}")
ui_bullets(c("v" = "Pulling changes from {.val {remref}}."))
git_pull(remref, verbose = FALSE)
Expand Down Expand Up @@ -511,7 +511,7 @@ pr_pause <- function() {
))
return(invisible())
}
challenge_uncommitted_changes(which = "switch branches")
challenge_uncommitted_changes(action = "switch branches")

Check warning on line 514 in R/pr.R

View check run for this annotation

Codecov / codecov/patch

R/pr.R#L514

Added line #L514 was not covered by tests
# TODO: what happens here if offline?
check_branch_pulled(use = "pr_pull()")

Expand Down
37 changes: 20 additions & 17 deletions R/utils-git.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ git_uncommitted <- function(untracked = FALSE) {
challenge_uncommitted_changes <- function(
untracked = FALSE,
msg = NULL,
which = c("push", "pull", "switch", "compare branches")) {
action = c("push", "pull", "switch", "compare branches")
) {
if (!uses_git()) {
return(invisible())
}
Expand All @@ -194,28 +195,30 @@ challenge_uncommitted_changes <- function(
}

default_msg <-
"Uncommitted changes may cause problems or be lost when we {.or {which}}."
"Uncommitted changes may cause problems or be lost when we {.or {action}}."
msg <- cli::format_inline(msg %||% default_msg)

uncommited <- git_status(untracked)
if (nrow(uncommited) > 0) {
choice <- utils::menu(
c(
"I want to proceed anyway.",
cli::format_inline(
"I want to take a closer look at {.file {uncommited$file}} first."
)
),
title = msg
)
if (choice == 1) {
return(invisible())
} else {
ui_abort(
"Uncommitted changes. Please commit before continuing.",
call = caller_env()
if (is_interactive()) {
choice <- utils::menu(
c(
"I want to proceed anyway.",
cli::format_inline(
"I want to take a closer look at {.file {uncommited$file}} first."
)
),
title = msg
)
if (choice == 1) {
return(invisible())

Check warning on line 214 in R/utils-git.R

View check run for this annotation

Codecov / codecov/patch

R/utils-git.R#L204-L214

Added lines #L204 - L214 were not covered by tests
}
}

ui_abort(
"Uncommitted changes. Please commit before continuing.",
call = caller_env()
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-rename-files.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test_that("checks uncommitted files", {
use_r("foo", open = FALSE)
expect_error(
rename_files("foo", "bar"),
"uncommitted changes",
"Uncommitted changes",
class = "usethis_error"
)
})
Expand Down

0 comments on commit 37def27

Please sign in to comment.