Skip to content

Commit aa2195b

Browse files
author
Jan Drábek
committed
First version
1 parent 60d5a95 commit aa2195b

File tree

3 files changed

+104
-2
lines changed

3 files changed

+104
-2
lines changed

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1-
tracy-gitversion-panel
1+
Git Version Panel
22
======================
33

4-
Debugger panel for Tracy
4+
Panel for Tracy debug panel.
5+
Shows current branch and current revision hash to be able identify your deployed version on sight.
6+
7+
Inspired by https://gist.github.com/vvondra/3645108.
8+
9+
Installing
10+
----------
11+
12+
Install library via composer:
13+
14+
```
15+
composer require jandrabek/tracy-gitversion-panel
16+
```
17+
18+
Register panel
19+
20+
```
21+
nette:
22+
debugger:
23+
bar: [JanDrabek\Tracy\GitVersionPanel]
24+
# Or when you register multiple extensions
25+
# bar:
26+
# - JanDrabek\Tracy\GitVersionPanel
27+
```

composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": “jandrabek/tracy-gitversion-panel",
3+
"description": “Tracy DebugBar panel displaying current project git branch.",
4+
"keywords": ["nette", "debug", "git", "branch", "log"],
5+
"license": ["BSD-3"],
6+
"authors": [
7+
{
8+
"name": "Vojtěch Vondra",
9+
"homepage": "http://www.vojtechvondra.cz"
10+
},
11+
{
12+
"name": "Jan Drábek",
13+
"homepage": "http://www.jandrabek.cz"
14+
}
15+
],
16+
"require": {
17+
"php": ">=5.3.2",
18+
"nette/tracy": ">=2.2"
19+
},
20+
"autoload": {
21+
"psr-4": { "JanDrabek\\Tracy\\”: "src/" }
22+
}
23+
}

src/GitVersionPanel.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace JanDrabek\Tracy;
4+
use Tracy\IBarPanel;
5+
6+
/**
7+
* Panel showing branch and commit hash of this branch to be able identify deployed version.
8+
*
9+
* @author Jan Drábek
10+
* @author Vojtěch Vondra
11+
*/
12+
class GitVersionPanel implements IBarPanel
13+
{
14+
15+
public function getPanel()
16+
{
17+
return '';
18+
}
19+
20+
protected function getCurrentBranchName()
21+
{
22+
$scriptPath = $_SERVER['SCRIPT_FILENAME'];
23+
24+
$dir = realpath(dirname($scriptPath));
25+
while ($dir !== false && !is_dir($dir . '/.git')) {
26+
flush();
27+
$currentDir = $dir;
28+
$dir .= '/..';
29+
$dir = realpath($dir);
30+
31+
// Stop recursion to parent on root directory
32+
if ($dir == $currentDir) {
33+
break;
34+
}
35+
}
36+
37+
$head = $dir . '/.git/HEAD';
38+
if ($dir && is_readable($head)) {
39+
$branch = file_get_contents($head);
40+
if (strpos($branch, 'ref:') === 0) {
41+
$parts = explode('/', $branch);
42+
return $parts[2];
43+
}
44+
return '(' . substr($branch, 0, 7) . '&hellip;)';
45+
}
46+
47+
return 'not versioned';
48+
}
49+
50+
public function getTab()
51+
{
52+
return '<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAedJREFUeNqMk79LXEEQx+e8FyKIGAKBNCKxiXiIP4r8EB9iEUFFSKFgDPkDrjpLi3QhfYSApSAoop34I4WNXAoVq9icheH8dXLxok9Ofd6+3Vtnxn2PxzuiGfgwszO735vZtxf7Mv8BIlZn/AU8YJ+HZ6FKKQUhPsVjlkNQHKlVQGYpKX3BAStuTb9rHeLFyvbMtFTyDMPl+7qokp4EpKus9FJPy3u4EXmGYspRzeypgAU8z4tLqdJ2oh/KugjO1R+GYspRjfYgEIVH8ISgYezVjbkk+lG77Q0X1rbmyc0ik4j61wiWKAnyPw2jN8Llgsl/DO19iSSN4G5wB9gBhHHFNRPNI8nOlt4Uzp7B+BXlWIB+KYxbchmznkJ+IxpJPXqsobtjEMXkJq7fkkBsZDwRHkm3tzdzcLzvQEfChvrnjVBX+5Rz679m4NmTBtCiGn6kF0DrsmX5rfhG7ZP19QzDUSED23tL2FExqBddB2JeDY+FAsElBuZfYnpnAXKHebg4u6RPybmm1hdQdK4gd3CKh7W9+D2rKjooGYFctkCHJzD8ipwi3/7mz1Mnh3z4Na637t6BeRCBgFdiX8ifkxsLlSb3944h+hkt/0n6JuRdR9G8OTRW8ZBCfyZWz2xmk34M/2G3AgwAYPB4kNQnLB4AAAAASUVORK5CYII=" />'
53+
. $this->getCurrentBranchName();
54+
}
55+
56+
}

0 commit comments

Comments
 (0)