Skip to content
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

git_tree_lookup - The requested type does not match the type in the ODB #63

Closed
laczak opened this issue Mar 26, 2014 · 2 comments
Closed

Comments

@laczak
Copy link

laczak commented Mar 26, 2014

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.

@ghost
Copy link

ghost commented May 13, 2014

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.

@ghost ghost mentioned this issue May 13, 2014
@chobie chobie closed this as completed May 14, 2014
@chobie
Copy link
Member

chobie commented May 14, 2014

thanks garyamort. this is expected behaviour. please check api doc.
http://libgit2.github.com/libgit2/#v0.20.0/group/tree/git_tree_lookup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants