The first git hook has just been committed. I will quote from the commit:
Git supports several hooks, some of which are client-side. The
prepare-commit-msg hook is run right after a `git commit` call, before
the editor is opened. This allows the initial message to be altered.
This hook will check if the current branch name begins with `bug/`, in
which case it will prepend `[$branchname]` to the commit message. This
makes it easier to create proper commit messages.
I've just had another idea for a hook. Well, actually it's not mine, I've seen this used at a popular open source project (phpBB).
How about a pre-commit hook that runs `php -l` on any file with .php extension. the -l stands for "lint", and makes sure there are no syntax errors in the file. If there are errors, they are echoed and the commit is aborted.
eviL3 wrote:I've just had another idea for a hook. Well, actually it's not mine, I've seen this used at a popular open source project (phpBB).
How about a pre-commit hook that runs `php -l` on any file with .php extension. the -l stands for "lint", and makes sure there are no syntax errors in the file. If there are errors, they are echoed and the commit is aborted.
Thanks, implemented. Now there's still a problem though. The hook will use the current working tree file. If the file is only partially staged (or staged and then edited) it will use the current state instead of the staged one.
My guess is that this would need more low-level git commands, to read the index, echo the contents and pipe them into php -l. Any git gurus around?
It might be possible to do it using git diff-index --cached $against and git cat-file, but I've been unable to parse the former command's output properly. Perhaps it's easier to do it using something other than bash.
I have finally managed to get it working with the methods I described above. It will now fetch the file contents from the index using `git cat-file` instead of using the filesystem. Suggestions and testing are welcome.