walk_git: Pipe-able, vectorized, and lightweight implementation of git...

Description Usage Arguments Value Examples

View source: R/walk_git.R View source: R/map_git.R

Description

Apply a Git command to each path.

Usage

1
walk_git(path, command, verbose = FALSE, stop_on_error = TRUE, ...)

Arguments

path

Path to one or multiple Git repos.

command

A Git command, e.g. "status" or "log –oneline -n 1".

verbose

Print Git's output?

stop_on_error

If Git fails, do you want an R error?

...

Other arguments passed to system.

Value

walk_git() is called for its side effect; it returns path 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
library(magrittr)

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

repos <- file.path(tempdir(), paste0("repo", 1:2))
repos %>% walk(dir.create)

# Fails because the repo isn't initialized
repos %>%
  walk_git("status") %>%
  try()

# Don't throw an error
repos %>%
  walk_git("status", stop_on_error = FALSE)

repos %>% walk_git("init")

repos %>% walk_git("status")
repos %>% walk_git("status", verbose = TRUE)

repos %>%
  walk_git("add .") %>%
  walk_git("commit -m 'Initialize' --allow-empty") %>%
  walk_git("log --oneline -n 1", verbose = TRUE)

# Cleanup
walk(repos, unlink, recursive = TRUE)

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