Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement a pre-commit hook script in SVN that calls dos2unix to validate checked-in file

I was wondering if anyone here had some experience writing this type of script and if they could give me some pointers.

I would like to modify this script 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:

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 Red Book does not indicate this clearly or I must have not seen it.

2) I would like to run the dos2unix 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.

I would like your comments/feedback on this approach.

like image 717
Julien Nephtali Avatar asked Sep 07 '08 16:09

Julien Nephtali


People also ask

How do you enforce a pre-commit hook?

If you want enforcement, use an update hook in the central repo. If the hook is doing per-commit verification, you can still provide a pre-commit hook; developers will likely adopt it voluntarily, so that they can find out right away when they've done something wrong, rather than waiting until they try to push.

What is pre-commit hook in SVN?

A pre-commit hook is a feature available in the Subversion version control system that allows code to be validated before it is committed to the repository. The PHP_CodeSniffer pre-commit hook allows you to check code for coding standard errors and stop the commit process if errors are found.

How do you run pre-commit hook without committing?

Just run git commit . You don't have to add anything before doing this, hence in the end you get the message no changes added to commit .


1 Answers

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

  • End-of-Line Character Sequences

  • Subversion Properties

This way SVN can worry about your line endings for you.

Good luck!

like image 132
Stephen Johnson Avatar answered Sep 23 '22 10:09

Stephen Johnson