1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of SebastianFeldmann\Git. |
5
|
|
|
* |
6
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace SebastianFeldmann\Git\Command\Describe; |
13
|
|
|
|
14
|
|
|
use SebastianFeldmann\Git\Command\Base; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class GetCurrentTag |
18
|
|
|
* |
19
|
|
|
* @package SebastianFeldmann\Git |
20
|
|
|
* @author Sebastian Feldmann <[email protected]> |
21
|
|
|
* @link https://github.com/sebastianfeldmann/git |
22
|
|
|
* @since Class available since Release 1.0.8 |
23
|
|
|
*/ |
24
|
|
|
class GetMostRecentTag extends Base |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $before; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Glob to define excluded tags e.g **-RC* to exclude release candidate tags |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $exclude; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Sets the start point to search for a tag |
39
|
|
|
* |
40
|
|
|
* @param string $hash |
41
|
2 |
|
* @return \SebastianFeldmann\Git\Command\Describe\GetMostRecentTag |
42
|
|
|
*/ |
43
|
2 |
|
public function before(string $hash): GetMostRecentTag |
44
|
|
|
{ |
45
|
2 |
|
$this->before = $hash; |
46
|
|
|
|
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Glob of tags to ignore e.g. **-RC* to ignore release candidate tags like '1.0.0-RC3' |
52
|
|
|
* |
53
|
|
|
* @param string $glob |
54
|
3 |
|
* @return \SebastianFeldmann\Git\Command\Describe\GetMostRecentTag |
55
|
|
|
*/ |
56
|
3 |
|
public function ignore(string $glob): GetMostRecentTag |
57
|
3 |
|
{ |
58
|
|
|
$this->exclude = $glob; |
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Return the command to execute. |
64
|
|
|
* |
65
|
3 |
|
* @return string |
66
|
|
|
*/ |
67
|
3 |
|
protected function getGitCommand(): string |
68
|
|
|
{ |
69
|
|
|
return 'describe --tags --abbrev=0' . $this->tagsToIgnore() . $this->startingPoint(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Return the --exclude='xxx' option |
74
|
|
|
* |
75
|
3 |
|
* @return string |
76
|
|
|
*/ |
77
|
3 |
|
private function tagsToIgnore(): string |
78
|
|
|
{ |
79
|
|
|
return empty($this->exclude) ? '' : ' --exclude=' . escapeshellarg($this->exclude); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Return the starting point where to start the search for a tag |
84
|
|
|
* |
85
|
3 |
|
* @return string |
86
|
|
|
*/ |
87
|
3 |
|
private function startingPoint(): string |
88
|
|
|
{ |
89
|
|
|
return empty($this->before) ? '' : ' ' . $this->before . '^'; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|