-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from mrc-ide/mrc-5105
mrc-5105: Add has_modifications flag to report list endpoint
- Loading branch information
Showing
10 changed files
with
227 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters