[bind10-dev] git hook for whitespace checking

Jeremy C. Reed jreed at isc.org
Mon Jul 8 14:37:28 UTC 2013


I use a hook at .git/hooks/pre-commit

The git installation usually provides a 
templates/hooks/pre-commit.sample file.

You can copy the script into place (without the .sample extension) as an 
executable.

It has a line like:

# If there are whitespace errors, print the offending file names and fail.
exec git diff-index --check --cached $against --

See the git-diff-index manual about the --check option. And look at the 
core.whitespace tunable documented at
http://git-scm.com/book/ch7-1.html
Maybe we should consider indent-with-non-tab also, like the following:

  git config --global core.whitespace \
      trailing-space,space-before-tab,indent-with-non-tab

We discussed this briefly during a bi-weekly meeting recently.  I 
sometimes need to disable this or fix lots of whitespace when I try to 
commit changes due to unrelated whitespace inconsistencies.

Also see the git-apply manual about --whitespace. This is about 
checking changed lines only where diff-index --check checks all 
lines. There is a "--whitespace=fix" option also.

  Jeremy C. Reed
  ISC


More information about the bind10-dev mailing list