threads / patch / 11338

patchallow a single form feed in pre commit hook

Subject: [PATCH] allow a single form feed in pre commit hook

## tl;dr

3 messages between Dec 18, 2007 and Dec 18, 2007. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Hannes Eder· Dec 18, 2007, 09:47 UTC · lore

It's not uncommon to have a lines with a single form feed in it, e.g. the default GPL COPYING and also in .c files and others. Attached patch allows this in the pre-commit hook.

-Hannes
From 454ede83f7a45741d825f0b6cbdb0be2ac235fdb Mon Sep 17 00:00:00 2001
From: Hannes Eder <Hannes@HannesEder.net>
Date: Tue, 18 Dec 2007 10:21:11 +0100
Subject: [PATCH] allow a lines with just one form feed in pre-commit hook
Show changes to templates/hooks--pre-commit +1 −1
diff --git a/templates/hooks--pre-commit b/templates/hooks--pre-commit
index 7092bae..a759f92 100644
--- a/templates/hooks--pre-commit
+++ b/templates/hooks--pre-commit
@@ -55,7 +55,7 @@ perl -e '
 	if (s/^\+//) {
 	    $lineno++;
 	    chomp;
-	    if (/\s$/) {
+	    if (!/^\f$/ && /\s$/) {
 		bad_line("trailing whitespace", $_);
 	    }
 	    if (/^\s* \t/) {
Junio C Hamano· Dec 18, 2007, 10:18 UTC · re: Hannes Eder · lore

Re: [PATCH] allow a single form feed in pre commit hook

"Hannes Eder" <hannes.eder@gmail.com> writes:
> It's not uncommon to have a lines with a single form feed in it, e.g.
> the default GPL COPYING and also in .c files and others. Attached
> patch allows this in the pre-commit hook.

Hmm. The current trend is to get rid of the whitespace checks from this hook and enrich git-diff --check and git-apply --whitespace=error.

I've been planning to add a new whitespace error rule that allows ^M at the end of line, post 1.5.4. Another rule that allows a lone ^L would match what you are doing here, and it would be a good addition as well.

Jakub Narebski· Dec 18, 2007, 10:27 UTC · re: Junio C Hamano · lore

Re: [PATCH] allow a single form feed in pre commit hook

Junio C Hamano <gitster@pobox.com> writes:
Show 12 quoted lines
> "Hannes Eder" <hannes.eder@gmail.com> writes:
> 
> > It's not uncommon to have a lines with a single form feed in it, e.g.
> > the default GPL COPYING and also in .c files and others. Attached
> > patch allows this in the pre-commit hook.
> 
> Hmm.  The current trend is to get rid of the whitespace checks from this
> hook and enrich git-diff --check and git-apply --whitespace=error.
> 
> I've been planning to add a new whitespace error rule that allows ^M at
> the end of line, post 1.5.4.  Another rule that allows a lone ^L would
> match what you are doing here, and it would be a good addition as well.
 
There probably should also be 'trailing-empty-lines' rule; also
'eol-at-eof' could be useful as well (ensuring that final line ends
with newline character).

By the way, the check in pre-commit hook also checks for merge conflict markers. Those are not whitespace errors, but are quite similar. It would be nice to have this also .gitattributes controlled, to avoid false positoves for changes in Documentation/*.txt; althought perhaps more strict checking would be enough...

-- 
Jakub Narebski
Poland
ShadeHawk on #git

← back to recent threads