Many version control systems have some sort of hook that one can use to do things at a certain time. For example, when committing java code, one could put commit hooks in place such that before someone can commit, it runs the unit tests and they must pass. A similar approach can be used here.
git has several commit hooks, of the ones you'd most likely look at using:
These are run before or after the commit or push (on the server, receiving). There are several others that get into more particular spots of the git workflow.
The combination of tidy to validate the code and a commit hook on the source. Write a little script that would look something like (note, this code may not work - I haven't tested it, its more just a get an idea of what you would be doing):
#!/bin/bash
bad=0;
git diff --cached --name-status | while read st file; do
# Skip deleted files.
if [ "$st" == 'D' ]; then continue; fi
if [[ $file =~ ".html ]] ; then
tidy $file
if [ $? != 0 ] ; then
echo "$file failed validation"
bad = 1
fi
fi
done
if [ $bad ] ; then
echo "rejecting commit"
exit 1
fi
Please write this in your preferred scripting language - hopefully its not bash.
This loops over the files being committed that are html files and then runs tidy against them. If tidy has a non-zero exit code, it says it failed validation. If any files fail to validate, it exits with a non-zero code which then would have the git hook fail the precommit.
Given the html nature of this, you may also find Deploying Websites With a Tiny Git Hook to be a useful read which works on a post receive hook on a server to copy the files committed into the webserver's htdocs.