Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Git branch Nette debugger panel
{
"name":"vvondra/gitbranch-debug-panel",
"description":"Nette DebugBar panel displaying current project git branch.",
"keywords":["nette", "debug", "git"],
"license":["BSD-3"],
"authors":[
{
"name":"Vojtěch Vondra",
"homepage":"http://www.vojtechvondra.cz"
}
],
"require":{
"php":">=5.3.2",
"nette/nette":"*"
},
"autoload":{
"psr-0":{
"Vondra":""
}
},
"target-dir":"Vondra"
}
<?php
namespace Vondra;
class GitBranchPanel implements \Nette\Diagnostics\IBarPanel
{
public function getPanel()
{
return '';
}
protected function getCurrentBranchName() {
$scriptPath = $_SERVER['SCRIPT_FILENAME'];
$dir = realpath(dirname($scriptPath));
while ($dir !== false && !is_dir($dir . '/.git')) {
flush();
$currentDir = $dir;
$dir .= '/..';
$dir = realpath($dir);
// Stop recursion to parent on root directory
if ($dir == $currentDir) {
break;
}
}
$head = $dir . '/.git/HEAD';
if ($dir && is_readable($head)) {
$branch = file_get_contents($head);
if (strpos($branch, 'ref:') === 0) {
$parts = explode('/', $branch);
return $parts[2];
}
return '(' . substr($branch, 0, 7) . '&hellip;)';
}
return 'not versioned';
}
public function getTab()
{
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=" />'
. $this->getCurrentBranchName();
}
}
@hrach

This comment has been minimized.

Copy link

commented May 26, 2014

Please update dependency to tracy/tracy ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.