Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
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 |
* Wrapper around git-describe
|
|
22 |
*
|
|
23 |
* @package phing.tasks.ext.git
|
|
24 |
* @author Siad Ardroumli <siad.ardroumli@gmail.com>
|
|
25 |
* @see VersionControl_Git
|
|
26 |
*/
|
|
27 |
class GitDescribeTask extends GitBaseTask |
|
28 |
{
|
|
29 |
/**
|
|
30 |
* Use any ref found in .git/refs/. See --all of git-describe
|
|
31 |
*
|
|
32 |
* @var boolean
|
|
33 |
*/
|
|
34 |
private $all = false; |
|
35 |
|
|
36 |
/**
|
|
37 |
* Use any tag found in .git/refs/tags. See --tags of git-describe
|
|
38 |
*
|
|
39 |
* @var boolean
|
|
40 |
*/
|
|
41 |
private $tags = false; |
|
42 |
|
|
43 |
/**
|
|
44 |
* Find tag that contains the commit. See --contains of git-describe
|
|
45 |
*
|
|
46 |
* @var boolean
|
|
47 |
*/
|
|
48 |
private $contains = false; |
|
49 |
|
|
50 |
/**
|
|
51 |
* Use <n> digit object name. See --abbrev of git-describe
|
|
52 |
*
|
|
53 |
* @var integer
|
|
54 |
*/
|
|
55 |
private $abbrev; |
|
56 |
|
|
57 |
/**
|
|
58 |
* Consider up to <n> most recent tags. See --candidates of git-describe
|
|
59 |
*
|
|
60 |
* @var integer
|
|
61 |
*/
|
|
62 |
private $candidates; |
|
63 |
|
|
64 |
/**
|
|
65 |
* Always output the long format. See --long of git-describe
|
|
66 |
*
|
|
67 |
* @var boolean
|
|
68 |
*/
|
|
69 |
private $long = false; |
|
70 |
|
|
71 |
/**
|
|
72 |
* Only consider tags matching the given pattern. See --match of git-describe
|
|
73 |
*
|
|
74 |
* @var string
|
|
75 |
*/
|
|
76 |
private $match; |
|
77 |
|
|
78 |
/**
|
|
79 |
* Show uniquely abbreviated commit object as fallback. See --always of git-describe
|
|
80 |
*
|
|
81 |
* @var boolean
|
|
82 |
*/
|
|
83 |
private $always = false; |
|
84 |
|
|
85 |
/**
|
|
86 |
* <committish> argument to git-describe
|
|
87 |
*
|
|
88 |
* @var string
|
|
89 |
*/
|
|
90 |
private $committish; |
|
91 |
|
|
92 |
/**
|
|
93 |
* Property name to set with output value from git-describe
|
|
94 |
*
|
|
95 |
* @var string
|
|
96 |
*/
|
|
97 |
private $outputProperty; |
|
98 |
|
|
99 |
/**
|
|
100 |
* The main entry point for the task
|
|
101 |
*/
|
|
102 | 1 |
public function main() |
103 |
{
|
|
104 | 1 |
if (null === $this->getRepository()) { |
105 |
throw new BuildException('"repository" is required parameter'); |
|
106 |
}
|
|
107 |
|
|
108 | 1 |
$client = $this->getGitClient(false, $this->getRepository()); |
109 | 1 |
$command = $client->getCommand('describe'); |
110 |
$command
|
|
111 | 1 |
->setOption('all', $this->isAll()) |
112 | 1 |
->setOption('tags', $this->isTags()) |
113 | 1 |
->setOption('contains', $this->isContains()) |
114 | 1 |
->setOption('long', $this->isLong()) |
115 | 1 |
->setOption('always', $this->isAlways()); |
116 |
|
|
117 | 1 |
if (null !== $this->getAbbrev()) { |
118 |
$command->setOption('abbrev', $this->getAbbrev()); |
|
119 |
}
|
|
120 | 1 |
if (null !== $this->getCandidates()) { |
121 |
$command->setOption('candidates', $this->getCandidates()); |
|
122 |
}
|
|
123 | 1 |
if (null !== $this->getMatch()) { |
124 |
$command->setOption('match', $this->getMatch()); |
|
125 |
}
|
|
126 | 1 |
if (null !== $this->getCommittish()) { |
127 |
$command->addArgument($this->getCommittish()); |
|
128 |
}
|
|
129 |
|
|
130 |
try { |
|
131 | 1 |
$output = $command->execute(); |
132 |
} catch (Exception $e) { |
|
133 |
throw new BuildException('Task execution failed'); |
|
134 |
}
|
|
135 |
|
|
136 | 1 |
if (null !== $this->outputProperty) { |
137 |
$this->project->setProperty($this->outputProperty, $output); |
|
138 |
}
|
|
139 |
|
|
140 | 1 |
$this->log( |
141 | 1 |
sprintf('git-describe: recent tags for "%s" repository', $this->getRepository()), |
142 | 1 |
Project::MSG_INFO |
143 |
);
|
|
144 | 1 |
$this->log('git-describe output: ' . trim($output), Project::MSG_INFO); |
145 |
}
|
|
146 |
|
|
147 |
/**
|
|
148 |
* @param $flag
|
|
149 |
*/
|
|
150 |
public function setAll(bool $flag) |
|
151 |
{
|
|
152 |
$this->all = $flag; |
|
153 |
}
|
|
154 |
|
|
155 |
/**
|
|
156 |
* @return bool
|
|
157 |
*/
|
|
158 | 1 |
public function getAll() |
159 |
{
|
|
160 | 1 |
return $this->all; |
161 |
}
|
|
162 |
|
|
163 |
/**
|
|
164 |
* @return bool
|
|
165 |
*/
|
|
166 | 1 |
public function isAll() |
167 |
{
|
|
168 | 1 |
return $this->getAll(); |
169 |
}
|
|
170 |
|
|
171 |
/**
|
|
172 |
* @param $flag
|
|
173 |
*/
|
|
174 | 1 |
public function setTags(bool $flag) |
175 |
{
|
|
176 | 1 |
$this->tags = $flag; |
177 |
}
|
|
178 |
|
|
179 |
/**
|
|
180 |
* @return bool
|
|
181 |
*/
|
|
182 | 1 |
public function getTags() |
183 |
{
|
|
184 | 1 |
return $this->tags; |
185 |
}
|
|
186 |
|
|
187 |
/**
|
|
188 |
* @return bool
|
|
189 |
*/
|
|
190 | 1 |
public function isTags() |
191 |
{
|
|
192 | 1 |
return $this->getTags(); |
193 |
}
|
|
194 |
|
|
195 |
/**
|
|
196 |
* @param $flag
|
|
197 |
*/
|
|
198 |
public function setContains(bool $flag) |
|
199 |
{
|
|
200 |
$this->contains = $flag; |
|
201 |
}
|
|
202 |
|
|
203 |
/**
|
|
204 |
* @return bool
|
|
205 |
*/
|
|
206 | 1 |
public function getContains() |
207 |
{
|
|
208 | 1 |
return $this->contains; |
209 |
}
|
|
210 |
|
|
211 |
/**
|
|
212 |
* @return bool
|
|
213 |
*/
|
|
214 | 1 |
public function isContains() |
215 |
{
|
|
216 | 1 |
return $this->getContains(); |
217 |
}
|
|
218 |
|
|
219 |
/**
|
|
220 |
* @param $length
|
|
221 |
*/
|
|
222 |
public function setAbbrev($length) |
|
223 |
{
|
|
224 |
$this->abbrev = (int) $length; |
|
225 |
}
|
|
226 |
|
|
227 |
/**
|
|
228 |
* @return int
|
|
229 |
*/
|
|
230 | 1 |
public function getAbbrev() |
231 |
{
|
|
232 | 1 |
return $this->abbrev; |
233 |
}
|
|
234 |
|
|
235 |
/**
|
|
236 |
* @param $count
|
|
237 |
*/
|
|
238 |
public function setCandidates($count) |
|
239 |
{
|
|
240 |
$this->candidates = (int) $count; |
|
241 |
}
|
|
242 |
|
|
243 |
/**
|
|
244 |
* @return int
|
|
245 |
*/
|
|
246 | 1 |
public function getCandidates() |
247 |
{
|
|
248 | 1 |
return $this->candidates; |
249 |
}
|
|
250 |
|
|
251 |
/**
|
|
252 |
* @param $flag
|
|
253 |
*/
|
|
254 |
public function setLong(bool $flag) |
|
255 |
{
|
|
256 |
$this->long = $flag; |
|
257 |
}
|
|
258 |
|
|
259 |
/**
|
|
260 |
* @return bool
|
|
261 |
*/
|
|
262 | 1 |
public function getLong() |
263 |
{
|
|
264 | 1 |
return $this->long; |
265 |
}
|
|
266 |
|
|
267 |
/**
|
|
268 |
* @return bool
|
|
269 |
*/
|
|
270 | 1 |
public function isLong() |
271 |
{
|
|
272 | 1 |
return $this->getLong(); |
273 |
}
|
|
274 |
|
|
275 |
/**
|
|
276 |
* @param $pattern
|
|
277 |
*/
|
|
278 |
public function setMatch($pattern) |
|
279 |
{
|
|
280 |
$this->match = $pattern; |
|
281 |
}
|
|
282 |
|
|
283 |
/**
|
|
284 |
* @return string
|
|
285 |
*/
|
|
286 | 1 |
public function getMatch() |
287 |
{
|
|
288 | 1 |
return $this->match; |
289 |
}
|
|
290 |
|
|
291 |
/**
|
|
292 |
* @param $flag
|
|
293 |
*/
|
|
294 |
public function setAlways(bool $flag) |
|
295 |
{
|
|
296 |
$this->always = $flag; |
|
297 |
}
|
|
298 |
|
|
299 |
/**
|
|
300 |
* @return bool
|
|
301 |
*/
|
|
302 | 1 |
public function getAlways() |
303 |
{
|
|
304 | 1 |
return $this->always; |
305 |
}
|
|
306 |
|
|
307 |
/**
|
|
308 |
* @return bool
|
|
309 |
*/
|
|
310 | 1 |
public function isAlways() |
311 |
{
|
|
312 | 1 |
return $this->getAlways(); |
313 |
}
|
|
314 |
|
|
315 |
/**
|
|
316 |
* @param $object
|
|
317 |
*/
|
|
318 |
public function setCommittish($object) |
|
319 |
{
|
|
320 |
$this->committish = $object; |
|
321 |
}
|
|
322 |
|
|
323 |
/**
|
|
324 |
* @return string
|
|
325 |
*/
|
|
326 | 1 |
public function getCommittish() |
327 |
{
|
|
328 | 1 |
return $this->committish; |
329 |
}
|
|
330 |
|
|
331 |
/**
|
|
332 |
* @param string $prop
|
|
333 |
*/
|
|
334 |
public function setOutputProperty($prop) |
|
335 |
{
|
|
336 |
$this->outputProperty = $prop; |
|
337 |
}
|
|
338 |
}
|
Read our documentation on viewing source code .