diff options
author | Thomas Wolf <thomas.wolf@paranor.ch> | 2020-04-08 00:07:47 +0200 |
---|---|---|
committer | Thomas Wolf <thomas.wolf@paranor.ch> | 2020-05-22 17:09:23 -0400 |
commit | 3dbd1f2fe70f6f0ca25ad4278cb976e0d2ddb65a (patch) | |
tree | 408f2c9df69c5ec81da26b02f55ce4d68aca88bc /org.eclipse.jgit.test | |
parent | 3c34e0acbfcac236daaf746690130c6e99a8e524 (diff) | |
download | jgit-3dbd1f2fe70f6f0ca25ad4278cb976e0d2ddb65a.tar.gz jgit-3dbd1f2fe70f6f0ca25ad4278cb976e0d2ddb65a.zip |
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>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributeFileTests.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributeFileTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributeFileTests.java index 7b90dcda08..5d05a98d66 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributeFileTests.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributeFileTests.java @@ -26,7 +26,9 @@ import org.eclipse.jgit.api.ResetCommand.ResetType; 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; @@ -39,6 +41,36 @@ import org.junit.Test; 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"); performTest("Test\r\nFile", "Test\nFile", "Test\nFile"); |