jgit/org.eclipse.jgit
Thomas Wolf 60cf85a4a3 Fix core.autocrlf for non-normalized index
With text=auto or core.autocrlf=true, git does not normalize upon
check-in if the file in the index contains already CR/LFs. The
documentation says: "When text is set to "auto", the path is
marked for automatic end-of-line conversion. If Git decides that
the content is text, its line endings are converted to LF on
checkin. When the file has been committed with CRLF, no conversion
is done."[1]

Implement the last bit as in canonical git: check the blob in the
index for CR/LFs. For very large files, we check only the first 8000
bytes, like RawText.isBinary() and AutoLFInputStream do.

In Auto(CR)LFInputStream, ensure that the buffer is filled as much as
possible for the isBinary() check.

Regarding these content checks, there are a number of inconsistencies:

* Canonical git considers files containing lone CRs as binary.
* RawText checks the first 8000 bytes.
* Auto(CR)LFInputStream checks the first 8096 (not 8192!) bytes.

None of these are changed with this commit. It appears that canonical
git will check the whole blob, not just the first 8k bytes. Also
note: the check for CR/LF text won't work with LFS (neither in JGit
nor in git) since the blob data is not run through the smudge filter.
C.f. [2].

Two tests in AddCommandTest actually tested that normalization was
done even if the file was already committed with CR/LF.These tests
had to be adapted. I find the git documentation unclear about the
case where core.autocrlf=input, but from [3] it looks as if this
non-normalization also applies in this case.

Add new tests in CommitCommandTest testing this for the case where
the index entry is for a merge conflict. In this case, canonical git
uses the "ours" version.[4] Do the same.

[1] https://git-scm.com/docs/gitattributes
[2] https://github.com/git/git/blob/3434569fc/convert.c#L225
[3] https://github.com/git/git/blob/3434569fc/convert.c#L529
[4] https://github.com/git/git/blob/f2b6aa98b/read-cache.c#L3281

Bug: 470643
Change-Id: Ie7310539fbe6c737d78b1dcc29e34735d4616b88
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2019-02-26 16:18:27 +09:00
..
.settings Move BaseReceivePack#advertisedRefs getter and setter to ReceivePack 2018-12-29 11:59:27 +01:00
META-INF Prepare 5.3.0-SNAPSHOT builds 2019-01-17 04:23:42 +01:00
findBugs [findBugs] Silence warning about Transport initialization 2012-09-14 00:01:47 +02:00
resources/org/eclipse/jgit JGitText: Remove unnecessary suffix from externalized message identifier 2019-02-25 11:05:44 +09:00
src/org/eclipse/jgit Fix core.autocrlf for non-normalized index 2019-02-26 16:18:27 +09:00
.classpath Change JGit minimum execution environment to JavaSE-1.8 2016-09-20 11:32:36 +02:00
.fbprefs
.gitignore
.project
BUILD Bazel: Format BUILD file with buildifier 2019-01-24 11:43:37 +09:00
about.html SHA-1: collision detection support 2017-02-28 16:38:43 -08:00
build.properties
plugin.properties Remove incubation marker 2011-05-31 22:53:53 +02:00
pom.xml Prepare 5.3.0-SNAPSHOT builds 2019-01-17 04:23:42 +01:00