license helper
[pharext/pharext] / src / pharext / SourceDir / Git.php
index a16b1e67769726e26c912b7d9883edcd2635dca9..62dc24f9e5162cfde0cf7ff3d6380c4e5a7a2875 100644 (file)
@@ -2,7 +2,8 @@
 
 namespace pharext\SourceDir;
 
-use pharext\Command;
+use pharext\Cli\Args;
+use pharext\License;
 use pharext\SourceDir;
 
 /**
@@ -10,11 +11,7 @@ use pharext\SourceDir;
  */
 class Git implements \IteratorAggregate, SourceDir
 {
-       /**
-        * The Packager command
-        * @var pharext\Command
-        */
-       private $cmd;
+       use License;
        
        /**
         * Base directory
@@ -26,8 +23,7 @@ class Git implements \IteratorAggregate, SourceDir
         * @inheritdoc
         * @see \pharext\SourceDir::__construct()
         */
-       public function __construct(Command $cmd, $path) {
-               $this->cmd = $cmd;
+       public function __construct($path) {
                $this->path = $path;
        }
 
@@ -38,7 +34,40 @@ class Git implements \IteratorAggregate, SourceDir
        public function getBaseDir() {
                return $this->path;
        }
-       
+
+       /**
+        * @inheritdoc
+        * @return array
+        */
+       public function getPackageInfo() {
+               return [];
+       }
+
+       /**
+        * @inheritdoc
+        * @return string
+        */
+       public function getLicense() {
+               if (($file = $this->findLicense($this->getBaseDir()))) {
+                       return $this->readLicense($file);
+               }
+               return "UNKNOWN";
+       }
+
+       /**
+        * @inheritdoc
+        * @return array
+        */
+       public function getArgs() {
+               return [];
+       }
+
+       /**
+        * @inheritdoc
+        */
+       public function setArgs(Args $args) {
+       }
+
        /**
         * Generate a list of files by `git ls-files`
         * @return Generator
@@ -46,23 +75,19 @@ class Git implements \IteratorAggregate, SourceDir
        private function generateFiles() {
                $pwd = getcwd();
                chdir($this->path);
-               if (($pipe = popen("git ls-files", "r"))) {
+               if (($pipe = popen("git ls-tree -r --name-only HEAD", "r"))) {
+                       $path = realpath($this->path);
                        while (!feof($pipe)) {
                                if (strlen($file = trim(fgets($pipe)))) {
-                                       if ($this->cmd->getArgs()->verbose) {
-                                               $this->cmd->info("Packaging %s\n", $file);
-                                       }
-                                       if (!($realpath = realpath($file))) {
-                                               $this->cmd->error("File %s does not exist\n", $file);
-                                       }
-                                       yield $realpath;
+                                       /* there may be symlinks, so no realpath here */
+                                       yield "$path/$file";
                                }
                        }
                        pclose($pipe);
                }
                chdir($pwd);
        }
-       
+
        /**
         * Implements IteratorAggregate
         * @see IteratorAggregate::getIterator()