Is it possible to make a precommit hook for git or svn that can reject files not committed in a specific encoding?
I have worked on several project where it seems to be a problem to stick to a certain file encoding (like UTF-8 for instance)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your iconv may be able to tell you if something is not UTF-8, but other encodings may not be so easy (especially 8-bit, single byte encodings like ISO-8859-1).
For Git, you may actually want an update hook instead of a pre-commit hook (so that it can be run in a central repository to enforce the rule).
Git pre-commit hook:
Put one or more Git pathspecs after the
--on the git ls-files command line to limit the pathnames that are checked.To check the tip of the updated ref in an update hook, use
git ls-tree --name-only -r -z $3 -- |to generate the pathnames (note: it does not handle pattern pathspecs like git ls-files, so do any pattern-based filtering in the shell code) andgit show "$3:$f"to extract the file contents. You might also want to check not only the tip commit, but each new commit (loop for each commit ingit rev-list ^$2 $3instead of just$3).