I'd like to write a git hook that automatically does some code cleaning, such as removing trailing whitespace. It's easy to write a script to reject certain commits, but I'd rather just fix the problems transparently when possible. While I realize git has some built-in support for stuff like this (automatically converting newlines, etc.), but I'd like something more flexible. Is it possible for a pre-commit hook to do this? Can you modify the index directly (or is there a better way of doing this)?
I also realize that ultimately I'll need a server hook that rejects bad commits for developers who don't use the local hook, but I'd like to help those that opt to use it. (If it is possible to modify the code on the server that would be even better, but I don't believe you can.)