Skip to content

Make pygit2 throw if tree of a commit is not found #682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "oid.h"

extern PyTypeObject TreeType;
extern PyObject *GitError;


PyDoc_STRVAR(Commit_message_encoding__doc__, "Message encoding.");
Expand Down Expand Up @@ -131,8 +132,11 @@ Commit_tree__get__(Commit *commit)
int err;

err = git_commit_tree(&tree, commit->commit);
if (err == GIT_ENOTFOUND)
Py_RETURN_NONE;
if (err == GIT_ENOTFOUND) {
char tree_id[GIT_OID_HEXSZ + 1] = { 0 };
git_oid_fmt(tree_id, git_commit_tree_id(commit->commit));
return PyErr_Format(GitError, "Unable to read tree %s", tree_id);
}

if (err < 0)
return Error_set(err);
Expand Down