Browse Source

Fixing perforce dev-master stored reference bug.

Clark Stuth 11 years ago
parent
commit
2651cbc5fe
2 changed files with 31 additions and 10 deletions
  1. 9 8
      src/Composer/Util/Perforce.php
  2. 22 2
      tests/Composer/Test/Util/PerforceTest.php

+ 9 - 8
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;
     }
 

+ 22 - 2
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()