summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2013-12-26 01:22:04 +0100
committerRobin Stocker <robin@nibor.org>2014-02-02 13:16:19 +0100
commit5404e70dc64201786cd6a21efb41310912860122 (patch)
treebb3ac6ab7850c50f8a59e755578ca14b3a88e158 /org.eclipse.jgit.test/tst
parent8352d1729ca63d4d6d831b2da0b168c950bc6f52 (diff)
downloadjgit-5404e70dc64201786cd6a21efb41310912860122.tar.gz
jgit-5404e70dc64201786cd6a21efb41310912860122.zip
Fix for core.autocrlf=input resulting in modified file
This version does not attempt to unsmudge, unlike the first attempt in Idafad150553df14827eccfde2e3b95760e16a8b6. Bug: 372834 Change-Id: I9300e735cb16d6208e1df963abb1ff69f688155d Also-by: Robin Stocker <robin@nibor.org> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com> Signed-off-by: Robin Stocker <robin@nibor.org>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java31
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java12
2 files changed, 40 insertions, 3 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
index 64e72e8fc7..a1e16e4cf7 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
@@ -68,9 +68,11 @@ import org.eclipse.jgit.dircache.DirCacheEditor;
import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.lib.CoreConfig.AutoCRLF;
import org.eclipse.jgit.lib.IndexDiff.StageState;
import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.util.IO;
import org.junit.Test;
@@ -576,6 +578,35 @@ public class IndexDiffTest extends RepositoryTestCase {
assertTrue(StageState.BOTH_ADDED.hasTheirs());
}
+ @Test
+ public void testAutoCRLFInput() throws Exception {
+ Git git = new Git(db);
+ FileBasedConfig config = db.getConfig();
+
+ // Make sure core.autocrlf is false before adding
+ config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
+ ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.FALSE);
+ config.save();
+
+ // File is already in repository with CRLF
+ writeTrashFile("crlf.txt", "this\r\ncontains\r\ncrlf\r\n");
+ git.add().addFilepattern("crlf.txt").call();
+ git.commit().setMessage("Add crlf.txt").call();
+
+ // Now set core.autocrlf to input
+ config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
+ ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.INPUT);
+ config.save();
+
+ FileTreeIterator iterator = new FileTreeIterator(db);
+ IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
+ diff.diff();
+
+ assertTrue(
+ "Expected no modified files, but there were: "
+ + diff.getModified(), diff.getModified().isEmpty());
+ }
+
private void verifyStageState(StageState expected, int... stages)
throws IOException {
DirCacheBuilder builder = db.lockDirCache().builder();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
index 6014f3b60e..4ce4c8d04f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
@@ -223,7 +223,9 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
ObjectId fromRaw = ObjectId.fromRaw(fti.idBuffer(), fti.idOffset());
assertEquals("6b584e8ece562ebffc15d38808cd6b98fc3d97ea",
fromRaw.getName());
- assertFalse(fti.isModified(dce, false));
+ ObjectReader objectReader = db.newObjectReader();
+ assertFalse(fti.isModified(dce, false, objectReader));
+ objectReader.release();
}
@Test
@@ -242,7 +244,9 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
.getConfig().get(WorkingTreeOptions.KEY));
while (!fti.getEntryPathString().equals("symlink"))
fti.next(1);
- assertFalse(fti.isModified(dce, false));
+ ObjectReader objectReader = db.newObjectReader();
+ assertFalse(fti.isModified(dce, false, objectReader));
+ objectReader.release();
}
@Test
@@ -265,7 +269,9 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
// If the rounding trick does not work we could skip the compareMetaData
// test and hope that we are usually testing the intended code path.
assertEquals(MetadataDiff.SMUDGED, fti.compareMetadata(dce));
- assertTrue(fti.isModified(dce, false));
+ ObjectReader objectReader = db.newObjectReader();
+ assertTrue(fti.isModified(dce, false, objectReader));
+ objectReader.release();
}
@Test