ソースを参照

New downloader for mercurial

Per Bernhardt 13 年 前
コミット
c6e4984a62
2 ファイル変更75 行追加0 行削除
  1. 1 0
      bin/composer
  2. 74 0
      src/Composer/Downloader/HgDownloader.php

+ 1 - 0
bin/composer

@@ -29,6 +29,7 @@ $rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository');
 // initialize download manager
 $dm = new Downloader\DownloadManager();
 $dm->setDownloader('git',  new Downloader\GitDownloader());
+$dm->setDownloader('hg', new Downloader\HgDownloader());
 $dm->setDownloader('pear', new Downloader\PearDownloader());
 $dm->setDownloader('zip',  new Downloader\ZipDownloader());
 

+ 74 - 0
src/Composer/Downloader/HgDownloader.php

@@ -0,0 +1,74 @@
+<?php
+
+/*
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ *     Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Downloader;
+
+use Composer\Package\PackageInterface;
+
+/**
+ * @author Per Bernhardt <plb@webfactory.de>
+ */
+class HgDownloader implements DownloaderInterface
+{
+    /**
+     * {@inheritDoc}
+     */
+    public function getInstallationSource()
+    {
+        return 'source';
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function download(PackageInterface $package, $path)
+    {
+        if (!$package->getSourceReference()) {
+            throw new \InvalidArgumentException('The given package is missing reference information');
+        }
+
+        $url = escapeshellarg($package->getSourceUrl());
+        $ref = escapeshellarg($package->getSourceReference());
+        system(sprintf('hg clone %s %s && cd %2$s && hg up %s', $url, $path, $ref));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function update(PackageInterface $initial, PackageInterface $target, $path)
+    {
+        if (!$target->getSourceReference()) {
+            throw new \InvalidArgumentException('The given package is missing reference information');
+        }
+
+		$this->enforceCleanDirectory($path);
+		system(sprintf('cd %s && hg pull && hg up %s', $path, $target->getSourceReference()));
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function remove(PackageInterface $package, $path)
+    {
+        $this->enforceCleanDirectory($path);
+        $fs = new Util\Filesystem();
+        $fs->remove($path);
+    }
+
+    private function enforceCleanDirectory($path)
+    {
+        exec(sprintf('cd %s && hg st', $path), $output);
+        if (implode('', $output)) {
+            throw new \RuntimeException('Source directory has uncommitted changes');
+        }
+    }
+}