README.md

checkout

R-CMD-check Codecov test
coverage CRAN
status

The goal of this package is to checkout a set of git repositories in a way similar to https://github.com/actions/checkout, to reproduce locally what you may usually do in GitHub actions. It is most useful to test locally the latest commit of the working directory in the context of the master branch of one or multiple other repositories.

Installation

You can install the development version of checkout from GitHub with:

# install.packages("devtools")
devtools::install_github("maurolepore/checkout")

Example

library(checkout)
library(magrittr)

# Helper
walk <- function(x, f, ...) {
  lapply(x, f, ...)
  invisible(x)
}
repos <- file.path(tempdir(), paste0("repo", 1:2))
repos %>% walk(dir.create)
repos %>% file.path("a-file.txt") %>% walk(file.create)
repos
#> [1] "/tmp/RtmpK9RbPy/repo1" "/tmp/RtmpK9RbPy/repo2"

repos %>%
  walk_git("init") %>%
  walk_git("config user.name Jerry") %>%
  walk_git("config user.email jerry@gmail.com") %>%
  walk_git("add .") %>%
  walk_git("commit -m 'Add a-file.txt'") %>%
  # Each repo now has a commit
  walk_git("log --oneline -n 1 --decorate", verbose = TRUE)
#> $`/tmp/RtmpK9RbPy/repo1`
#> [1] "9767b8f (HEAD -> main) Add a-file.txt"
#> 
#> $`/tmp/RtmpK9RbPy/repo2`
#> [1] "9767b8f (HEAD -> main) Add a-file.txt"
oldwd <- getwd()
setwd(repos[[1]])

repos %>% walk_git("checkout -b pr")

# Compare before and after `checkout()`
repos %>% walk_git("branch", verbose = TRUE)
#> $`/tmp/RtmpK9RbPy/repo1`
#> [1] "  main" "* pr"  
#> 
#> $`/tmp/RtmpK9RbPy/repo2`
#> [1] "  main" "* pr"
repos %>% checkout()
repos %>% walk_git("branch", verbose = TRUE)
#> $`/tmp/RtmpK9RbPy/repo1`
#> [1] "  main" "* pr"  
#> 
#> $`/tmp/RtmpK9RbPy/repo2`
#> [1] "* main" "  pr"

# Cleanup
setwd(oldwd)
repos %>% walk(unlink, recursive = TRUE)


maurolepore/checkout documentation built on Jan. 12, 2021, 1:27 p.m.