How do I implement a pre-commit hook script in SVN that calls dos2unix to validate checked-in file
<p>I was wondering if anyone here had some experience writing this type of script and if they could give me some pointers.</p>

<p>I would like to modify this <a href="http://wordaligned.org/articles/a-subversion-pre-commit-hook" rel="nofollow">script</a> to validate that the check-in file does not have a Carriage Return in the EOL formatting. The EOL format is CR LF in Windows and LF in Unix. When a User checks-in code with the Windows format. It does not compile in Unix anymore. I know this can be done on the client side but I need to have this validation done on the server side. To achieve this, I need to do the following:</p>

<p>1) Make sure the file I check is not a binary, I dont know how to do this with svnlook, should I check the mime:type of the file? The <a href="http://svnbook.red-bean.com/nightly/en/svn.reposadmin.create.html" rel="nofollow">Red Book</a> does not indicate this clearly or I must have not seen it.</p>

<p>2) I would like to run the <a href="http://linux.about.com/od/commands/l/blcmdl1_dos2uni.htm" rel="nofollow">dos2unix</a> command to validate that the file has the correct EOL format. I would compare the output of the dos2unix command against the original file. If there is a diff between both, I give an error message to the client and cancel the check-in.</p>

<p>I would like your comments/feedback on this approach.</p>

<p>I think you can avoid a commit hook script in this case by using the <code>svn:eol-style</code> property as described in the SVNBook:</p>

<ul>
<li><p><a href="http://svnbook.red-bean.com/en/1.7/svn.advanced.props.file-portability.html#svn.advanced.props.special.eol-style" rel="nofollow">End-of-Line Character Sequences</a></p></li>
<li><p><a href="http://svnbook.red-bean.com/en/1.7/svn.ref.properties.html" rel="nofollow">Subversion Properties</a></p></li>
</ul>

<p>This way SVN can worry about your line endings for you.</p>

<p>Good luck!</p>
