Skip to content

Commit

Permalink
fix: restore last tag with refname method
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocesarato committed Oct 27, 2022
1 parent d526e80 commit ef97fb0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .changelog
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ return [
],
'releaseCommitMessageFormat' => "{$releaseMessagePrefix}{{currentTag}}",
'postRun' => function () use ($releaseMessagePrefix) {
$lastTag = Repository::getLastTag();
$lastTagCommit = Repository::getLastTagCommit();
$lastTag = Repository::getLastTagRefname();
$lastTagCommit = Repository::getLastTagRefnameCommit();
$lastCommit = Repository::getLastCommit();

if ($lastTagCommit !== $lastCommit) {
Expand Down
19 changes: 19 additions & 0 deletions src/Git/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ public static function getLastCommit(): string
return self::run('git log -1 --pretty=format:%H');
}

/**
* Get last tag.
*/
public static function getLastTagRefname($prefix = '', $merged = false): string
{
$merged = $merged ? '--merged' : '';
return self::run('git for-each-ref ' /* 'refs/tags/" . $prefix . "*' */ . " --sort=-v:refname --format='%(refname:strip=2)' --count=1 {$merged}");
}

/**
* Get last tag.
*/
Expand Down Expand Up @@ -125,6 +134,16 @@ public static function getLastTagCommit($prefix = ''): string
return self::run("git rev-parse --verify {$lastTag}");
}

/**
* Get last tag commit hash.
*/
public static function getLastTagRefnameCommit($prefix = ''): string
{
$lastTag = self::getLastTagRefname($prefix);

return self::run("git rev-parse --verify {$lastTag}");
}

/**
* Get current branch name.
*/
Expand Down

0 comments on commit ef97fb0

Please sign in to comment.