|
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\Operator; |
|
13
|
|
|
|
|
14
|
|
|
use SebastianFeldmann\Git\Command\Describe\GetCurrentTag; |
|
15
|
|
|
use SebastianFeldmann\Git\Command\Describe\GetMostRecentTag; |
|
16
|
|
|
use SebastianFeldmann\Git\Command\RevParse\GetBranch; |
|
17
|
|
|
use SebastianFeldmann\Git\Command\RevParse\GetCommitHash; |
|
18
|
|
|
use SebastianFeldmann\Git\Command\Tag\GetTags; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class Info |
|
22
|
|
|
* |
|
23
|
|
|
* @package SebastianFeldmann\Git |
|
24
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
25
|
|
|
* @link https://github.com/sebastianfeldmann/git |
|
26
|
|
|
* @since Class available since Release 1.0.8 |
|
27
|
|
|
*/ |
|
28
|
|
|
class Info extends Base |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Returns the tag of the current commit |
|
32
|
|
|
* |
|
33
|
2 |
|
* @return string |
|
34
|
|
|
*/ |
|
35
|
2 |
|
public function getCurrentTag(): string |
|
36
|
2 |
|
{ |
|
37
|
|
|
$cmd = new GetCurrentTag($this->repo->getRoot()); |
|
38
|
1 |
|
$result = $this->runner->run($cmd); |
|
39
|
|
|
|
|
40
|
|
|
return trim($result->getStdOut()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Returns the most recent tag |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $ignore Unix glob to ignore tags e.g. **-RC* |
|
47
|
1 |
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
1 |
|
public function getMostRecentTag(string $ignore = ''): string |
|
50
|
1 |
|
{ |
|
51
|
|
|
$cmd = new GetMostRecentTag($this->repo->getRoot()); |
|
52
|
1 |
|
$cmd->ignore($ignore); |
|
53
|
|
|
|
|
54
|
1 |
|
$result = $this->runner->run($cmd); |
|
55
|
|
|
|
|
56
|
|
|
return trim($result->getStdOut()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Returns the most recent tag before the given commit |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $hash |
|
63
|
|
|
* @param string $ignore Unix glob to ignore tags e.g. **-RC* |
|
64
|
1 |
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
1 |
|
public function getMostRecentTagBefore(string $hash, string $ignore = ''): string |
|
67
|
1 |
|
{ |
|
68
|
1 |
|
$cmd = new GetMostRecentTag($this->repo->getRoot()); |
|
69
|
|
|
$cmd->ignore($ignore); |
|
70
|
1 |
|
$cmd->before($hash); |
|
71
|
|
|
|
|
72
|
1 |
|
$result = $this->runner->run($cmd); |
|
73
|
|
|
|
|
74
|
|
|
return trim($result->getStdOut()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Returns a list of tags for a given commit hash |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $hash |
|
81
|
1 |
|
* @return string[] |
|
82
|
|
|
*/ |
|
83
|
1 |
|
public function getTagsPointingTo(string $hash): array |
|
84
|
1 |
|
{ |
|
85
|
|
|
$cmd = new GetTags($this->repo->getRoot()); |
|
86
|
1 |
|
$cmd->pointingTo($hash); |
|
87
|
|
|
|
|
88
|
1 |
|
$result = $this->runner->run($cmd); |
|
89
|
|
|
|
|
90
|
|
|
return $result->getBufferedOutput(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Returns the the hash of the current commit |
|
95
|
|
|
* |
|
96
|
1 |
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
1 |
|
public function getCurrentCommitHash(): string |
|
99
|
1 |
|
{ |
|
100
|
|
|
$cmd = new GetCommitHash($this->repo->getRoot()); |
|
101
|
1 |
|
$result = $this->runner->run($cmd); |
|
102
|
|
|
|
|
103
|
|
|
return trim($result->getStdOut()); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Returns the current branch name |
|
108
|
|
|
* |
|
109
|
1 |
|
* @return string |
|
110
|
|
|
*/ |
|
111
|
1 |
|
public function getCurrentBranch(): string |
|
112
|
1 |
|
{ |
|
113
|
|
|
$cmd = new GetBranch($this->repo->getRoot()); |
|
114
|
1 |
|
$result = $this->runner->run($cmd); |
|
115
|
|
|
|
|
116
|
|
|
return trim($result->getStdOut()); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|