-
Notifications
You must be signed in to change notification settings - Fork 0
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
mrc-5105: Add has_modifications flag to report list endpoint #3
Changes from all commits
985caf3
6d7f444
d2360ea
f1b01a7
c89423d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
git_run <- function(args, repo = NULL, check = FALSE) { | ||
git <- sys_which("git") | ||
if (!is.null(repo)) { | ||
args <- c("-C", repo, args) | ||
} | ||
res <- system3(git, args) | ||
if (check && !res$success) { | ||
stop(sprintf("Error code %d running command:\n%s", | ||
res$code, paste0(" > ", res$output, collapse = "\n"))) | ||
} | ||
res | ||
} | ||
|
||
|
||
git_get_default_branch <- function(repo = NULL) { | ||
# This is assuming remote origin exists. We'll get an error if it | ||
# doesn't. But this should be safe for us as we'll always have cloned | ||
# this from GitHub. | ||
origin <- gert::git_remote_info("origin", repo = repo) | ||
origin$head | ||
} | ||
|
||
|
||
git_get_modified <- function(ref, base = NULL, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should make a ticket to patch gert for this perhaps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, added a ticket for this https://mrc-ide.myjetbrains.com/youtrack/issue/mrc-5126/Update-gert-to-be-able-to-get-diff-with-...-syntax |
||
relative_dir = NULL, repo = NULL) { | ||
if (is.null(base)) { | ||
base <- git_get_default_branch(repo) | ||
} | ||
if (is.null(relative_dir)) { | ||
relative <- "" | ||
additional_args <- "" | ||
} else { | ||
relative <- sprintf("--relative=%s", relative_dir) | ||
additional_args <- sprintf("-- %s", relative_dir) | ||
} | ||
git_run( | ||
c("diff", "--name-only", relative, | ||
sprintf("%s...%s", base, gert::git_commit_id(ref, repo = repo)), | ||
additional_args), | ||
repo = repo, check = TRUE)$output | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
test_that("handle failure", { | ||
testthat::skip_on_cran() | ||
repo <- initialise_git_repo() | ||
r <- git_run("unknown-command", repo = repo$path) | ||
expect_false(r$success) | ||
expect_error( | ||
git_run("unknown-command", repo = repo$path, check = TRUE), | ||
r$output, fixed = TRUE) | ||
}) | ||
|
||
|
||
test_that("can get default branch when remote origin is set", { | ||
testthat::skip_on_cran() | ||
repo <- initialise_git_repo() | ||
expect_null(git_get_default_branch(repo$path)) | ||
git_run(c("symbolic-ref", | ||
"refs/remotes/origin/HEAD", | ||
"refs/remotes/origin/main"), | ||
repo = repo$path) | ||
expect_equal(git_get_default_branch(repo$path), "refs/remotes/origin/main") | ||
}) | ||
|
||
|
||
test_that("can get files which have been modified", { | ||
testthat::skip_on_cran() | ||
repo <- test_prepare_orderly_remote_example("data") | ||
copy_examples("parameters", repo$local) | ||
gert::git_add(".", repo = repo$local) | ||
user <- "author <author@example.com>" | ||
gert::git_commit("add parameters", author = user, committer = user, | ||
repo = repo$local) | ||
|
||
log <- gert::git_log(repo = repo$local) | ||
expect_equal(git_get_modified(log$commit[[2]], repo = repo$local), | ||
character(0)) | ||
expect_equal(git_get_modified(log$commit[[1]], repo = repo$local), | ||
"src/parameters/orderly.R") | ||
expect_equal(git_get_modified(log$commit[[1]], relative = "src/", | ||
repo = repo$local), | ||
"parameters/orderly.R") | ||
expect_equal(git_get_modified(log$commit[[1]], base = log$commit[[2]], | ||
repo = repo$local), | ||
"src/parameters/orderly.R") | ||
expect_equal(git_get_modified(log$commit[[2]], base = log$commit[[1]], | ||
repo = repo$local), | ||
character(0)) | ||
expect_equal(git_get_modified(log$commit[[2]], base = log$commit[[2]], | ||
repo = repo$local), | ||
character(0)) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to ref too because I think this is better description, it can work with a hash or a branch name