inc/CommitCheck/BlankLines.php
authorAlan Knowles <alan@akbkhome.com>
Thu, 27 Jan 2011 06:51:38 +0000 (14:51 +0800)
committerAlan Knowles <alan@akbkhome.com>
Thu, 27 Jan 2011 06:51:38 +0000 (14:51 +0800)
inc/CommitCheck/BlankLines.php

index df106c5..3344cd4 100644 (file)
@@ -8,22 +8,31 @@ class MTrackCommitCheck_BlankLines implements IMTrackCommitListener
     {
         // should only have a list of files which have been updated/added. (not deleted)
         $ret = array();
-        foreach ($files as $filename) {
-            $pi = pathinfo($filename);
-            switch($pi['extension']) {
-              case 'php':
-              case 'html': 
-                    $fp = $checker->bridge->getFileStream($filename);
-               
-                    $res = $this->checkBlanks($filename, $fp);
-                    if ($res !== true) {
-                        $ret[] = $res;
-                    }
-                    $fp = null; // remove stream.
-          }
+        if (!method_exists($checker->bridge, 'getDiffStream')) {
+            return true;
         }
+        $fp = $checker->bridge->getDiffStream();
+        $diff = stream_get_contents($fp);
+        $lines = explode("\n",$contents);
+        $seq = 0;
+        $total = 0;
+        foreach($lines as $l) {
+            $ll = trim($l);
+            if ($l != '+') {
+                $seq =0;
+                continue;
+            }
+            // got blannk line
+            $seq++;
+            $total++;
+            if ($seq > 2) {
+                return "You are adding more than 2 blank lines - please remove the new blank lines you added and try again.";
+            }
+        }
+        
+         
          
-       return $ret ? implode("\n", $ret) : true;
+       return true;
     }
 
     function postCommit($msg, $files, $actions) {