-
Notifications
You must be signed in to change notification settings - Fork 1
/
git.php
63 lines (50 loc) · 1.91 KB
/
git.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
59
60
61
62
63
<?php define('_ACCESS_OK', true);
require_once 'init.php';
require_once 'vendor/autoload.php';
$repository = Gitonomy\Git\Admin::init(__DIR__, false);
// echo '<pre>';
// echo $size = $repository->getSize();echo "kb";
$head = $repository->getHead(); // Commit or Reference
$head = $repository->getHeadCommit(); // Commit
if ($repository->isHeadDetached()) {
echo "Sorry man\n";
}
// print_r($head);
$log = $repository->getLog('master');
// $log = $repository->getLog('master', 'vendors/cruzersoftwares/css/style.css', 0, 10);
// print_r($log);
// $revision = $repository->getRevision('master@{12 days ago}');
// Returns 100 lasts commits
// $log = $revision->getLog(null, 10);
$blame = $repository->getBlame('master', 'README.md');
foreach ($blame->getLines() as $lineNumber => $line) {
$commit = $line->getCommit();
echo $lineNumber.': '.$line->getContent()."\r\n";
echo $commit->getMessage();
echo $commit->getAuthorName().' ['.$commit->getAuthorEmail().']'.' on '.$commit->getAuthorDate()->format('d M Y h:iA')."\n";
}
// print_r($log);
// die;
$diff = $repository->getDiff('master@{2 days ago}..master');
$files = $diff->getFiles();
echo sprintf("%s files modified", count($files));echo "<br/>";
// echo '<pre>';
foreach ($files as $file) {
echo sprintf("Old name: (%s) %s\n", $file->getOldMode(), $file->getOldName());echo "<br/>";
echo sprintf("New name: (%s) %s\n", $file->getNewMode(), $file->getNewName());echo "<br/>";
$changes = $file->getChanges();
foreach ($changes as $change) {
foreach ($change->getLines() as $data) {
list ($type, $line) = $data;
if ($type === 0) {
echo ' '.htmlspecialchars($line)."\n";
} elseif ($type === 1) {
echo '+'.htmlspecialchars($line)."\n";
} else {
echo '-'.htmlspecialchars($line)."\n";
}
}
}
}
// print_r($diff);
echo('end');