From: Junio C Hamano <gitster@pobox.com>
To: Jason Spiro <jasonspiro4@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Improving CRLF error message; also, enabling autocrlf and safecrlf by default
Date: Sun, 15 Feb 2009 19:08:53 -0800 [thread overview]
Message-ID: <7vljs7f58a.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <loom.20090216T022524-78@post.gmane.org> (Jason Spiro's message of "Mon, 16 Feb 2009 02:45:43 +0000 (UTC)")
Jason Spiro <jasonspiro4@gmail.com> 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 --
prev parent reply other threads:[~2009-02-16 3:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-16 2:45 Improving CRLF error message; also, enabling autocrlf and safecrlf by default Jason Spiro
2009-02-16 3:04 ` Jeff King
2009-02-16 3:14 ` Junio C Hamano
2009-02-16 3:18 ` Jeff King
2009-02-16 3:29 ` Jason Spiro
2009-02-16 3:43 ` Improving CRLF error message; also, enabling autocrlf and?safecrlf " Jeff King
2009-02-16 3:08 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vljs7f58a.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jasonspiro4@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).