git2r icon indicating copy to clipboard operation
git2r copied to clipboard

FR: commits() for other objects

Open krlmlr opened this issue 8 years ago • 1 comments

  • commit
  • branch
  • repo + SHA1
  • ...

krlmlr avatar May 10 '16 11:05 krlmlr

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="[email protected]")

## 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

stewid avatar May 18 '16 16:05 stewid