Skip to content

Instantly share code, notes, and snippets.

@lukeocodes
Last active December 11, 2018 08:06
Show Gist options
  • Save lukeocodes/5501074 to your computer and use it in GitHub Desktop.
Save lukeocodes/5501074 to your computer and use it in GitHub Desktop.

Revisions

  1. lukeocodes revised this gist Feb 27, 2017. 1 changed file with 65 additions and 18 deletions.
    83 changes: 65 additions & 18 deletions QuickGit.php
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,69 @@
    <?php

    class QuickGit {
    private $version;
    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 = '';


    function __construct() {
    exec('git describe --always',$version_mini_hash);
    exec('git rev-list HEAD | wc -l',$version_number);
    exec('git log -1',$line);
    $this->version['short'] = "v1.".trim($version_number[0]).".".$version_mini_hash[0];
    $this->version['full'] = "v1.".trim($version_number[0]).".$version_mini_hash[0] (".str_replace('commit ','',$line[0]).")";
    }

    public function output() {
    return $this->version;
    }

    public function show() {
    echo $this->version;
    }
    }
    /**
    * @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();
    }
    }
  2. lukeocodes revised this gist Jun 10, 2013. 1 changed file with 12 additions and 6 deletions.
    18 changes: 12 additions & 6 deletions QuickGit.php
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,22 @@
    <?php

    class QuickGit {
    private $version;

    public function __construct() {
    function __construct() {
    exec('git describe --always',$version_mini_hash);
    exec('git rev-list HEAD | wc -l',$version_number);
    exec('git log -1',$line);
    $version['short'] = "v1.".trim($version_number[0]).".".$version_mini_hash[0];
    $version['full'] = "v1.".trim($version_number[0]).".$version_mini_hash[0] (".str_replace('commit ','',$line[0]).")";

    return $version;
    $this->version['short'] = "v1.".trim($version_number[0]).".".$version_mini_hash[0];
    $this->version['full'] = "v1.".trim($version_number[0]).".$version_mini_hash[0] (".str_replace('commit ','',$line[0]).")";
    }

    public function output() {
    return $this->version;
    }

    public function show() {
    echo $this->version;
    }

    }

  3. lukeocodes revised this gist May 2, 2013. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions QuickGit.php
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,16 @@
    <?php

    class QuickGit {

    public static function version() {
    public function __construct() {
    exec('git describe --always',$version_mini_hash);
    exec('git rev-list HEAD | wc -l',$version_number);
    exec('git log -1',$line);
    $version['short'] = "v1.".trim($version_number[0]).".".$version_mini_hash[0];
    $version['full'] = "v1.".trim($version_number[0]).".$version_mini_hash[0] (".str_replace('commit ','',$line[0]).")";

    return $version;
    }

    }

  4. lukeocodes created this gist May 2, 2013.
    15 changes: 15 additions & 0 deletions QuickGit.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    <?php

    class QuickGit {

    public static function version() {
    exec('git describe --always',$version_mini_hash);
    exec('git rev-list HEAD | wc -l',$version_number);
    exec('git log -1',$line);
    $version['short'] = "v1.".trim($version_number[0]).".".$version_mini_hash[0];
    $version['full'] = "v1.".trim($version_number[0]).".$version_mini_hash[0] (".str_replace('commit ','',$line[0]).")";
    return $version;
    }

    }