Ignore core.eol if core.autocrlf=input

Config core.eol is to be ignored if core.autocrlf is true or input.[1]
JGit didn't do so when core.autocrlf=input was set.

[1] https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreeol

Bug: 561877
Change-Id: I5e62e0510d160b5113c1090319af09c2bc1bcb59
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
This commit is contained in:
Thomas Wolf 2020-04-08 00:07:47 +02:00
parent 3c34e0acbf
commit 3dbd1f2fe7
2 changed files with 34 additions and 0 deletions

View File

@ -26,7 +26,9 @@
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils;
import org.junit.Test;
@ -38,6 +40,36 @@
*/
public class AttributeFileTests extends RepositoryTestCase {
@Test
public void testTextAutoCoreEolCoreAutoCrLfInput() throws Exception {
FileBasedConfig cfg = db.getConfig();
cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_AUTOCRLF, false);
cfg.save();
final String content = "Line1\nLine2\n";
try (Git git = Git.wrap(db)) {
writeTrashFile(".gitattributes", "* text=auto");
File dummy = writeTrashFile("dummy.txt", content);
git.add().addFilepattern(".").call();
git.commit().setMessage("Commit with LF").call();
assertEquals("Unexpected index state",
"[.gitattributes, mode:100644, content:* text=auto]"
+ "[dummy.txt, mode:100644, content:" + content
+ ']',
indexState(CONTENT));
assertTrue("Should be able to delete " + dummy, dummy.delete());
cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_EOL, "crlf");
cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_AUTOCRLF, "input");
cfg.save();
git.reset().setMode(ResetType.HARD).call();
assertTrue("File " + dummy + "should exist", dummy.isFile());
String textFile = RawParseUtils.decode(IO.readFully(dummy, 512));
assertEquals("Unexpected text content", content, textFile);
}
}
@Test
public void testTextAutoEolLf() throws Exception {
writeTrashFile(".gitattributes", "* text=auto eol=lf");

View File

@ -168,6 +168,8 @@ private static EolStreamType getOutputFormat(WorkingTreeOptions options) {
switch (options.getAutoCRLF()) {
case TRUE:
return EolStreamType.TEXT_CRLF;
case INPUT:
return EolStreamType.DIRECT;
default:
// no decision
}