Permalink
Browse files

Added a check-for-dos-endings pre commit hook

  • Loading branch information...
2 parents fcf10d7 + 85cca53 commit 68eeb848e971cf5ea750350a8068231ebeee5fd6 Jason Ardell committed Aug 2, 2010
Showing with 27 additions and 1 deletion.
  1. +1 −0 Config.sample.php
  2. +25 −0 check-for-dos-endings
  3. +1 −1 pre-commit
View
@@ -3,6 +3,7 @@
$CONFIG['preCommit'] = array(
'run-php-lint',
+ 'check-for-dos-endings',
'check-whitespace',
'enforce-coding-standards',
'run-phpunit',
View
@@ -0,0 +1,25 @@
+#!/usr/bin/env php
+<?php
+$output = array();
+$return = 0;
+$exit_status = 0;
+
+// finds any DOS carriage returns, but ignores .git directory
+$cmd = "grep -PIlsr '\\r\\n' . | grep -v '.git'";
+// REGEX from: http://stackoverflow.com/questions/73833/how-do-you-search-for-files-containing-dos-line-endings-crlf-with-grep-under-li
+
+
+exec($cmd, $output, $return);
+if ($return != 1) {
+ echo "DOS line endings detected\n" . implode("\n", $output);
+ $exit_status = 1;
+ exit($exit_status);
+}
+
+/**
+bash script to fix dos files:
+WARNING: this overwrites files in place
+
+ for f in `grep -PIlsr '\r\n' . | grep -v '.git'`; do dos2unix ${f}; done
+
+**/
View
@@ -12,4 +12,4 @@ foreach ($commandsToRun as $command) {
echo implode("\n", $output) . "\n";
exit(1);
}
-}
+}

0 comments on commit 68eeb84

Please sign in to comment.