r93999 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93998‎ | r93999 | r94000 >
Date:20:57, 5 August 2011
Author:demon
Status:ok
Tags:
Comment:
Also add prevention of commits by "root"
Modified paths:
  • /trunk/tools/subversion/hooks/HooksCommon.inc (modified) (history)

Diff [purge]

Index: trunk/tools/subversion/hooks/HooksCommon.inc
@@ -38,6 +38,9 @@
3939 'testPHPLint' => array(
4040 array( 'php', 'php5', 'phtml', 'inc' ), /** valid types to check **/
4141 ),
 42+ 'testBadUsers' => array(
 43+ array( 'root' ), /** users we don't want commits from **/
 44+ ),
4245 );
4346
4447 /**
@@ -93,6 +96,18 @@
9497 }
9598
9699 /**
 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+ /**
97112 * Get commit files list
98113 *
99114 * @return array filenames are keys and status letters are values
@@ -163,6 +178,8 @@
164179 }
165180
166181 /**
 182+ * Check if PHP-related files pass a basic lint test
 183+ *
167184 * @param $fileTypes array
168185 * @return bool|string
169186 */
@@ -181,4 +198,18 @@
182199 }
183200 return $result !== '' ? $result : true;
184201 }
 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+ }
185216 }

Status & tagging log