ropensci / git2r

R bindings to the libgit2 library
https://docs.ropensci.org/git2r
GNU General Public License v2.0
216 stars 58 forks source link

FR: commits() for other objects #234

Open krlmlr opened 8 years ago

krlmlr commented 8 years ago
stewid commented 8 years ago

Hi @krlmlr

I have started to work on this and added commits methods with signature git_commit, git_branch and git_tag in the fr_commits branch. Is this the functionality you meant?

library(git2r)

## Create a directory in tempdir
path <- tempfile(pattern="git2r-")
dir.create(path)

## Initialize a repository
repo <- init(path)
config(repo, user.name="Alice", user.email="alice@example.org")

## Create a file and commit
writeLines("Hello world!", file.path(path, "test.txt"))
add(repo, "test.txt")
commit_1 <- commit(repo, "First commit message")

## Update the file and commit
writeLines(c("Hello world!", "Hello world!"), file.path(path, "test.txt"))
add(repo, "test.txt")
commit_2 <- commit(repo, "Second commit message")

## Add a tag
tag_1 <- tag(repo, "Tagname", "Tag message")

## List commits
commits(repo)
#> [[1]]
#> [f520221] 2016-05-18: Second commit message
#> 
#> [[2]]
#> [25d02cb] 2016-05-18: First commit message
commits(commit_1)
#> [[1]]
#> [f520221] 2016-05-18: Second commit message
#> 
#> [[2]]
#> [25d02cb] 2016-05-18: First commit message
commits(commit_2)
#> [[1]]
#> [f520221] 2016-05-18: Second commit message
#> 
#> [[2]]
#> [25d02cb] 2016-05-18: First commit message
commits(tag_1)
#> [[1]]
#> [f520221] 2016-05-18: Second commit message
#> 
#> [[2]]
#> [25d02cb] 2016-05-18: First commit message
commits(branches(repo)$master)
#> [[1]]
#> [f520221] 2016-05-18: Second commit message
#> 
#> [[2]]
#> [25d02cb] 2016-05-18: First commit message