checkout: Checkout Git repositories

Description Usage Arguments Value Examples

View source: R/checkout.R

Description

Checkout the main or master branch of the given Git repositories. But stay on the current reference (e.g. branch) if checking out the repository that called checkout().

Usage

1
checkout(repos)

Arguments

repos

Path to one or more Git repositories.

Value

Called for its side effect. Returns repos invisibly.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
library(magrittr)

# Helper
walk <- function(x, f, ...) {
  lapply(x, f, ...)
  invisible(x)
}

# Setup two minimal repositories.
repos <- file.path(tempdir(), paste0("repo", 1:2))
repos
repos %>% walk(dir.create)
repos %>%
  file.path("a-file.txt") %>%
  walk(file.create)
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 'New file'")

# If we set the directory at `repo1`, it stays at the branch `pr`, whereas the
# `repo2` changes to the branch `master` (or `main`).

oldwd <- getwd()
setwd(repos[[1]])

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

# Compare before and after `checkout()`
repos %>% walk_git("branch", verbose = TRUE)
repos %>% checkout()
repos %>% walk_git("branch", verbose = TRUE)

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

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