post-commit — Notification of a successful commit.
The post-commit hook is run after the transaction is committed, and a new revision created. Most people use this hook to send out descriptive emails about the commit or to notify some other tool (such as an issue tracker) that a commit has happened. Some configurations also use this hook to trigger backup processes.
The output from, and exit value returned by the post-commit hook program are ignored.
What you want is a pre-commit hook (kind of obvious once you think about those names):
pre-commit — Notification just prior to commit completion.
The pre-commit hook is run just before a commit transaction is promoted to a new revision. Typically, this hook is used to protect against commits that are disallowed due to content or location (for example, your site might require that all commits to a certain branch include a ticket number from the bug tracker, or that the incoming log message is non-empty).
If the pre-commit hook program returns a non-zero exit value, the commit is aborted, the commit transaction is removed, and anything printed to stderr is marshalled back to the client.
Also, make sure to make the script file executable, and use the exact name
post-commit, i.e. without file name extension!