Skip to content

Commit

Permalink
Added a check-for-dos-endings pre commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Ardell committed Aug 2, 2010
2 parents fcf10d7 + 85cca53 commit 68eeb84
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions Config.sample.php
Expand Up @@ -3,6 +3,7 @@

$CONFIG['preCommit'] = array(
'run-php-lint',
'check-for-dos-endings',
'check-whitespace',
'enforce-coding-standards',
'run-phpunit',
Expand Down
25 changes: 25 additions & 0 deletions check-for-dos-endings
@@ -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
**/
2 changes: 1 addition & 1 deletion pre-commit
Expand Up @@ -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.