Return the git ref (tag or branch) of the repo to install given the available branches and tags.

determine_ref(ref, available_refs, fallback_branch = "main", branch_sep = "@")

Arguments

ref

ref we want to build

available_refs

data.frame with columns ref the names of the available refs and type (branch or tag)

fallback_branch

the default branch to try to use if no other matches found

branch_sep

separator between branches in feature, / does not work well with git because it clashes with the filesystem paths

Value

branch/tag to choose to match feature, error if no suitable branch was provided with the type attribute "tag" or "branch"

Details

A ref is either a tag or branches separated by slashes of the form name1@name2@...@nameN. Where separator is specified by branch_sep argument

This function checks for an exact match for the tag if this is not found then among the available branches, it searches in the order name1@name2@...@nameN, name2@name3@...@nameN, name3@name4@...@nameN, ..., nameN

Examples

determine_ref(
  "feature1",
  data.frame(ref = c("main", "feature1"), type = "branch")
) == structure("feature1", type = "branch")
#> [1] TRUE

determine_ref(
  "feature1@devel",
  data.frame(ref = c("main", "devel", "feature1"), type = "branch")
) == structure("devel", type = "branch")
#> [1] TRUE

determine_ref(
  ref = "fix1@feature1@devel",
  available_refs = data.frame(
    ref = c(
      "main", "devel", "feature1", "feature1@devel",
      "fix1@feature1@devel", "fix1"
    ),
    type = "branch"
  )
) == structure("fix1@feature1@devel", type = "branch")
#> [1] TRUE

determine_ref(
  "fix1@feature1@devel",
  data.frame(
    ref = c("main", "devel", "feature1", "feature1@devel", "fix1"),
    type = "branch"
  )
) == structure("feature1@devel", type = "branch")
#> [1] TRUE

determine_ref(
  "fix1@feature1@devel",
  data.frame(ref = c("main", "devel", "feature1", "fix1"), type = "branch")
) == structure("devel", type = "branch")
#> [1] TRUE

determine_ref("feature1@release", data.frame(ref = c("main", "devel"), type = "branch"))
#> [1] "main"
#> attr(,"type")
#> [1] "branch"

# error because neither `feature1@release` nor `release` branch exists
# determine_ref("feature1@release", data.frame(ref = c("master", "devel"), type = "branch"))

# tag examples
determine_ref(
  "v0.1",
  data.frame(ref = c("main", "devel", "feature1", "v0.1"), type = c(rep("branch", 3), "tag"))
) == structure("v0.1", type = "tag")
#> [1] TRUE

determine_ref(
  "v0.2",
  data.frame(ref = c("main", "devel", "feature1", "v0.1"), type = c(rep("branch", 3), "tag"))
) == structure("main", type = "branch")
#> [1] TRUE