git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Torsten Bögershausen" <tboegi@web.de>
To: Alexandre Garnier <zigarn@gmail.com>, git@vger.kernel.org
Subject: Re: [BUG] Git does not convert CRLF=>LF on files with \r not before \n
Date: Tue, 21 Apr 2015 21:28:11 +0200	[thread overview]
Message-ID: <5536A4CB.9050000@web.de> (raw)
In-Reply-To: <CAFFOgCUTxnbL7vJpf1Hw39CJL_p2raDZ2a3DehhYhdbkVyi2fw@mail.gmail.com>

On 2015-04-21 15.51, Alexandre Garnier wrote:
> Here is a test:
> 
> git init -q crlf-test
> cd crlf-test
> echo '*       text=auto' > .gitattributes
> git add .gitattributes
> git commit -q -m "Normalize EOL"
> echo -ne 'some content\r\nother \rcontent with CR\r\ncontent\r\nagain
> content with\r\r\n' > inline-cr.txt
> echo "Working directory content:"
> cat -A inline-cr.txt
> echo
> git add inline-cr.txt
> echo "Indexed content:"
> git show :inline-cr.txt | cat -A
> 
> Result
> ------
> File content:
> some content^M$
> other ^Mcontent with CR^M$
> content^M$
> again content with^M^M$
> 
> Indexed content:
> some content^M$
> other ^Mcontent with CR^M$
> content^M$
> again content with^M^M$
> 
> Expected result
> ---------------
> File content:
> some content^M$
> other ^Mcontent with CR^M$
> content^M$
> again content with^M^M$
> 
> Indexed content:
> some content$
> other ^Mcontent with CR$
> content$
> again content with^M$
> # or even 'again content with$' for this last line
> 
> If you remove the \r that are not at the end of the lines, EOL are
> converted as expected:
> File content:
> some content^M$
> other content with CR^M$
> content^M$
> again content with^M$
> 
> Indexed content:
> some content$
> other content with CR$
> content$
> again content with$
> 

First of all, thanks for the info.

The current implementation of Git does an auto-detection
if a file is text or binary.

For a file which is "suspected to be text", it is expected to have either LF or CRLF as
line endings, but a "bare CR" make Git wonder:
Should this still be treated as a text file ?
If yes, should the CR be kept as is, or should it be converted into LF (or CRLF) ?

The current implementation may simply be explained by the fact that nobody has so far asked 
to treat this file as "text", so the implementation assumes it to be binary.

(Which makes the code a little bit easier, at the time it was written)

So the status of today is that you can force Git to let the CR as is,
when you specify that the file is "text".

Is there a real life problem behind it ?
And what should happen to the CRs ?

  parent reply	other threads:[~2015-04-21 19:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-21 13:51 [BUG] Git does not convert CRLF=>LF on files with \r not before \n Alexandre Garnier
2015-04-21 17:41 ` Junio C Hamano
2015-04-22 17:42   ` Junio C Hamano
2015-04-21 19:28 ` Torsten Bögershausen [this message]
2015-04-22 13:06   ` Alexandre Garnier

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=5536A4CB.9050000@web.de \
    --to=tboegi@web.de \
    --cc=git@vger.kernel.org \
    --cc=zigarn@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).