Skip to content

Commit

Permalink
[#84] Fixed [tags] token using all tags instead of latest. (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
tannguyen04 authored Apr 17, 2024
1 parent 36ac23d commit 2cf0a91
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Commands/ArtifactCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -914,9 +914,10 @@ protected function getTokenBranch(): string {
*/
protected function getTokenTags(string $delimiter = NULL): string {
$delimiter = $delimiter ?: '-';
// We just want to get all tags point to the HEAD.
$tags = $this
->gitRepository
->getTags();
->getTagsPointToHead();

return implode($delimiter, $tags);
}
Expand Down
19 changes: 19 additions & 0 deletions src/Git/ArtifactGitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,25 @@ public function setConfigReceiveDenyCurrentBranchIgnore(): ArtifactGitRepository
return $this;
}

/**
* Get tag point to HEAD.
*
* @return string[]
* Array of tags from the latest commit.
*
* @throws \Exception
* If no tags found in the latest commit.
*/
public function getTagsPointToHead(): array {
$tags = $this->extractFromCommand(['tag', ['--points-at', 'HEAD']]);

if (empty($tags)) {
throw new \Exception('No tags found in the latest commit.');
}

return $tags;
}

/**
* Create an annotated tag.
*
Expand Down
14 changes: 13 additions & 1 deletion tests/phpunit/Functional/ForcePushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,20 @@ public function testBuildMultipleTags(): void {
$this->gitAddTag($this->src, 'tag2');

$this->assertBuildSuccess('--branch=[tags]', 'tag1-tag2');

$this->assertFixtureCommits(2, $this->dst, 'tag1-tag2', ['Deployment commit']);

$this->gitCreateFixtureCommit(3);
$this->gitAddTag($this->src, 'tag3');
$this->assertBuildSuccess('--branch=[tags]', 'tag3');
$this->assertFixtureCommits(3, $this->dst, 'tag3', ['Deployment commit']);
}

public function testBuildMultipleTagsMissingTags(): void {
$this->gitCreateFixtureCommits(2);
$this->gitAddTag($this->src, 'tag1');
$this->gitCreateFixtureCommit(3);

$this->assertBuildFailure('--branch=[tags]');
}

public function testBuildMultipleTagsDelimiter(): void {
Expand Down

0 comments on commit 2cf0a91

Please sign in to comment.