On Sat, Dec 14, 2013 at 04:28:14PM +0100, Paul Menzel wrote:
> in coreboot we try to check for whitespace errors before committing. Of
> course a pre-commit hook is the way to go, but unfortunately it is not
> so simple (at least for me) as the following requirements exist.
> 
> 1. Only the files actually committed should be checked. That means
> running `git commit -a`, abort that and then running `git commit
> some/file` should only check `some/file` for whitespace errors.
> 
> 2. There are certain files that are allowed to have whitespace errors.
> In our case these are `*.patch` and `*.diff` files which by design seem
> to contain whitespace error.
> 
> Currently the whole tree is checked, which takes a lot of time [1].
> 
> I tried to come up with a patch [2], but failed so far. Best would be to
> have
> 
>     $ git diff --check --only-committed-files --exclude "*patch$"
> 
> where I could not find a way for the last to switches.
> 
> Currently, I would use
> 
>     $ git diff-index --cached --name-only $against -- | grep -v patch$
> 
> and pass that list to some whitespace check program. Unfortunately that
> still does not fulfill the first requirement.
> 
> What am I missing to solve this elegantly?

I think you want to combine .gitattributes with something like the
diff-index above:

        $ cat >.gitattributes <<-EOF
        *.patch whitespace=false
        *.diff whitespace=false
        EOF

        $ git diff-index --check --cached $against --
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to