Преглед на файлове

Add support for unixy paths in git/hg local repo urls, closes #3294

Jordi Boggiano преди 10 години
родител
ревизия
91ac3e1426

+ 2 - 2
src/Composer/Repository/Vcs/GitDriver.php

@@ -225,12 +225,12 @@ class GitDriver extends VcsDriver
 
         // local filesystem
         if (Filesystem::isLocalPath($url)) {
+            $url = Filesystem::getPlatformPath($url);
             if (!is_dir($url)) {
                 throw new \RuntimeException('Directory does not exist: '.$url);
             }
 
-            $process = new ProcessExecutor();
-            $url = str_replace('file://', '', $url);
+            $process = new ProcessExecutor($io);
             // check whether there is a git repo in that path
             if ($process->execute('git tag', $output, $url) === 0) {
                 return true;

+ 1 - 1
src/Composer/Repository/Vcs/HgDriver.php

@@ -198,12 +198,12 @@ class HgDriver extends VcsDriver
 
         // local filesystem
         if (Filesystem::isLocalPath($url)) {
+            $url = Filesystem::getPlatformPath($url);
             if (!is_dir($url)) {
                 throw new \RuntimeException('Directory does not exist: '.$url);
             }
 
             $process = new ProcessExecutor();
-            $url = str_replace('file://', '', $url);
             // check whether there is a hg repo in that path
             if ($process->execute('hg summary', $output, $url) === 0) {
                 return true;

+ 1 - 1
src/Composer/Repository/Vcs/VcsDriver.php

@@ -46,7 +46,7 @@ abstract class VcsDriver implements VcsDriverInterface
     final public function __construct(array $repoConfig, IOInterface $io, Config $config, ProcessExecutor $process = null, RemoteFilesystem $remoteFilesystem = null)
     {
         if (Filesystem::isLocalPath($repoConfig['url'])) {
-            $repoConfig['url'] = preg_replace('{^file://}', '', $repoConfig['url']);
+            $repoConfig['url'] = Filesystem::getPlatformPath($repoConfig['url']);
         }
 
         $this->url = $repoConfig['url'];

+ 9 - 0
src/Composer/Util/Filesystem.php

@@ -461,6 +461,15 @@ class Filesystem
         return (bool) preg_match('{^(file://|/|[a-z]:[\\\\/]|\.\.[\\\\/]|[a-z0-9_.-]+[\\\\/])}i', $path);
     }
 
+    public static function getPlatformPath($path)
+    {
+        if (defined('PHP_WINDOWS_VERSION_BUILD')) {
+            $path = preg_replace('{^(?:file:///([a-z])/)}i', 'file://$1:/', $path);
+        }
+
+        return preg_replace('{^file://}i', '', $path);
+    }
+
     protected function directorySize($directory)
     {
         $it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);