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