Ver Fonte

Git can handle commit references in git archive just fine so use them

Nils Adermann há 12 anos atrás
pai
commit
bcbc50c0d6

+ 1 - 3
src/Composer/Package/Archiver/GitArchiver.php

@@ -32,9 +32,7 @@ class GitArchiver implements ArchiverInterface
      */
     public function archive($sources, $target, $format, $sourceRef = null)
     {
-        // Since git-archive no longer works with a commit ID in git 1.7.10,
-        // use by default the HEAD reference instead of the commit sha1
-        if (null === $sourceRef || preg_match('/^[0-9a-f]{40}$/i', $sourceRef)) {
+        if (null === $sourceRef) {
             $sourceRef = 'HEAD';
         }
 

+ 14 - 2
tests/Composer/Test/Package/Archiver/GitArchiverTest.php

@@ -31,7 +31,7 @@ class GitArchiverTest extends ArchiverTest
 
         // Test archive
         $archiver = new GitArchiver();
-        $archiver->archive($package->getSourceUrl(), $target, 'zip', 'master');
+        $archiver->archive($package->getSourceUrl(), $target, 'zip', 'master^1');
         $this->assertFileExists($target);
 
         unlink($target);
@@ -46,7 +46,7 @@ class GitArchiverTest extends ArchiverTest
 
         // Test archive
         $archiver = new GitArchiver();
-        $archiver->archive($package->getSourceUrl(), $target, 'tar', 'master');
+        $archiver->archive($package->getSourceUrl(), $target, 'tar', 'master^1');
         $this->assertFileExists($target);
 
         unlink($target);
@@ -78,6 +78,18 @@ class GitArchiverTest extends ArchiverTest
             throw new \RuntimeException('Could not commit: '.$this->process->getErrorOutput());
         }
 
+        $result = file_put_contents('d', 'c');
+        if (false === $result) {
+            chdir($currentWorkDir);
+            throw new \RuntimeException('Could not save file.');
+        }
+
+        $result = $this->process->execute('git add d && git commit -m "commit d" -q');
+        if ($result > 0) {
+            chdir($currentWorkDir);
+            throw new \RuntimeException('Could not commit: '.$this->process->getErrorOutput());
+        }
+
         chdir($currentWorkDir);
     }
 }