Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Current git version.
<?php
class QuickGit
{
/** @var int */
private $major = 1;
/** @var int */
private $minor = 0;
/** @var string */
private $patch = '';
/** @var int */
private $commits = 0;
/** @var string */
private $commit = '';
/**
* @method __construct
*/
public function __construct()
{
// Collect git data.
exec('git describe --always', $gitHashShort);
$this->patch = $gitHashShort;
exec('git rev-list HEAD | wc -l', $gitCommits);
$this->commits = $gitCommits;
exec('git log -1', $gitHashLong);
$this->commit = $gitHashLong;
}
/**
* @return string
*/
public function toString($format = 'short')
{
switch ($format) {
case 'long':
return sprintf(
'%d.%d.%s (#%d, %s)',
$this->major,
$this->minor,
$this->patch,
$this->commits,
$this->commit
);
default:
return sprintf(
'%d.%d.%s',
$this->major,
$this->minor,
$this->patch
);
}
}
/**
* @method __toString
*/
public function __toString()
{
return $this->toString();
}
}
@lukeocodes

This comment has been minimized.

Copy link
Owner Author

lukeocodes commented Feb 27, 2017

Not tested even since having PSR'd/improved it.

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.