File tree 2 files changed +89
-0
lines changed
2 files changed +89
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+
4
+ function recurse_copy ($ src ,$ dst ) {
5
+ $ dir = opendir ($ src );
6
+ @mkdir ($ dst );
7
+ while (false !== ( $ file = readdir ($ dir )) ) {
8
+ if (( $ file != '. ' ) && ( $ file != '.. ' )) {
9
+ if ( is_dir ($ src . '/ ' . $ file ) ) {
10
+ recurse_copy ($ src . '/ ' . $ file ,$ dst . '/ ' . $ file );
11
+ }
12
+ else {
13
+ copy ($ src . '/ ' . $ file ,$ dst . '/ ' . $ file );
14
+ }
15
+ }
16
+ }
17
+ closedir ($ dir );
18
+ }
19
+
20
+
21
+ function init_repo ($ reponame , $ target , $ bare = false )
22
+ {
23
+ $ rootPath = dirname (__DIR__ );
24
+ $ libgitPath = $ rootPath . '/libgit2 ' ;
25
+ $ testRepoPath = $ libgitPath . '/tests/resources ' ;
26
+
27
+ if (!file_exists ($ testRepoPath ))
28
+ {
29
+ throw new Exception ('test repository assets not found at ' .$ testRepoPath );
30
+ }
31
+
32
+ $ repoPath = $ testRepoPath . '/ ' . $ reponame ;
33
+
34
+
35
+ if (!file_exists ($ repoPath ))
36
+ {
37
+ throw new Exception ('test repository ' . $ reponame .' assets not found ' );
38
+ }
39
+
40
+ @mkdir ($ target );
41
+ recurse_copy ($ repoPath , $ target .'/ ' .$ reponame );
42
+
43
+ if (!$ bare )
44
+ {
45
+ $ oldPath =$ target .'/ ' .$ reponame .'/.gitted ' ;
46
+
47
+ $ newPath =$ target .'/ ' .$ reponame .'/.git ' ;
48
+
49
+ rename ($ oldPath , $ newPath );
50
+ }
51
+
52
+ }
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Check for git_tree_lookup
3
+ --SKIPIF--
4
+ <?php if (!extension_loaded ("git2 " )) print "skip " ; ?>
5
+ --FILE--
6
+ <?php
7
+ include_once (__DIR__ . '/../init.php ' );
8
+ $ path = "/tmp/git-tree-lookup " ;
9
+ $ testRepo = 'testrepo ' ;
10
+ init_Repo ($ testRepo , $ path );
11
+ $ repositroy = git_repository_open ($ path . '/ ' . $ testRepo );
12
+
13
+ $ fileHash = '6336846bd5c88d32f93ae57d846683e61ab5c530 ' ;
14
+ $ treeHash = '1810dff58d8a660512d4832e740f692884338ccd ' ;
15
+
16
+
17
+
18
+ $ tree = git_tree_lookup ($ repositroy , $ treeHash );
19
+ if (is_resource ($ tree )) {
20
+ echo "TREE: $ treeHash OK " . PHP_EOL ;
21
+ }
22
+ else
23
+ {
24
+ echo "TREE: $ treeHash FAIL " . PHP_EOL ;
25
+ }
26
+
27
+ $ tree = @git_tree_lookup ($ repositroy , $ fileHash );
28
+ if ($ tree ===null ) {
29
+ echo "FILE: $ fileHash OK " . PHP_EOL ;
30
+ }
31
+ else
32
+ {
33
+ echo "FILE: $ fileHash FAIL " . PHP_EOL ;
34
+ }
35
+ --EXPECT --
36
+ TREE : 1810 dff58d8a660512d4832e740f692884338ccd OK
37
+ FILE : 6336846 bd5c88d32f93ae57d846683e61ab5c530 FAIL
You can’t perform that action at this time.
0 commit comments