/usr/share/php/SebastianBergmann/Git/Git.php is in phpunit-git 2.1.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | <?php
/*
* This file is part of Git.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Git;
use DateTime;
/**
*/
class Git
{
/**
* @var string
*/
private $repositoryPath;
/**
* @param string $repositoryPath
*/
public function __construct($repositoryPath)
{
if (!is_dir($repositoryPath)) {
throw new RuntimeException(
sprintf(
'Directory "%s" does not exist',
$repositoryPath
)
);
}
$this->repositoryPath = realpath($repositoryPath);
}
/**
* @param string $revision
*/
public function checkout($revision)
{
$this->execute(
'checkout --force --quiet ' . $revision . ' 2>&1'
);
}
/**
* @return string
*/
public function getCurrentBranch()
{
$output = $this->execute('symbolic-ref --short HEAD');
return $output[0];
}
/**
* @param string $from
* @param string $to
* @return string
*/
public function getDiff($from, $to)
{
$output = $this->execute(
'diff --no-ext-diff ' . $from . ' ' . $to
);
return implode("\n", $output);
}
/**
* @return array
*/
public function getRevisions()
{
$output = $this->execute(
'log --no-merges --date-order --reverse --format=medium'
);
$numLines = count($output);
$revisions = array();
for ($i = 0; $i < $numLines; $i++) {
$tmp = explode(' ', $output[$i]);
if ($tmp[0] == 'commit') {
$sha1 = $tmp[1];
} elseif ($tmp[0] == 'Author:') {
$author = implode(' ', array_slice($tmp, 1));
} elseif ($tmp[0] == 'Date:' && isset($author) && isset($sha1)) {
$revisions[] = array(
'author' => $author,
'date' => DateTime::createFromFormat(
'D M j H:i:s Y O',
implode(' ', array_slice($tmp, 3))
),
'sha1' => $sha1,
'message' => isset($output[$i+2]) ? trim($output[$i+2]) : ''
);
unset($author);
unset($sha1);
}
}
return $revisions;
}
/**
* @return bool
*/
public function isWorkingCopyClean()
{
$output = $this->execute('status');
return $output[count($output)-1] == 'nothing to commit, working directory clean';
}
/**
* @param string $command
* @throws RuntimeException
*/
protected function execute($command)
{
$command = 'git -C ' . escapeshellarg($this->repositoryPath) . ' ' . $command;
if (DIRECTORY_SEPARATOR == '/') {
$command = 'LC_ALL=en_US.UTF-8 ' . $command;
}
exec($command, $output, $returnValue);
if ($returnValue !== 0) {
throw new RuntimeException(implode("\r\n", $output));
}
return $output;
}
}
|