final move of files
[web.mtrack] / MTrack / CommitCheck / UnixLineBreak.php
1 <?php 
2 require_once 'Interface/CommitListener.php';
3
4 class MTrackCommitCheck_UnixLineBreak implements IMTrackCommitListener 
5 {
6   
7     function vetoCommit($msg, $files, $actions, $checker)
8     {
9         // should only have a list of files which have been updated/added. (not deleted)
10         $ret = array();
11          if (count($files) > 30) {
12             // to many files.. we can not check that amount without causing serious delays in commits
13             return true;
14         }
15         
16         foreach ($files as $filename) {
17             $pi = pathinfo($filename);
18             switch($pi['extension']) {
19               case 'php':
20               case 'html': 
21                     $fp = $checker->bridge->getFileStream($filename);
22                
23                     $res = $this->checkLineBreaks($filename, $fp);
24                     if ($res !== true) {
25                         $ret[] = $res;
26                     }
27                     $fp = null; // remove stream.
28           }
29         }
30          
31        return $ret ? implode("\n", $ret) : true;
32     }
33
34     function postCommit($msg, $files, $actions) {
35         return true;
36     }
37     function checkLineBreaks($filename, $fp)
38     {
39         $pipes = null;
40         $contents = stream_get_contents($fp);
41         if (preg_match("/\r+/", $contents)) {
42             return "Use Unix line endings only in $filename";
43         }
44         
45         return true;
46     }
47 }