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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 16, 2013, 19:06 UTC
Message-ID
<xmqq8uvkpqcs.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1387034894.4636.9.camel@mattotaupa>
Paul Menzel <paulepanter@users.sourceforge.net> writes:
> 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.
Doesn't hooks/pre-commit.sample we ship already gets this right?
	$ git init foobar && cd foobar
	$ mv .git/hooks/pre-commit.sample .git/hooks/pre-commit
        $ for i in foo bar; do echo $i >$i.txt; done
        $ git commit -m initial
        $ for i in foo bar; do echo "$i " >$i.txt; done
        $ git commit -a
        bar.txt:1: trailing whitespace.
        +bar
        foo.txt:1: trailing whitespace.
        +foo
        $ git commit foo.txt
        foo.txt:1: trailing whitespace.
        +foo
> 2. There are certain files that are allowed to have whitespace errors.

As John Keeping alraedy pointed out, you can use the attributes mechanism to mark what kind of payload each path has to control this kind of thing.

Previous: John Keeping
Message 3 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.