Skip to content
  • Torsten Bögershausen's avatar
    convert: Correct NNO tests and missing `LF will be replaced by CRLF` · a0ad53c1
    Torsten Bögershausen authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    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: default avatarJohannes Schindelin <Johannes.Schindelin@gmx.de>
    Signed-off-by: default avatarTorsten Bögershausen <tboegi@web.de>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    a0ad53c1