]> git.ipfire.org Git - thirdparty/git.git/commit
convert: Correct NNO tests and missing `LF will be replaced by CRLF`
authorTorsten Bögershausen <tboegi@web.de>
Sat, 13 Aug 2016 21:29:27 +0000 (23:29 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 14 Aug 2016 20:45:52 +0000 (13:45 -0700)
commita0ad53c18100226cb1a138cb9b3bc3615170be8f
tree7e02e1c5e093e0f955689a3a3c7219579ab0f2bc
parent1335d76e4569fa84e52dc24c88c04daeae6e160e
convert: Correct NNO tests and missing `LF will be replaced by CRLF`

When a non-reversible CRLF conversion is done in "git add",
a warning is printed on stderr (or Git dies, depending on checksafe)

The function commit_chk_wrnNNO() in t0027 was written to test this,
but did the wrong thing: Instead of looking at the warning
from "git add", it looked at the warning from "git commit".

This is racy because "git commit" may not have to do CRLF conversion
at all if it can use the sha1 value from the index (which depends on
whether "add" and "commit" run in a single second).

Correct t0027 and replace the commit for each and every file with a commit
of all files in one go.
The function commit_chk_wrnNNO() should be renamed in a separate commit.

Now that t0027 does the right thing, it detects a bug in covert.c:
This sequence should generate the warning `LF will be replaced by CRLF`,
but does not:

$ git init
$ git config core.autocrlf false
$ printf "Line\r\n" >file
$ git add file
$ git commit -m "commit with CRLF"
$ git config core.autocrlf true
$ printf "Line\n" >file
$ git add file

"git add" calls crlf_to_git() in convert.c, which calls check_safe_crlf().
When has_cr_in_index(path) is true, crlf_to_git() returns too early and
check_safe_crlf() is not called at all.

Factor out the code which determines if "git checkout" converts LF->CRLF
into will_convert_lf_to_crlf().

Update the logic around check_safe_crlf() and "simulate" the possible
LF->CRLF conversion at "git checkout" with help of will_convert_lf_to_crlf().
Thanks to Jeff King <peff@peff.net> for analyzing t0027.

Reported-By: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
convert.c
t/t0027-auto-crlf.sh