Skip to content
Stefan Widgren edited this page Jun 27, 2014 · 3 revisions

The central object in the git2r package is the S4 class git_repository. The following three methods can instantiate a repository; init, repository and clone.

Class "git_repository"

S4 class to handle a git repository

Slots

path: Path to a git repository

Open an existing repository

## Open an existing repository repo <- repository(/path/to/git2r)

Summary of repository

summary(repo)
#> Remote: @ origin (https://github.com/ropensci/git2r) #> Local: master /path/to/git2r/ #> #> Branches: 1 #> Tags: 0 #> Commits: 320 #> Contributors: 3 #> Ignored files: 0 #> Untracked files: 0 #> Unstaged files: 0 #> Staged files: 0

List all commits in repository

commits(repo)[[1]] # Truncated here for readability
#> Commit: 6fb440133765e80649de8d714eaea17b114bd0a7 #> Author: Stefan Widgren <stefan.widgren@gmail.com> #> When: 2014-04-22 21:43:19 #> Summary: Fixed clone progress to end line with newline

Create a new repository

Create a new repository in a temporary directory using init

## Create a temporary directory to hold the repository path <- tempfile(pattern="git2r-") dir.create(path) ## Initialize the repository repo <- init(path)

Display a brief summary of the new repository

repo
#> Local: /tmp/Rtmp7CXPlx/git2r-1ae2305c0e8d/ #> Head: nothing commited (yet)

Check if repository is bare

is_bare(repo)
#> [1] FALSE

Check if repository is empty

is_empty(repo)
#> [1] TRUE

Create a new bare repository

Create a temporary directory to hold the repository

path <- tempfile(pattern="git2r-") dir.create(path)

Initialize the repository

repo <- init(path, bare=TRUE)

Check if repository is bare

is_bare(repo)
#> [1] TRUE

Clone a repository

Create a temporary directory to hold the repository

path <- file.path(tempfile(pattern="git2r-"), "git2r") dir.create(path, recursive=TRUE)

Clone the git2r repository (Note: clone over https does not yet work on Windws)

repo <- clone("https://github.com/ropensci/git2r", path)
#> cloning into '/tmp/Rtmp7CXPlx/git2r-1ae27d811539/git2r'... #> Receiving objects: 1% (24/2329), 12 kb #> Receiving objects: 11% (257/2329), 60 kb #> Receiving objects: 21% (490/2329), 100 kb #> Receiving objects: 31% (722/2329), 125 kb #> Receiving objects: 41% (955/2329), 237 kb #> Receiving objects: 51% (1188/2329), 574 kb #> Receiving objects: 61% (1421/2329), 1014 kb #> Receiving objects: 71% (1654/2329), 1350 kb #> Receiving objects: 81% (1887/2329), 1733 kb #> Receiving objects: 91% (2120/2329), 2614 kb #> Receiving objects: 100% (2329/2329), 2641 kb, done.

Clone this wiki locally