git2r
git2r copied to clipboard
FR: commits() for other objects
- commit
- branch
- repo + SHA1
- ...
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