as.git_repository: Open a Git repository, the git2r way

Description Usage Arguments Details Value Examples

Description

Use this to convert a path into a git_repository object, which is how the git2r package handles Git repositories. This function is a slightly more flexible version of git2r::repository().

Usage

1

Arguments

x

path that is or is in a Git repository; defaults to working directory

...

additional arguments, such as ceiling from discover_repository()

Details

githug uses git2r, under the hood, to perform local Git operations. While githug always identifies the repository via its path, git2r handles repositories as objects of class git_repository. If you want to do a Git operation that isn't exposed via githug, this function helps you specify the repository git2r-style.

Value

An S4 git_repository object

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
repo <- git_init(tempfile("git-repository-example-"))

## you can specify the path explicitly
as.git_repository(repo)

## switch working directory to the repo
owd <- setwd(repo)

## as.git_repository() with no args consults working directory
as.git_repository()

dir.create("subdir")

## as.git_repository() walks up parents, looking for a repo
as.git_repository("subdir")

setwd("subdir")
as.git_repository()
## unless you put a ceiling on the walk
## Not run: 
as.git_repository("repo-path/subdir", ceiling = 0)

## End(Not run)

setwd(owd)

## Not run: 
## here's a rather exotic Git operation that githug is unlikely to expose:
## odb_blobs() lists "all blobs reachable from the commits in the object database"
## pre-process the repo with as_git_repository() to prepare for git2r
git2r::odb_blobs(as.git_repository("path_to_a_git_repo"))

## End(Not run)

jennybc/githug documentation built on May 19, 2019, 5:05 a.m.