From 15b8c6f1c38b6c2541616b44b00928526f00b7db Mon Sep 17 00:00:00 2001 From: Clark Stuth Date: Fri, 21 Mar 2014 13:42:00 -0500 Subject: [PATCH] Fixing perforce dev-master stored reference bug. --- src/Composer/Util/Perforce.php | 17 ++++++++-------- tests/Composer/Test/Util/PerforceTest.php | 24 +++++++++++++++++++++-- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index f3e9d2023..ae6f44d04 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -315,11 +315,7 @@ class Perforce chdir($this->path); $p4SyncCommand = $this->generateP4Command('sync -f '); - if (isset($label)) { - if (strcmp($label, 'dev-master') != 0) { - $p4SyncCommand = $p4SyncCommand . '@' . $label; - } - } + $p4SyncCommand = $p4SyncCommand . '@' . $label; $this->executeCommand($p4SyncCommand); chdir($prevDir); @@ -481,9 +477,15 @@ class Perforce } } } - $branches = array(); - $branches['master'] = $possibleBranches[$this->p4Branch]; + $command = $this->generateP4Command('changes '. $this->getStream() . '/...', false); + $this->executeCommand($command); + $result = $this->commandResult; + $resArray = explode(PHP_EOL, $result); + $lastCommit = $resArray[0]; + $lastCommitArr = explode(' ', $lastCommit); + $lastCommitNum = $lastCommitArr[1]; + $branches = array('master' => $possibleBranches[$this->p4Branch] . '@'. $lastCommitNum); return $branches; } @@ -501,7 +503,6 @@ class Perforce $tags[$fields[1]] = $this->getStream() . '@' . $fields[1]; } } - return $tags; } diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index 06e3cce8b..1b8063258 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -351,15 +351,35 @@ class PerforceTest extends \PHPUnit_Framework_TestCase } ) ); + $expectedCommand2 = 'p4 -u user -p port changes //depot/branch/...'; + $expectedCallback = function($command, &$output) + { + $output = 'Change 1234 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\''; + return true; + }; + $this->processExecutor->expects($this->at(1)) + ->method('execute') + ->with($this->equalTo($expectedCommand2)) + ->will($this->returnCallback($expectedCallback)); $branches = $this->perforce->getBranches(); - $this->assertEquals('//depot/branch', $branches['master']); + $this->assertEquals('//depot/branch@1234', $branches['master']); } public function testGetBranchesWithoutStream() { + $expectedCommand = 'p4 -u user -p port changes //depot/...'; + $expectedCallback = function($command, &$output) + { + $output = 'Change 5678 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\''; + return true; + }; + $this->processExecutor->expects($this->once()) + ->method('execute') + ->with($this->equalTo($expectedCommand)) + ->will($this->returnCallback($expectedCallback)); $branches = $this->perforce->getBranches(); - $this->assertEquals('//depot', $branches['master']); + $this->assertEquals('//depot@5678', $branches['master']); } public function testGetTagsWithoutStream()