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

Re: [PATCH] .gitattributes: CR at the end of the line is an error

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 21, 2009, 09:31 UTC
Message-ID
<7vvdmqrl06.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20090619194253.6117@nanako3.lavabit.com>
Nanako Shiraishi <nanako3@lavabit.com> writes:
Show 23 quoted lines
> When a CR is accidentally added at the end of a C source file in the git
> project tree, "git diff --check" doesn't detect it as an error.
>
>     $ echo abQ | tr Q '\015' >>fast-import.c
>     $ git diff --check
>
> I think this is because the "whitespace" attribute is set to *.[ch] files
> without specifying what kind of errors are caught. It makes git "notice
> all types of errors" (as described in the documentation), but I think it
> is incorrectly setting cr-at-eol, too, and hides this error.
>
> Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com>
> ---
>
> diff --git a/.gitattributes b/.gitattributes
> index 6b9c715..bb03350 100644
> --- a/.gitattributes
> +++ b/.gitattributes
> @@ -1,2 +1,2 @@
>  * whitespace=!indent,trail,space
> -*.[ch] whitespace
> +*.[ch] whitespace=indent,trail,space
>
I like the result of applying this patch to my tree.

A "whitespace" attribute that is Set, which is what the original has, is defined to "notice all types of errors known to git", it is a poor way to define the project policy, which was what 14f9e12 (Define the project whitespace policy, 2008-02-10) tried to do. It means the policy will silently change when newer git learns to detect more types of whitespace errors.

And it never meant to allow trailing carriage-returns. I think the implementation of whitespace attribute handling is broken.

Previous: Nanako ShiraishiNext: Junio C Hamano
Message 2 of 3 in “.gitattributes: CR at the end of the line is an error”
  1. .gitattributes: CR at the end of the line is an errorNanako Shiraishi, Jun 19, 2009
  2. Junio C HamanoJun 21, 2009
  3. attribute: whitespace set to true detects all errors known to gitJunio C Hamano, Jun 21, 2009

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.