githug (version 0.0.0.9000)

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

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

as.git_repository(x, ...)

Arguments

x
path that is or is in a Git repository; defaults to working directory
...
additional arguments, such as ceiling from discover_repository()

Value

An S4 git_repository object

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.

Examples

Run this code
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)

Run the code above in your browser using DataLab