Skip to content

Instantly share code, notes, and snippets.

@mithereal
Forked from lukeocodes/QuickGit.php
Last active July 1, 2016 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mithereal/596a101e7b1bacf47d2a36af2a237e33 to your computer and use it in GitHub Desktop.
Save mithereal/596a101e7b1bacf47d2a36af2a237e33 to your computer and use it in GitHub Desktop.
Current git version.
<?php
class QuickGit {
private $version;
function __construct() {
if(function_exists('exec')) {
exec('git describe --always',$version_mini_hash,$error);
if($error == 0 ){
exec('git rev-list HEAD | wc -l',$version_number);
exec('git log -1',$line);
exec('git rev-parse --abbrev-ref HEAD',$branch);
$this->version['branch'] = $branch[0];
$this->version['short'] = $branch[0].".".trim($version_number[0]).".".$version_mini_hash[0];
$this->version['full'] = $branch[0].".".trim($version_number[0]).".$version_mini_hash[0] (".str_replace('commit ','',$line[0]).")";
}else{
$this->version['error']="Ooops there was an Error: [ ". $error ." ]";
}
}else{
$this->version['error']="Error: [ exec not enabled ]";
}
}
public function output() {
return $this->version;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment