|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the LGPL. For more information please see |
|
17
|
|
|
* <http://phing.info>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Base class for Git tasks |
|
22
|
|
|
* |
|
23
|
|
|
* @author Victor Farazdagi <[email protected]> |
|
24
|
|
|
* @package phing.tasks.ext.git |
|
25
|
|
|
* @see VersionControl_Git |
|
26
|
|
|
* @since 2.4.3 |
|
27
|
|
|
*/ |
|
28
|
|
|
abstract class GitBaseTask extends Task |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Bath to git binary |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
private $gitPath = '/usr/bin/git'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var VersionControl_Git |
|
39
|
|
|
*/ |
|
40
|
|
|
private $gitClient = null; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Current repository directory |
|
44
|
|
|
* |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
private $repository; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Initialize Task. |
|
51
|
|
|
* Check and include necessary libraries. |
|
52
|
|
|
*/ |
|
53
|
93 |
|
public function init() |
|
54
|
|
|
{ |
|
55
|
93 |
|
@include_once 'VersionControl/Git.php'; |
|
56
|
93 |
|
if (false == class_exists('VersionControl_Git')) { |
|
|
|
|
|
|
57
|
|
|
throw new BuildException( |
|
58
|
|
|
"The Git tasks depend on PEAR\'s " |
|
59
|
|
|
. "VersionControl_Git package.", |
|
60
|
|
|
$this->getLocation() |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
93 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Set repository directory |
|
67
|
|
|
* |
|
68
|
|
|
* @param string $repository Repo directory |
|
69
|
|
|
* @return GitBaseTask |
|
70
|
|
|
*/ |
|
71
|
82 |
|
public function setRepository($repository) |
|
72
|
|
|
{ |
|
73
|
82 |
|
$this->repository = $repository; |
|
74
|
|
|
|
|
75
|
82 |
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Get repository directory |
|
80
|
|
|
* |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
94 |
|
public function getRepository() |
|
84
|
|
|
{ |
|
85
|
94 |
|
return $this->repository; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Set path to git executable |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $gitPath New path to git repository |
|
92
|
|
|
* @return GitBaseTask |
|
93
|
|
|
*/ |
|
94
|
81 |
|
public function setGitPath($gitPath) |
|
95
|
|
|
{ |
|
96
|
81 |
|
$this->gitPath = $gitPath; |
|
97
|
|
|
|
|
98
|
81 |
|
return $this; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Get path to git executable |
|
103
|
|
|
* |
|
104
|
|
|
* @return string |
|
105
|
|
|
*/ |
|
106
|
76 |
|
public function getGitPath() |
|
107
|
|
|
{ |
|
108
|
76 |
|
return $this->gitPath; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param bool $reset |
|
113
|
|
|
* @param null $repository |
|
|
|
|
|
|
114
|
|
|
* @return null|VersionControl_Git |
|
115
|
|
|
* @throws BuildException |
|
116
|
|
|
*/ |
|
117
|
77 |
|
protected function getGitClient($reset = false, $repository = null) |
|
118
|
|
|
{ |
|
119
|
77 |
|
$this->gitClient = ($reset === true) ? null : $this->gitClient; |
|
120
|
77 |
|
$repository = $repository ?? $this->getRepository(); |
|
121
|
|
|
|
|
122
|
77 |
|
if (null === $this->gitClient) { |
|
123
|
|
|
try { |
|
124
|
77 |
|
$this->gitClient = new VersionControl_Git($repository); |
|
125
|
3 |
|
} catch (VersionControl_Git_Exception $e) { |
|
126
|
|
|
// re-package |
|
127
|
3 |
|
throw new BuildException( |
|
128
|
3 |
|
'You must specify readable directory as repository.', |
|
129
|
3 |
|
$e |
|
130
|
|
|
); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
75 |
|
$this->gitClient->setGitCommandPath($this->getGitPath()); |
|
134
|
|
|
|
|
135
|
75 |
|
return $this->gitClient; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.