git_tree_lookup - The requested type does not match the type in the ODB
laczak opened this issue · 2 comments
Hi,
I'm trying to do an example/diff.php but I have an error:
Warning: git_tree_lookup(): WARNING -3 git_commit_lookup - The requested type does not match the type in the ODB in /srv/www/htdocs/index.php on line 6
Warning: git_diff_tree_to_workdir() expects parameter 2 to be resource, boolean given in /srv/www/htdocs/index.php on line 7
Warning: git_diff_print() expects parameter 1 to be resource, null given in /srv/www/htdocs/index.php on line 15
Source code:
<?php
//phpinfo();
echo '<pre>';
$repo = git_repository_open("/home/michal/git/base-app");
$tree = git_tree_lookup($repo, "96b38d2751d00bae12f42e6331140076d6f79a3c");
$diff = git_diff_tree_to_workdir($repo, $tree, git_diff_options_init());
$p = array();
git_diff_print($diff, GIT_DIFF_FORMAT_PATCH, function($diff_delta, $diff_hunk, $diff_line, $payload){
if ($diff_line['origin'] == "-" || $diff_line['origin'] == "+") {
echo $diff_line['origin'];
}
echo $diff_line['content'];
}, $p);
echo '</pre>';
The error is in this line:
$tree = git_tree_lookup($repo, "96b38d2751d00bae12f42e6331140076d6f79a3c");
This hash is one of my commit hash.
This is the correct response. git_tree_lookup requires the id of a git tree object, not a git commit object. So by giving it a git commit object you generated the error:
Warning: git_tree_lookup(): WARNING -3 git_commit_lookup - The requested type does not match the type in the ODB in /srv/www/htdocs/index.php on line 6
The other errors are because $tree is null instead of being a git tree resource.
I've added two tests of git_tree_lookup using libgit2's tests as a model:
#69
The test first uses a known tree hash from the libgit2 testrepo and verifies the lookup was successful.
The second test uses a known file hash from the libgit2 testrepo and verifies that $tree is null.
thanks garyamort. this is expected behaviour. please check api doc.
http://libgit2.github.com/libgit2/#v0.20.0/group/tree/git_tree_lookup