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

Re: [PATCH] pre-commit hook should ignore carriage returns at EOL

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 24, 2008, 22:31 UTC
Message-ID
<7v3an2bh3b.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<39C2861E-F800-40AE-8C15-4FC3BB51EF16@gmail.com>
Christian Holtje <docwhat@gmail.com> writes:
> The code is checking for \r$ and then doing a different space check
> depending on that, not one after another.
>
> Thanks for the feedback. I'll put up v2 in a second.
Please don't.

It's an ancient sample hook that is not be enabled by default. I do not want people to be wasting too much time on the relic.

However, if this sample is to be changed at all, please do it right.

If somebody suddenly adds CR at the end of an existing file that ought to have LF line endings, we _DO_ want to catch that as a breakage. So the title of the commit "should ignore carriage returns at EOL" is WRONG. It shouldn't, in general.

One thing the hook could and probably should do these days is if the file type says you _ought to_ have CRLF line endings, actively make sure your lines do end with CRLF (this is a much stronger and better check than blindly ignoring CR before LF for such files). And on the other hand, if the file should end with LF, do make sure it does not have CR before it.

The person who did the sample hook you are looking at couldn't do so because there weren't autocrlf nor gitattributes(5) facility back then. But you can use them now to rewrite this properly.

I wonder if "git diff --check" can be used for most if not all of the checking, without the big Perl script you are touching in your patch. That facility did not exist when the current sample hook was written, either.

Previous: Christian HoltjeNext: Christian Holtje
Message 9 of 21 in “pre-commit hook should ignore carriage returns at EOL”
  1. pre-commit hook should ignore carriage returns at EOLChristian Holtje, Jun 24, 2008
  2. Alf ClementJun 24, 2008
  3. Ian HiltJun 24, 2008
  4. Jakub NarebskiJun 24, 2008
  5. Ian HiltJun 24, 2008
  6. Jakub NarebskiJun 24, 2008
  7. Ian HiltJun 24, 2008
  8. Christian HoltjeJun 24, 2008
  9. Junio C HamanoJun 24, 2008
  10. Christian HoltjeJun 24, 2008
  11. Jakub NarebskiJun 24, 2008
  12. Junio C HamanoJun 24, 2008
  13. Christian HoltjeJun 25, 2008
  14. Junio C HamanoJun 24, 2008
  15. Ship sample hooks with .sample suffixJunio C Hamano, Jun 25, 2008
  16. Junio C HamanoJun 25, 2008
  17. Johannes SixtJun 25, 2008
  18. Junio C HamanoJun 25, 2008
  19. Johannes SixtJun 26, 2008
  20. Junio C HamanoJun 26, 2008
  21. Peter BaumannJun 25, 2008

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.