* Looking for pre-commit hook to check whitespace errors but not for all files
@ 2013-12-14 15:28 Paul Menzel
2013-12-14 16:59 ` John Keeping
2013-12-16 19:06 ` Junio C Hamano
0 siblings, 2 replies; 3+ messages in thread
From: Paul Menzel @ 2013-12-14 15:28 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 1376 bytes --]
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/
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Looking for pre-commit hook to check whitespace errors but not for all files
2013-12-14 15:28 Looking for pre-commit hook to check whitespace errors but not for all files Paul Menzel
@ 2013-12-14 16:59 ` John Keeping
2013-12-16 19:06 ` Junio C Hamano
1 sibling, 0 replies; 3+ messages in thread
From: John Keeping @ 2013-12-14 16:59 UTC (permalink / raw)
To: Paul Menzel; +Cc: git
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 --
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Looking for pre-commit hook to check whitespace errors but not for all files
2013-12-14 15:28 Looking for pre-commit hook to check whitespace errors but not for all files Paul Menzel
2013-12-14 16:59 ` John Keeping
@ 2013-12-16 19:06 ` Junio C Hamano
1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2013-12-16 19:06 UTC (permalink / raw)
To: Paul Menzel; +Cc: git
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-12-16 19:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-14 15:28 Looking for pre-commit hook to check whitespace errors but not for all files Paul Menzel
2013-12-14 16:59 ` John Keeping
2013-12-16 19:06 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).