Index: trunk/tools/subversion/hooks/HooksCommon.inc |
— | — | @@ -38,6 +38,9 @@ |
39 | 39 | 'testPHPLint' => array( |
40 | 40 | array( 'php', 'php5', 'phtml', 'inc' ), /** valid types to check **/ |
41 | 41 | ), |
| 42 | + 'testBadUsers' => array( |
| 43 | + array( 'root' ), /** users we don't want commits from **/ |
| 44 | + ), |
42 | 45 | ); |
43 | 46 | |
44 | 47 | /** |
— | — | @@ -93,6 +96,18 @@ |
94 | 97 | } |
95 | 98 | |
96 | 99 | /** |
| 100 | + * Get commit author |
| 101 | + * |
| 102 | + * @return string |
| 103 | + */ |
| 104 | + private function getAuthor() { |
| 105 | + $output = null; |
| 106 | + $cmd = "{$this->svnlook} author -t '{$this->transaction}' '{$this->repo}'"; |
| 107 | + exec( $cmd, $output ); |
| 108 | + return trim( implode( $output ) ); |
| 109 | + } |
| 110 | + |
| 111 | + /** |
97 | 112 | * Get commit files list |
98 | 113 | * |
99 | 114 | * @return array filenames are keys and status letters are values |
— | — | @@ -163,6 +178,8 @@ |
164 | 179 | } |
165 | 180 | |
166 | 181 | /** |
| 182 | + * Check if PHP-related files pass a basic lint test |
| 183 | + * |
167 | 184 | * @param $fileTypes array |
168 | 185 | * @return bool|string |
169 | 186 | */ |
— | — | @@ -181,4 +198,18 @@ |
182 | 199 | } |
183 | 200 | return $result !== '' ? $result : true; |
184 | 201 | } |
| 202 | + |
| 203 | + /** |
| 204 | + * Some users we don't like committing as (eg: root). Bail and yell at them. |
| 205 | + * |
| 206 | + * @param $badUsers array of bad user names |
| 207 | + * @return bool|string |
| 208 | + */ |
| 209 | + protected function testBadUsers( $badUsers ) { |
| 210 | + $ourUser = $this->getAuthor(); |
| 211 | + if( in_array( $ourUser, $badUsers ) ) { |
| 212 | + return "Please do not commit as '{$ourUser}', use your real commit name"; |
| 213 | + } |
| 214 | + return true; |
| 215 | + } |
185 | 216 | } |