forked from ardell/Git-Hooks
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a check-for-dos-endings pre commit hook
- Loading branch information
Showing
3 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
**/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ foreach ($commandsToRun as $command) { | |
echo implode("\n", $output) . "\n"; | ||
exit(1); | ||
} | ||
} | ||
} |