This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGitCloneTask.php
executable file
·76 lines (71 loc) · 1.78 KB
/
GitCloneTask.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
require_once 'GitTask.php';
/**
* Clones a git repository to a local directory.
*
* @author Zach Campbell <[email protected]>
*/
class GitCloneTask extends GitTask {
private $_repo;
private $_path;
private $_onexisting;
/**
* Sets the repository to clone.
*/
public function setRepo($repo) {
$this->_repo = $repo;
}
/**
* Sets the target path for the cloned repository.
*/
public function setPath($path) {
$this->_path = $path;
}
/**
* Sets the behaviour if path exists.
*/
public function setOnexisting($onexisting) {
$this->_onexisting = $onexisting;
}
/**
* The main entry.
*/
public function main() {
if(false == isset($this->_repo) || false == isset($this->_path)) {
$this->log("GitCloneTask Fail: REPO and PATH must be set!\n");
exit(1);
}
if ( file_exists($this->_path) ) {
switch($this->_onexisting) {
case 'replace':
if ( ! $this->recursiveRmDir($this->_path) ) {
$this->log("GitCloneTask Fail: PATH could not be deleted!\n");
exit(1);
};
break;
case 'ignore':
if ( file_exists($this->_path . '/.git/config') ) {
// Ignore, just return.
return;
} else {
$this->log("GitCloneTask Fail: PATH already exists but does not look like a Git repository!\n");
exit(1);
}
break;
case 'fail':
default:
$this->log("GitCloneTask Fail: PATH already exists!\n");
exit(1);
break;
}
}
$command = $this->git_path . " clone " . $this->_repo . " " . $this->_path;
$this->log("Attempting to clone '" . $this->_repo . "' into '" . $this->_path . "'");
$this->log("Running " . $command);
passthru($command, $return);
if(intval($return) > 0) {
$this->log("Git Clone Failed.");
exit(1);
}
}
}