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

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

From
Christian Holtje <docwhat@gmail.com>
Date
Jun 25, 2008, 18:47 UTC
Message-ID
<5B163827-204D-4F76-88C9-8F0C93E60AF3@gmail.com>
In-Reply-To
<20080625181422.GC4039@steel.home>
On Jun 25, 2008, at 2:14 PM, Alex Riesen wrote:
Show 36 quoted lines
> Christian Holtje, Tue, Jun 24, 2008 21:21:22 +0200:
>> diff --git a/t/t7503-template-hook--pre-commit.sh b/t/t7503-template-
>> hook--pre-commit.sh
>
> Your patch has long lines wrapped.
>
>> diff --git a/templates/hooks--pre-commit b/templates/hooks--pre- 
>> commit
>> index b25dce6..335ca09 100644
>> --- a/templates/hooks--pre-commit
>> +++ b/templates/hooks--pre-commit
>> @@ -55,8 +55,14 @@ perl -e '
>> 	if (s/^\+//) {
>> 	    $lineno++;
>> 	    chomp;
>> -	    if (/\s$/) {
>> -		bad_line("trailing whitespace", $_);
>> +	    if (/\r$/) {
>> +		if (/\s\r$/) {
>> +		    bad_line("trailing whitespace", $_);
>> +		}
>> +	    } else {
>> +		if (/\s$/) {
>> +		    bad_line("trailing whitespace", $_);
>> +		}
>
> You coud just strip the trailing (cr)lf, instead of chomp:
>
>  	if (s/^\+//) {
>  	    $lineno++;
> - 	    chomp;
> +	    s/\r?\n$//so;
> 	    if (/\s$/) {
> 		bad_line("trailing whitespace", $_);
>
> Makes for a shorter patch and less code.

That's a good idea! However, this patch is not going anyplace, I think. Junio submitted a different patch to disable the pre-commit example.

Junio, do you want me to make this change anyway? It does make sense. The unittests for the pre-commit hook may or may not still be useful.

Ciao!
Previous: Alex RiesenNext: Junio C Hamano
Message 3 of 14 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. Alex RiesenJun 25, 2008
  3. Christian HoltjeJun 25, 2008
  4. Junio C HamanoJun 25, 2008
  5. Christian HoltjeJun 26, 2008
  6. Junio C HamanoJun 26, 2008
  7. 1/5 diff --check: explain why we do not care whether old side is binaryJunio C Hamano, Jun 26, 2008
  8. 2/5 check_and_emit_line(): rename and refactorJunio C Hamano, Jun 26, 2008
  9. 3/5 checkdiff: pass diff_options to the callbackJunio C Hamano, Jun 26, 2008
  10. 4/5 Teach "diff --check" about a new blank lines at endJunio C Hamano, Jun 26, 2008
  11. 5/5 diff --check: detect leftover conflict markersJunio C Hamano, Jun 26, 2008
  12. Junio C HamanoJun 26, 2008
  13. Junio C HamanoJun 26, 2008
  14. Jeff KingJun 27, 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.