-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path000_base.php
53 lines (41 loc) · 1.32 KB
/
000_base.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
if (!extension_loaded('git2')) {
echo "Unable to run tests without extension!\n";
exit(1);
}
$repo = Git2\Repository::open(dirname(__DIR__));
var_dump($repo);
var_dump($repo->path());
var_dump($repo->head());
var_dump($repo->head()->name());
$config = $repo->config();
var_dump($config);
var_dump($config->export());
$last_commit = $repo->head()->target();
var_dump(bin2hex($last_commit));
//$commit = Git2\Commit::lookup_oid($repo, $last_commit);
$commit = $repo->head()->peel(Git2::OBJ_COMMIT); // this is actually equivalent to the previous command
var_dump($commit);
var_dump($commit->message());
$tree = $commit->tree();
var_dump($tree);
var_dump(bin2hex($tree->id()));
var_dump($tree->entrycount());
$cb = function($root, $entry) use ($repo) {
$fullname = $root.$entry->name();
echo " + $fullname (".bin2hex($entry->id()).")\n";
if ($fullname == 'README.md') {
// fetch contents, compare with actual README.md (will fail if uncommitted changes exist in file)
$blob = Git2\Blob::lookup_oid($repo, $entry->id());
$data = $blob->rawcontent();
$actual_data = file_get_contents(dirname(__DIR__).'/README.md');
if ($data == $actual_data) {
echo " `- TEST OK\n";
} else {
echo " `- TEST FAILED ! (data different, uncommitted changes?)\n";
exit(1);
}
}
return 0;
};
$tree->walk(Git2\Tree::WALK_POST, $cb);