Skip to content

Commit

Permalink
feat(git): add get last commit hash method
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocesarato committed Feb 13, 2021
1 parent bf4d1a8 commit c650b5e
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/Git/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,19 @@ public static function getFirstCommit(): string
}

/**
* Get last tag.
* Get last commit hash.
*/
public static function getLastTag(): string
public static function getLastCommit(): string
{
return self::run("git for-each-ref refs/tags --sort=-creatordate --format='%(refname:strip=2)' --count=1");
return self::run('git log -1 --pretty=format:%H');
}

/**
* Get commit date.
* Get last tag.
*/
public static function getCommitDate($hash): string
public static function getLastTag(): string
{
$date = self::run("git log -1 --format=%aI {$hash}");
$today = new DateTime($date);

return $today->format('Y-m-d');
return self::run("git for-each-ref refs/tags --sort=-creatordate --format='%(refname:strip=2)' --count=1");
}

/**
Expand All @@ -76,6 +73,17 @@ public static function getLastTagCommit(): string
return self::run("git rev-parse --verify {$lastTag}");
}

/**
* Get commit date.
*/
public static function getCommitDate($hash): string
{
$date = self::run("git log -1 --format=%aI {$hash}");
$today = new DateTime($date);

return $today->format('Y-m-d');
}

/**
* Get remote url.
*/
Expand Down

0 comments on commit c650b5e

Please sign in to comment.