-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathGitCommand.php
58 lines (48 loc) · 1.19 KB
/
GitCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace CodeClimate\PhpTestReporter\System\Git;
use Satooshi\Component\System\SystemCommand;
class GitCommand extends SystemCommand
{
protected $commandPath = 'git';
/**
* @return GitInfoInterface
*/
public function getGitInfo()
{
return new GitInfo(
$this->getHead(),
$this->getBranch(),
$this->getCommittedAt()
);
}
/**
* @return string
*/
private function getHead()
{
$command = $this->createCommand("log -1 --pretty=format:'%H'");
return current($this->executeCommand($command));
}
/**
* @return string|null
*/
private function getBranch()
{
$command = $this->createCommand("branch");
$branches = $this->executeCommand($command);
foreach ($branches as $branch) {
if ($branch[0] == "*") {
return str_replace("* ", "", $branch);
}
}
return null;
}
/**
* @return int
*/
private function getCommittedAt()
{
$command = $this->createCommand("log -1 --pretty=format:'%ct'");
return (int)current($this->executeCommand($command));
}
}