|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
15
|
|
|
* |
|
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
17
|
|
|
* and is licensed under the LGPL. For more information please see |
|
18
|
|
|
* <http://phing.info>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace Phing\Task\Ext\Git; |
|
22
|
|
|
|
|
23
|
|
|
use Phing\Exception\BuildException; |
|
24
|
|
|
use Phing\Project; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Wrapper around git-tag |
|
28
|
|
|
* |
|
29
|
|
|
* @author Evan Kaufman <[email protected]> |
|
30
|
|
|
* @author Victor Farazdagi <[email protected]> |
|
31
|
|
|
* @package phing.tasks.ext.git |
|
32
|
|
|
* @see VersionControl_Git |
|
33
|
|
|
* @since 2.4.5 |
|
34
|
|
|
*/ |
|
35
|
|
|
class GitTagTask extends GitBaseTask |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* Make unsigned, annotated tag object. See -a of git-tag |
|
39
|
|
|
* |
|
40
|
|
|
* @var boolean |
|
41
|
|
|
*/ |
|
42
|
|
|
private $annotate = false; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Make GPG-signed tag. See -s of git-tag |
|
46
|
|
|
* |
|
47
|
|
|
* @var boolean |
|
48
|
|
|
*/ |
|
49
|
|
|
private $sign = false; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Make GPG-signed tag, using given key. See -u of git-tag |
|
53
|
|
|
* |
|
54
|
|
|
* @var string |
|
55
|
|
|
*/ |
|
56
|
|
|
private $keySign; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Replace existing tag with given name. See -f of git-tag |
|
60
|
|
|
* |
|
61
|
|
|
* @var boolean |
|
62
|
|
|
*/ |
|
63
|
|
|
private $replace = false; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Delete existing tags with given names. See -d of git-tag |
|
67
|
|
|
* |
|
68
|
|
|
* @var boolean |
|
69
|
|
|
*/ |
|
70
|
|
|
private $delete = false; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Verify gpg signature of given tag names. See -v of git-tag |
|
74
|
|
|
* |
|
75
|
|
|
* @var boolean |
|
76
|
|
|
*/ |
|
77
|
|
|
private $verify = false; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* List tags with names matching given pattern. See -l of git-tag |
|
81
|
|
|
* |
|
82
|
|
|
* @var boolean |
|
83
|
|
|
*/ |
|
84
|
|
|
private $list = false; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* <num> specifies how many lines from the annotation, if any, are printed |
|
88
|
|
|
* when using -l. See -n of git-tag |
|
89
|
|
|
* |
|
90
|
|
|
* @var int |
|
91
|
|
|
*/ |
|
92
|
|
|
private $num; |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Only list tags containing specified commit. See --contains of git-tag |
|
96
|
|
|
* |
|
97
|
|
|
* @var string |
|
98
|
|
|
*/ |
|
99
|
|
|
private $contains; |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Use given tag message. See -m of git-tag |
|
103
|
|
|
* |
|
104
|
|
|
* @var string |
|
105
|
|
|
*/ |
|
106
|
|
|
private $message; |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Take tag message from given file. See -F of git-tag |
|
110
|
|
|
* |
|
111
|
|
|
* @var string |
|
112
|
|
|
*/ |
|
113
|
|
|
private $file; |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* <tagname> argument to git-tag |
|
117
|
|
|
* |
|
118
|
|
|
* @var string |
|
119
|
|
|
*/ |
|
120
|
|
|
private $name; |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* <commit> argument to git-tag |
|
124
|
|
|
* |
|
125
|
|
|
* @var string |
|
126
|
|
|
*/ |
|
127
|
|
|
private $commit; |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* <object> argument to git-tag |
|
131
|
|
|
* |
|
132
|
|
|
* @var string |
|
133
|
|
|
*/ |
|
134
|
|
|
private $object; |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* <pattern> argument to git-tag |
|
138
|
|
|
* |
|
139
|
|
|
* @var string |
|
140
|
|
|
*/ |
|
141
|
|
|
private $pattern; |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Property name to set with output value from git-tag |
|
145
|
|
|
* |
|
146
|
|
|
* @var string |
|
147
|
|
|
*/ |
|
148
|
|
|
private $outputProperty; |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* The main entry point for the task |
|
152
|
|
|
*/ |
|
153
|
15 |
|
public function main() |
|
154
|
|
|
{ |
|
155
|
15 |
|
if (null === $this->getRepository()) { |
|
|
|
|
|
|
156
|
1 |
|
throw new BuildException('"repository" is required parameter'); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
14 |
|
$client = $this->getGitClient(false, $this->getRepository()); |
|
160
|
14 |
|
$command = $client->getCommand('tag'); |
|
161
|
14 |
|
$command |
|
162
|
14 |
|
->setOption('a', $this->isAnnotate()) |
|
163
|
14 |
|
->setOption('s', $this->isSign()) |
|
164
|
14 |
|
->setOption('f', $this->isReplace()) |
|
165
|
14 |
|
->setOption('d', $this->isDelete()) |
|
166
|
14 |
|
->setOption('v', $this->isVerify()) |
|
167
|
14 |
|
->setOption('l', $this->isList()); |
|
168
|
|
|
|
|
169
|
14 |
|
if (null !== $this->getKeySign()) { |
|
|
|
|
|
|
170
|
|
|
$command->setOption('u', $this->getKeySign()); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
14 |
|
if (null !== $this->getMessage()) { |
|
|
|
|
|
|
174
|
2 |
|
$command->setOption('m', $this->getMessage()); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
14 |
|
if (null !== $this->getFile()) { |
|
|
|
|
|
|
178
|
1 |
|
$command->setOption('F', $this->getFile()); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
// Use 'name' arg, if relevant |
|
182
|
14 |
|
if (null != $this->getName() && false == $this->isList()) { |
|
|
|
|
|
|
183
|
14 |
|
$command->addArgument($this->getName()); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
14 |
|
if (null !== $this->getKeySign() || $this->isAnnotate() || $this->isSign()) { |
|
|
|
|
|
|
187
|
|
|
// Require a tag message or file |
|
188
|
2 |
|
if (null === $this->getMessage() && null === $this->getFile()) { |
|
|
|
|
|
|
189
|
1 |
|
throw new BuildException('"message" or "file" required to make a tag'); |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
// Use 'commit' or 'object' args, if relevant |
|
194
|
13 |
|
if (null !== $this->getCommit()) { |
|
|
|
|
|
|
195
|
1 |
|
$command->addArgument($this->getCommit()); |
|
196
|
|
|
} else { |
|
197
|
12 |
|
if (null !== $this->getObject()) { |
|
198
|
1 |
|
$command->addArgument($this->getObject()); |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
// Customize list (-l) options |
|
203
|
13 |
|
if ($this->isList()) { |
|
204
|
9 |
|
if (null !== $this->getContains()) { |
|
|
|
|
|
|
205
|
|
|
$command->setOption('contains', $this->getContains()); |
|
206
|
|
|
} |
|
207
|
9 |
|
if (null !== $this->getPattern()) { |
|
|
|
|
|
|
208
|
2 |
|
$command->addArgument($this->getPattern()); |
|
209
|
|
|
} |
|
210
|
9 |
|
if (null != $this->getNum()) { |
|
211
|
1 |
|
$command->setOption('n', $this->getNum()); |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
13 |
|
$this->log('git-tag command: ' . $command->createCommandString(), Project::MSG_INFO); |
|
216
|
|
|
|
|
217
|
|
|
try { |
|
218
|
13 |
|
$output = $command->execute(); |
|
219
|
1 |
|
} catch (\Exception $e) { |
|
220
|
1 |
|
$this->log($e->getMessage(), Project::MSG_ERR); |
|
221
|
1 |
|
throw new BuildException('Task execution failed. ' . $e->getMessage()); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
13 |
|
if (null !== $this->outputProperty) { |
|
225
|
1 |
|
$this->project->setProperty($this->outputProperty, trim($output)); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
13 |
|
$this->log( |
|
229
|
13 |
|
sprintf('git-tag: tags for "%s" repository', $this->getRepository()), |
|
230
|
13 |
|
Project::MSG_INFO |
|
231
|
13 |
|
); |
|
232
|
13 |
|
$this->log('git-tag output: ' . trim($output), Project::MSG_INFO); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* @param $flag |
|
237
|
|
|
*/ |
|
238
|
2 |
|
public function setAnnotate(bool $flag) |
|
239
|
|
|
{ |
|
240
|
2 |
|
$this->annotate = $flag; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* @return bool |
|
245
|
|
|
*/ |
|
246
|
14 |
|
public function getAnnotate() |
|
247
|
|
|
{ |
|
248
|
14 |
|
return $this->annotate; |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* @return bool |
|
253
|
|
|
*/ |
|
254
|
14 |
|
public function isAnnotate() |
|
255
|
|
|
{ |
|
256
|
14 |
|
return $this->getAnnotate(); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* @param $flag |
|
261
|
|
|
*/ |
|
262
|
|
|
public function setSign(bool $flag) |
|
263
|
|
|
{ |
|
264
|
|
|
$this->sign = $flag; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* @return bool |
|
269
|
|
|
*/ |
|
270
|
14 |
|
public function getSign() |
|
271
|
|
|
{ |
|
272
|
14 |
|
return $this->sign; |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
/** |
|
276
|
|
|
* @return bool |
|
277
|
|
|
*/ |
|
278
|
14 |
|
public function isSign() |
|
279
|
|
|
{ |
|
280
|
14 |
|
return $this->getSign(); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* @param $keyId |
|
285
|
|
|
*/ |
|
286
|
|
|
public function setKeySign($keyId) |
|
287
|
|
|
{ |
|
288
|
|
|
$this->keySign = $keyId; |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
/** |
|
292
|
|
|
* @return string |
|
293
|
|
|
*/ |
|
294
|
14 |
|
public function getKeySign() |
|
295
|
|
|
{ |
|
296
|
14 |
|
return $this->keySign; |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
/** |
|
300
|
|
|
* @param $flag |
|
301
|
|
|
*/ |
|
302
|
2 |
|
public function setReplace(bool $flag) |
|
303
|
|
|
{ |
|
304
|
2 |
|
$this->replace = $flag; |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
/** |
|
308
|
|
|
* @return bool |
|
309
|
|
|
*/ |
|
310
|
14 |
|
public function getReplace() |
|
311
|
|
|
{ |
|
312
|
14 |
|
return $this->replace; |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
/** |
|
316
|
|
|
* @return bool |
|
317
|
|
|
*/ |
|
318
|
14 |
|
public function isReplace() |
|
319
|
|
|
{ |
|
320
|
14 |
|
return $this->getReplace(); |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
/** |
|
324
|
|
|
* @param $flag |
|
325
|
|
|
*/ |
|
326
|
1 |
|
public function setForce(bool $flag) |
|
327
|
|
|
{ |
|
328
|
1 |
|
return $this->setReplace($flag); |
|
|
|
|
|
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
/** |
|
332
|
|
|
* @param $flag |
|
333
|
|
|
*/ |
|
334
|
1 |
|
public function setDelete(bool $flag) |
|
335
|
|
|
{ |
|
336
|
1 |
|
$this->delete = $flag; |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
/** |
|
340
|
|
|
* @return bool |
|
341
|
|
|
*/ |
|
342
|
14 |
|
public function getDelete() |
|
343
|
|
|
{ |
|
344
|
14 |
|
return $this->delete; |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
/** |
|
348
|
|
|
* @return bool |
|
349
|
|
|
*/ |
|
350
|
14 |
|
public function isDelete() |
|
351
|
|
|
{ |
|
352
|
14 |
|
return $this->getDelete(); |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* @param $flag |
|
357
|
|
|
*/ |
|
358
|
|
|
public function setVerify(bool $flag) |
|
359
|
|
|
{ |
|
360
|
|
|
$this->verify = $flag; |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
/** |
|
364
|
|
|
* @return bool |
|
365
|
|
|
*/ |
|
366
|
14 |
|
public function getVerify() |
|
367
|
|
|
{ |
|
368
|
14 |
|
return $this->verify; |
|
369
|
|
|
} |
|
370
|
|
|
|
|
371
|
|
|
/** |
|
372
|
|
|
* @return bool |
|
373
|
|
|
*/ |
|
374
|
14 |
|
public function isVerify() |
|
375
|
|
|
{ |
|
376
|
14 |
|
return $this->getVerify(); |
|
377
|
|
|
} |
|
378
|
|
|
|
|
379
|
|
|
/** |
|
380
|
|
|
* @param $flag |
|
381
|
|
|
*/ |
|
382
|
9 |
|
public function setList(bool $flag) |
|
383
|
|
|
{ |
|
384
|
9 |
|
$this->list = $flag; |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
/** |
|
388
|
|
|
* @return bool |
|
389
|
|
|
*/ |
|
390
|
14 |
|
public function getList() |
|
391
|
|
|
{ |
|
392
|
14 |
|
return $this->list; |
|
393
|
|
|
} |
|
394
|
|
|
|
|
395
|
|
|
/** |
|
396
|
|
|
* @return bool |
|
397
|
|
|
*/ |
|
398
|
14 |
|
public function isList() |
|
399
|
|
|
{ |
|
400
|
14 |
|
return $this->getList(); |
|
401
|
|
|
} |
|
402
|
|
|
|
|
403
|
|
|
/** |
|
404
|
|
|
* @param $num |
|
405
|
|
|
*/ |
|
406
|
1 |
|
public function setNum($num) |
|
407
|
|
|
{ |
|
408
|
1 |
|
$this->num = (int) $num; |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
/** |
|
412
|
|
|
* @return int |
|
413
|
|
|
*/ |
|
414
|
9 |
|
public function getNum() |
|
415
|
|
|
{ |
|
416
|
9 |
|
return $this->num; |
|
417
|
|
|
} |
|
418
|
|
|
|
|
419
|
|
|
/** |
|
420
|
|
|
* @param $commit |
|
421
|
|
|
*/ |
|
422
|
|
|
public function setContains($commit) |
|
423
|
|
|
{ |
|
424
|
|
|
$this->contains = $commit; |
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
|
/** |
|
428
|
|
|
* @return string |
|
429
|
|
|
*/ |
|
430
|
9 |
|
public function getContains() |
|
431
|
|
|
{ |
|
432
|
9 |
|
return $this->contains; |
|
433
|
|
|
} |
|
434
|
|
|
|
|
435
|
|
|
/** |
|
436
|
|
|
* @param $msg |
|
437
|
|
|
*/ |
|
438
|
2 |
|
public function setMessage($msg) |
|
439
|
|
|
{ |
|
440
|
2 |
|
$this->message = $msg; |
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
/** |
|
444
|
|
|
* @return string |
|
445
|
|
|
*/ |
|
446
|
14 |
|
public function getMessage() |
|
447
|
|
|
{ |
|
448
|
14 |
|
return $this->message; |
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
/** |
|
452
|
|
|
* @param $file |
|
453
|
|
|
*/ |
|
454
|
1 |
|
public function setFile($file) |
|
455
|
|
|
{ |
|
456
|
1 |
|
$this->file = $file; |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
/** |
|
460
|
|
|
* @return string |
|
461
|
|
|
*/ |
|
462
|
14 |
|
public function getFile() |
|
463
|
|
|
{ |
|
464
|
14 |
|
return $this->file; |
|
465
|
|
|
} |
|
466
|
|
|
|
|
467
|
|
|
/** |
|
468
|
|
|
* @param $name |
|
469
|
|
|
*/ |
|
470
|
14 |
|
public function setName($name) |
|
471
|
|
|
{ |
|
472
|
14 |
|
$this->name = $name; |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
/** |
|
476
|
|
|
* @return string |
|
477
|
|
|
*/ |
|
478
|
14 |
|
public function getName() |
|
479
|
|
|
{ |
|
480
|
14 |
|
return $this->name; |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
/** |
|
484
|
|
|
* @param $commit |
|
485
|
|
|
*/ |
|
486
|
1 |
|
public function setCommit($commit) |
|
487
|
|
|
{ |
|
488
|
1 |
|
$this->commit = $commit; |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
/** |
|
492
|
|
|
* @return string |
|
493
|
|
|
*/ |
|
494
|
13 |
|
public function getCommit() |
|
495
|
|
|
{ |
|
496
|
13 |
|
return $this->commit; |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
/** |
|
500
|
|
|
* @param $object |
|
501
|
|
|
*/ |
|
502
|
1 |
|
public function setObject($object) |
|
503
|
|
|
{ |
|
504
|
1 |
|
$this->object = $object; |
|
505
|
|
|
} |
|
506
|
|
|
|
|
507
|
|
|
/** |
|
508
|
|
|
* @return string |
|
509
|
|
|
*/ |
|
510
|
12 |
|
public function getObject() |
|
511
|
|
|
{ |
|
512
|
12 |
|
return $this->object; |
|
513
|
|
|
} |
|
514
|
|
|
|
|
515
|
|
|
/** |
|
516
|
|
|
* @param $pattern |
|
517
|
|
|
*/ |
|
518
|
2 |
|
public function setPattern($pattern) |
|
519
|
|
|
{ |
|
520
|
2 |
|
$this->pattern = $pattern; |
|
521
|
|
|
} |
|
522
|
|
|
|
|
523
|
|
|
/** |
|
524
|
|
|
* @return string |
|
525
|
|
|
*/ |
|
526
|
9 |
|
public function getPattern() |
|
527
|
|
|
{ |
|
528
|
9 |
|
return $this->pattern; |
|
529
|
|
|
} |
|
530
|
|
|
|
|
531
|
|
|
/** |
|
532
|
|
|
* @param $prop |
|
533
|
|
|
*/ |
|
534
|
1 |
|
public function setOutputProperty($prop) |
|
535
|
|
|
{ |
|
536
|
1 |
|
$this->outputProperty = $prop; |
|
537
|
|
|
} |
|
538
|
|
|
} |
|
539
|
|
|
|