Re: Improving CRLF error message; also, enabling autocrlf and safecrlf by default

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jason Spiro <jasonspiro4@xxxxxxxxx> writes:

> One of the pre-commit hooks detects trailing whitespace:

All sample hooks are shipped disabled by default, so it shouldn't be
triggering unless you enabled it yourself.  The only known exception is
the binary packaged one for Cygwin, which we do not have much control over
here.

> if (/\s$/) {
> bad_line("trailing whitespace", $_);
> }
>
> Unfortunately, when I try to check in a file with DOS (CR+LF) line endings, 
> this hook triggers on every line.  This happens on Cygwin.  I haven't checked, 
> but I bet it happens on other platforms as well, as long as this hook runs.
>
> But the error message "trailing whitespace" doesn't clearly tell me what's 
> wrong.

I and other people agreed with your analysis above wholeheartedly several
months ago, and as a result, v1.6.0 and later version of git use a
different implementation for this check in the sample hook.  It does know
your CRLF line endings and therefore it should behave much better.

The fix to your situation might be just the matter of taking a copy of
templates/hooks--pre-commit.sample from the current git source code and
replacing .git/hooks/pre-commit in your repository.

The sample hook looks like the attached one these days.  It relies on an
enhancement 346245a (hard-code the empty tree object, 2008-02-13) that
appeared first in v1.5.5 so it may not work if your copy of git is older
than that version.

-- >8 -- cut here -- >8 --
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by git-commit with no arguments.  The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".

if git-rev-parse --verify HEAD 2>/dev/null
then
	against=HEAD
else
	# Initial commit: diff against an empty tree object
	against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

exec git diff-index --check --cached $against --
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux