Skip to content

Commit

Permalink
Return None for sha of in-memory objects.
Browse files Browse the repository at this point in the history
Change-Id: Ieb1f332184bf747f4f8b12f12fec9e3570f74b10
  • Loading branch information
dborowitz committed Nov 12, 2010
1 parent 1236c64 commit 3fa91b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pygit2.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,14 @@ Object_get_type(Object *self, void *closure) {

static PyObject *
Object_get_sha(Object *self, void *closure) {
const git_oid *id;
char hex[GIT_OID_HEXSZ];
git_oid_fmt(hex, git_object_id(self->obj));

id = git_object_id(self->obj);
if (!id)
return Py_None;

git_oid_fmt(hex, id);
return PyString_FromStringAndSize(hex, GIT_OID_HEXSZ);
}

Expand Down
1 change: 1 addition & 0 deletions test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_new_commit(self):
commit.committer = committer
commit.author = author

self.assertEqual(None, commit.sha)
self.assertEqual(pygit2.GIT_OBJ_COMMIT, commit.type)
self.assertEqual(message, commit.message)
# TODO: Uncomment when git_commit_set_message updates message_short.
Expand Down

0 comments on commit 3fa91b9

Please sign in to comment.