-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathinit.php
52 lines (39 loc) · 1.01 KB
/
init.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
52
<?php
function recurse_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
recurse_copy($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}
function init_repo($reponame, $target, $bare = false)
{
$rootPath = dirname(__DIR__);
$libgitPath = $rootPath . '/libgit2';
$testRepoPath = $libgitPath . '/tests/resources';
if (!file_exists($testRepoPath))
{
throw new Exception('test repository assets not found at '.$testRepoPath);
}
$repoPath = $testRepoPath . '/' . $reponame;
if (!file_exists($repoPath))
{
throw new Exception('test repository '. $reponame.' assets not found');
}
@mkdir($target);
recurse_copy($repoPath, $target.'/'.$reponame);
if (!$bare)
{
$oldPath =$target.'/'.$reponame.'/.gitted';
$newPath =$target.'/'.$reponame.'/.git';
rename($oldPath, $newPath);
}
}