From 209454c5f67e9fa8d1042b2410cd8350eeb4fcb7 Mon Sep 17 00:00:00 2001 From: Adirelle Date: Tue, 21 Apr 2015 14:51:55 +0200 Subject: [PATCH] When starting a manual build, replace the "Manual" commit id with the HEAD hash. Close #928 --- PHPCI/Model/Build/RemoteGitBuild.php | 16 ++++++++-------- PHPCI/Service/BuildService.php | 2 ++ Tests/PHPCI/Service/BuildServiceTest.php | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/PHPCI/Model/Build/RemoteGitBuild.php b/PHPCI/Model/Build/RemoteGitBuild.php index 5d0c9419..faaccfb5 100644 --- a/PHPCI/Model/Build/RemoteGitBuild.php +++ b/PHPCI/Model/Build/RemoteGitBuild.php @@ -124,16 +124,16 @@ class RemoteGitBuild extends Build $success = true; $commit = $this->getCommitId(); + $chdir = IS_WIN ? 'cd /d "%s"' : 'cd "%s"'; + if (!empty($commit) && $commit != 'Manual') { - $cmd = 'cd "%s"'; + $cmd = $chdir . ' && git checkout %s --quiet'; + $success = $builder->executeCommand($cmd, $cloneTo, $commit); + } - if (IS_WIN) { - $cmd = 'cd /d "%s"'; - } - - $cmd .= ' && git checkout %s --quiet'; - - $success = $builder->executeCommand($cmd, $cloneTo, $this->getCommitId()); + // Always update the commit hash with the actual HEAD hash + if ($builder->executeCommand($chdir . ' && git rev-parse HEAD', $cloneTo)) { + $this->setCommitId(trim($builder->getLastOutput())); } return $success; diff --git a/PHPCI/Service/BuildService.php b/PHPCI/Service/BuildService.php index a95ac44f..ca2fae4d 100644 --- a/PHPCI/Service/BuildService.php +++ b/PHPCI/Service/BuildService.php @@ -9,6 +9,7 @@ namespace PHPCI\Service; +use PHPCI\Helper\Lang; use PHPCI\Model\Build; use PHPCI\Model\Project; use PHPCI\Store\BuildStore; @@ -59,6 +60,7 @@ class BuildService $build->setCommitId($commitId); } else { $build->setCommitId('Manual'); + $build->setCommitMessage(Lang::get('manual_build')); } if (!is_null($branch)) { diff --git a/Tests/PHPCI/Service/BuildServiceTest.php b/Tests/PHPCI/Service/BuildServiceTest.php index 426845a9..985f3088 100644 --- a/Tests/PHPCI/Service/BuildServiceTest.php +++ b/Tests/PHPCI/Service/BuildServiceTest.php @@ -57,7 +57,7 @@ class BuildServiceTest extends \PHPUnit_Framework_TestCase $this->assertNull($returnValue->getStarted()); $this->assertNull($returnValue->getFinished()); $this->assertNull($returnValue->getLog()); - $this->assertEmpty($returnValue->getCommitMessage()); + $this->assertEquals(\PHPCI\Helper\Lang::get('manual_build'), $returnValue->getCommitMessage()); $this->assertNull($returnValue->getCommitterEmail()); $this->assertNull($returnValue->getExtra()); $this->assertEquals('master', $returnValue->getBranch());