1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* GitElephant - An abstraction layer for git written in PHP |
5
|
|
|
* Copyright (C) 2013 Matteo Giachino |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with this program. If not, see [http://www.gnu.org/licenses/]. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace GitElephant\Command; |
22
|
|
|
|
23
|
|
|
use GitElephant\Objects\Commit; |
24
|
|
|
use GitElephant\Objects\Tag; |
25
|
|
|
use GitElephant\Repository; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* RevList Command generator |
29
|
|
|
* |
30
|
|
|
* @author Matteo Giachino <[email protected]> |
31
|
|
|
*/ |
32
|
|
|
class RevListCommand extends BaseCommand |
33
|
|
|
{ |
34
|
|
|
public const GIT_REVLIST = 'rev-list'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* constructor |
38
|
|
|
* |
39
|
|
|
* @param \GitElephant\Repository $repo The repository object this command |
40
|
|
|
* will interact with |
41
|
|
|
*/ |
42
|
30 |
|
public function __construct(Repository $repo = null) |
43
|
|
|
{ |
44
|
30 |
|
parent::__construct($repo); |
45
|
30 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* get tag commit command via rev-list |
49
|
|
|
* |
50
|
|
|
* @param \GitElephant\Objects\Tag $tag a tag instance |
51
|
|
|
* |
52
|
|
|
* @throws \RuntimeException |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
27 |
|
public function getTagCommit(Tag $tag): string |
56
|
|
|
{ |
57
|
27 |
|
$this->clearAll(); |
58
|
27 |
|
$this->addCommandName(static::GIT_REVLIST); |
59
|
|
|
// only the last commit |
60
|
27 |
|
$this->addCommandArgument('-n1'); |
61
|
27 |
|
$this->addCommandSubject($tag->getFullRef()); |
62
|
|
|
|
63
|
27 |
|
return $this->getCommand(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* get the commits path to the passed commit. Useful to count commits in a repo |
68
|
|
|
* |
69
|
|
|
* @param \GitElephant\Objects\Commit $commit commit instance |
70
|
|
|
* @param int $max max count |
71
|
|
|
* |
72
|
|
|
* @throws \RuntimeException |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
3 |
|
public function commitPath(Commit $commit, $max = 1000): string |
76
|
|
|
{ |
77
|
3 |
|
$this->clearAll(); |
78
|
3 |
|
$this->addCommandName(static::GIT_REVLIST); |
79
|
3 |
|
$this->addCommandArgument(sprintf('--max-count=%s', $max)); |
80
|
3 |
|
$this->addCommandSubject($commit->getSha()); |
81
|
|
|
|
82
|
3 |
|
return $this->getCommand(); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|