Actually use the gitignore information.
authorGunnar Wrobel <p@rdus.de>
Tue, 2 Nov 2010 18:33:54 +0000 (19:33 +0100)
committerGunnar Wrobel <p@rdus.de>
Tue, 2 Nov 2010 19:39:05 +0000 (20:39 +0100)
components/lib/Components/Pear/Package/Contents/Ignore.php

index 50118a3..9bf48e1 100644 (file)
@@ -52,6 +52,7 @@ class Components_Pear_Package_Contents_Ignore
     public function __construct($gitignore, $base = '')
     {
         $this->_base = $base;
+        $this->_prepare($gitignore);
     }
 
     /**
@@ -98,6 +99,28 @@ class Components_Pear_Package_Contents_Ignore
     }
 
     /**
+     * Prepare the list of ignores and include from the gitignore input.
+     *
+     * @param string $gitignore
+     *
+     * @return NULL
+     */
+    private function _prepare($gitignore)
+    {
+        foreach (split("\n", $gitignore) as $line) {
+            $line = strtr($line, ' ', '');
+            if (empty($line) || strpos($line, '#') == 1) {
+                continue;
+            }
+            if (strpos($line, '!') == 1) {
+                $this->_include[] = $this->_getRegExpableSearchString($line);
+            } else {
+                $this->_ignore[] = $this->_getRegExpableSearchString($line);
+            }
+        }
+    }
+
+    /**
      * Converts $s into a string that can be used with preg_match
      *
      * @param string $s string with wildcards ? and *