Return None for sha of in-memory objects.

Change-Id: Ieb1f332184bf747f4f8b12f12fec9e3570f74b10
This commit is contained in:
Dave Borowitz 2010-10-30 17:13:40 -07:00
parent 1236c64a94
commit 3fa91b901d
2 changed files with 8 additions and 1 deletions

@ -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);
}

@ -62,6 +62,7 @@ class CommitTest(utils.TestRepoTestCase):
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.