Skip to content

Commit

Permalink
revparse_single: handle case when git object is a blob
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Widgren <stefan.widgren@gmail.com>
  • Loading branch information
stewid committed Jan 5, 2018
1 parent 76a59c6 commit c1774b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/git2r_revparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ SEXP git2r_revparse_single(SEXP repo, SEXP revision)
goto cleanup;

switch (git_object_type(treeish)) {
case GIT_OBJ_BLOB:
PROTECT(result = NEW_OBJECT(MAKE_CLASS("git_blob")));
git2r_blob_init((git_blob*)treeish, repo, result);
break;
case GIT_OBJ_COMMIT:
PROTECT(result = NEW_OBJECT(MAKE_CLASS("git_commit")));
git2r_commit_init((git_commit*)treeish, repo, result);
Expand Down
1 change: 1 addition & 0 deletions tests/revparse.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ add(repo, "test.txt")
commit(repo, "Second commit message")

stopifnot(identical(revparse_single(repo, "HEAD^"), commit_1))
stopifnot(is_blob(revparse_single(repo, "HEAD:test.txt")))

## Cleanup
unlink(path, recursive=TRUE)

0 comments on commit c1774b1

Please sign in to comment.