Skip to content

Commit 29e0fb8

Browse files
Raise error on repo.descendant_of when no commit exists.
Fixed #822
1 parent b4c1e07 commit 29e0fb8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/repository.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,12 @@ Repository_descendant_of(Repository *self, PyObject *args)
590590
if (err < 0)
591591
return NULL;
592592

593-
return PyBool_FromLong(git_graph_descendant_of(self->repo, &oid1, &oid2));
593+
// err < 0 => error, see source code of `git_graph_descendant_of`
594+
err = git_graph_descendant_of(self->repo, &oid1, &oid2);
595+
if (err < 0)
596+
return Error_set(err);
597+
598+
return PyBool_FromLong(err);
594599
}
595600

596601
PyDoc_STRVAR(Repository_merge_base__doc__,

test/test_repository.py

+5
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,11 @@ def test_descendent_of(self):
359359
'acecd5ea2924a4b900e7e149496e1f4b57976e51',
360360
'5ebeeebb320790caf276b9fc8b24546d63316533')
361361

362+
with pytest.raises(pygit2.GitError):
363+
self.repo.descendant_of(
364+
'2' * 40, # a valid but inexistent SHA
365+
'5ebeeebb320790caf276b9fc8b24546d63316533')
366+
362367
def test_ahead_behind(self):
363368
ahead, behind = self.repo.ahead_behind(
364369
'5ebeeebb320790caf276b9fc8b24546d63316533',

0 commit comments

Comments
 (0)