SVN commit hook to enforce encoding & line-endings?
There is a known problem with VC++ that it seems to use your system localization settings to choose default file-encodings. I wondered how one might make SVN e开发者_如何学Gonforce a certain encoding and line-end type when the file is committed.
You need to set svn:eol-style property, but you need to do this on all of your files, so you need to make sure your developers use it when they create a new file. And, I just happen to have the Subversion Kitchen Sink Pre-Commit Hook that'll handle this. This hook is in Perl which is available on almost all platforms. I've tried to write the hook not to need any non-standard Perl modules, so all you have to do is install Perl on the Subversion server.
The hook does many things (thus the Kitchen Sink designation). It can prevent users from doing commits unless they have permission, it can keep your tags from being modified, it can prevent certain file names from being added, and for you, it can check to make sure that a particular Subversion property is installed, and is set to the correct value.
Basically, if someone creates a new file (or modifies an old file) and the property isn't set on that file, the user is prevented from committing that file. The error from the failed commit explains the problem and the solution.
To avoid this issue, users can set their autoproperties to automatically add a property when they create a new file. Unfortunately, this is a user-by-user setting, so you can't force users to do this. However, after the first one or two times they come against this hook, they'll set their autoproperties.
Have a look at the svn:eol-style property. This property sets the line end type of files. Enforcing an encoding isn't really feasible: that would require converting (i.e. changing) your file content without you first checking the conversion.
精彩评论