git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Looking for pre-commit hook to check whitespace errors but not for all files

From
PMPaul Menzel <paulepanter@users.sourceforge.net>
Date
Dec 14, 2013, 15:28 UTC
Message-ID
<1387034894.4636.9.camel@mattotaupa>
Dear git folks,

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?
Thanks,
Paul

[1] http://review.coreboot.org/gitweb?p=coreboot.git;a=blob;f=util/lint/lint-stable-003-whitespace;h=1e824a1e76e37ce641b91c75f2f78e0e2abfd37f;hb=HEAD [2] http://review.coreboot.org/#/c/3340/

Next: John Keeping
Message 1 of 3 in “Looking for pre-commit hook to check whitespace errors but not for all files”
  1. Paul MenzelDec 14, 2013
  2. John KeepingDec 14, 2013
  3. Junio C HamanoDec 16, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.