Skip to content

Commit 7b1f48c

Browse files
authored
Merge pull request #318 from vimc/vimc-6484
Allow control over default branch
2 parents 4ccd6eb + f4c7284 commit 7b1f48c

File tree

6 files changed

+107
-16
lines changed

6 files changed

+107
-16
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: orderly
22
Title: Lightweight Reproducible Reporting
3-
Version: 1.4.8
3+
Version: 1.4.9
44
Description: Order, create and store reports from R. By defining a
55
lightweight interface around the inputs and outputs of an
66
analysis, a lot of the repetitive work for reproducible research

R/config.R

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,9 @@ config_validate_remote <- function(remote, filename) {
298298
d <- remote[[name]]
299299
check_fields(d, sprintf("%s:remote:%s", filename, name),
300300
c("driver", "args"),
301-
c("url", "slack_url", "teams_url", "primary", "master_only"))
301+
c("url", "slack_url", "teams_url", "primary",
302+
"master_only", "default_branch_only",
303+
"default_branch"))
302304
field_name <- function(nm) {
303305
sprintf("%s:remote:%s:%s", filename, name, nm)
304306
}
@@ -318,10 +320,36 @@ config_validate_remote <- function(remote, filename) {
318320
} else {
319321
assert_scalar_logical(d$primary, field_name("primary"))
320322
}
321-
if (is.null(d$master_only)) {
322-
d$master_only <- FALSE
323+
324+
if (!is.null(d$master_only)) {
325+
if (!is.null(d$default_branch_only)) {
326+
msg <- c("Can't specify both 'master_only' and 'default_branch_only': ",
327+
sprintf("see %s:remote:%s", filename, name))
328+
stop(msg)
329+
}
330+
msg <- c("The 'master_only' field (used in",
331+
sprintf("%s:remote:%s", filename, name),
332+
"is deprecated and replaced with 'default_branch_only'",
333+
"and will be dropped in a future version of",
334+
"orderly. Please rename it in your orderly_config.yml")
335+
orderly_warning(flow_text(msg))
336+
d$default_branch_only <- d$master_only
337+
d$master_only <- NULL
338+
}
339+
340+
if (is.null(d$default_branch_only)) {
341+
d$default_branch_only <- FALSE
342+
} else {
343+
assert_scalar_logical(d$default_branch_only,
344+
field_name("default_branch_only"))
345+
}
346+
347+
## use '[[' not '$' here to avoid partial matches.
348+
if (is.null(d[["default_branch"]])) {
349+
d[["default_branch"]] <- "master"
323350
} else {
324-
assert_scalar_logical(d$master_only, field_name("master_only"))
351+
assert_scalar_character(d[["default_branch"]],
352+
field_name("default_branch"))
325353
}
326354

327355
d$driver <- check_symbol_from_str(d$driver, field_name("driver"))

R/remote.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ orderly_push_archive <- function(name, id = "latest", root = NULL,
241241
##' be included.
242242
##'
243243
##' @param ref Optional reference, indicating which branch should be
244-
##' used. This cannot be used if the remote has `master_only`
244+
##' used. This cannot be used if the remote has `default_branch_only`
245245
##' set.
246246
##'
247247
##' @param instance Select instance of the source database to be used,

R/testing.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ build_git_demo <- function() {
234234
archive
235235
}
236236

237-
unzip_git_demo <- function(path = tempfile()) {
237+
unzip_git_demo <- function(path = tempfile(), default_branch = "master") {
238238
tmp <- tempfile()
239239
dir.create(tmp, FALSE, TRUE)
240240
demo <- getOption("orderly.server.demo", build_git_demo())
@@ -244,14 +244,23 @@ unzip_git_demo <- function(path = tempfile()) {
244244
no.. = TRUE)
245245
file_copy(src, path, recursive = TRUE)
246246
unlink(tmp, recursive = TRUE)
247+
if (default_branch != "master") {
248+
## If git changes it's mind about what the default branch is called,
249+
## this will fail, we should probably detect this, but it's likely
250+
## that will break build_git_demo too
251+
gert::git_branch_move("master", default_branch, force = TRUE,
252+
repo = path)
253+
}
247254
path
248255
}
249256

250257
prepare_orderly_git_example <- function(path = tempfile(), run_report = FALSE,
251-
branch = "master") {
258+
branch = default_branch,
259+
default_branch = "master") {
252260
path_upstream <- file.path(path, "upstream")
253-
unzip_git_demo(path)
254-
unzip_git_demo(path_upstream)
261+
unzip_git_demo(path, default_branch)
262+
unzip_git_demo(path_upstream, default_branch)
263+
255264
git_checkout_branch(branch, root = path)
256265
git_checkout_branch(branch, root = path_upstream)
257266

man/orderly_run_remote.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-config.R

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ test_that("support declaring api server", {
126126
main = list(
127127
driver = "orderly::orderly_remote_path",
128128
primary = TRUE,
129-
master_only = TRUE,
129+
default_branch_only = TRUE,
130130
args = list(root = path)),
131131
other = list(
132132
driver = "orderly::orderly_remote_path",
@@ -145,7 +145,8 @@ test_that("support declaring api server", {
145145
expect_null(cfg$remote$other$identity)
146146
expect_equal(
147147
cfg$server_options(),
148-
list(primary = TRUE, master_only = TRUE, name = "main"))
148+
list(primary = TRUE, default_branch_only = TRUE,
149+
default_branch = "master", name = "main"))
149150

150151
cfg <- withr::with_envvar(
151152
c("ORDERLY_API_SERVER_IDENTITY" = "other"),
@@ -154,7 +155,8 @@ test_that("support declaring api server", {
154155
expect_true(cfg$remote$other$identity)
155156
expect_equal(
156157
cfg$server_options(),
157-
list(primary = FALSE, master_only = FALSE, name = "other"))
158+
list(primary = FALSE, default_branch_only = FALSE,
159+
default_branch = "master", name = "other"))
158160

159161
cfg <- withr::with_envvar(
160162
c("ORDERLY_API_SERVER_IDENTITY" = NA),
@@ -203,11 +205,11 @@ test_that("remote parse check", {
203205
driver = "orderly::orderly_remote_path",
204206
primary = TRUE,
205207
args = list(root = path),
206-
master_only = "yeah")))
208+
default_branch_only = "yeah")))
207209
writeLines(yaml::as.yaml(dat), path_orderly_config_yml(path))
208210
expect_error(
209211
orderly_config_$new(path),
210-
"'orderly_config.yml:remote:myhost:master_only' must be logical")
212+
"'orderly_config.yml:remote:myhost:default_branch_only' must be logical")
211213
})
212214

213215
test_that("no global folder", {
@@ -555,3 +557,55 @@ test_that("adding new fields in new versions gives good errors", {
555557
orderly_config_$new(path),
556558
"Orderly version '9.9.9' is required, but only '.+' installed")
557559
})
560+
561+
562+
test_that("can configure default branch for a remote", {
563+
path <- tempfile()
564+
dir.create(path)
565+
dat <- list(remote = list(
566+
main = list(
567+
driver = "orderly::orderly_remote_path",
568+
primary = TRUE,
569+
default_branch_only = TRUE,
570+
default_branch = "main",
571+
args = list(root = path))))
572+
writeLines(yaml::as.yaml(dat), path_orderly_config_yml(path))
573+
cfg <- orderly_config_$new(path)
574+
expect_true(cfg$remote$main$default_branch_only)
575+
expect_equal(cfg$remote$main$default_branch, "main")
576+
})
577+
578+
579+
test_that("migrate master_only", {
580+
path <- tempfile()
581+
dir.create(path)
582+
dat <- list(remote = list(
583+
main = list(
584+
driver = "orderly::orderly_remote_path",
585+
primary = TRUE,
586+
master_only = TRUE,
587+
args = list(root = path))))
588+
writeLines(yaml::as.yaml(dat), path_orderly_config_yml(path))
589+
expect_warning(
590+
cfg <- orderly_config_$new(path),
591+
"The 'master_only' field.*deprecated")
592+
expect_true(cfg$remote$main$default_branch_only)
593+
expect_equal(cfg$remote$main$default_branch, "master")
594+
})
595+
596+
597+
test_that("disallow both master_only and default_branch_only", {
598+
path <- tempfile()
599+
dir.create(path)
600+
dat <- list(remote = list(
601+
main = list(
602+
driver = "orderly::orderly_remote_path",
603+
primary = TRUE,
604+
master_only = TRUE,
605+
default_branch_only = TRUE,
606+
args = list(root = path))))
607+
writeLines(yaml::as.yaml(dat), path_orderly_config_yml(path))
608+
expect_error(
609+
orderly_config_$new(path),
610+
"Can't specify both 'master_only' and 'default_branch_only'")
611+
})

0 commit comments

Comments
 (0)