aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2014-12-12 04:57:30 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2014-12-12 04:57:30 -0500
commit42b20d41271a8cd3e3b87513332f64cdd764e6e6 (patch)
tree8338684c205ab1cf0d1fb8fa1f4ff90daf70ba15
parent80b1da1aae418fbfefd99fb88c3588d64e04680b (diff)
parent59c4ea042ca29b5ad6fee2e3c0761e22bdac440f (diff)
downloadjgit-42b20d41271a8cd3e3b87513332f64cdd764e6e6.tar.gz
jgit-42b20d41271a8cd3e3b87513332f64cdd764e6e6.zip
Merge "Fix DirCacheCheckout to set correct file length if core.autocrlf=true" into stable-3.6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java48
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java6
2 files changed, 50 insertions, 4 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
index f13fb20261..f7a50dffcb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
@@ -43,8 +43,8 @@
*/
package org.eclipse.jgit.api;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -78,6 +78,7 @@ import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
@@ -508,4 +509,49 @@ public class CheckoutCommandTest extends RepositoryTestCase {
}
}
+ // TODO: write a faster test which depends less on characteristics of
+ // underlying filesystem/OS.
+ @Test
+ public void testCheckoutAutoCrlfTrue() throws Exception {
+ int nrOfAutoCrlfTestFiles = 200;
+
+ FileBasedConfig c = db.getConfig();
+ c.setString("core", null, "autocrlf", "true");
+ c.save();
+
+ AddCommand add = git.add();
+ for (int i = 100; i < 100 + nrOfAutoCrlfTestFiles; i++) {
+ writeTrashFile("Test_" + i + ".txt", "Hello " + i
+ + " world\nX\nYU\nJK\n");
+ add.addFilepattern("Test_" + i + ".txt");
+ }
+ fsTick(null);
+ add.call();
+ RevCommit c1 = git.commit().setMessage("add some lines").call();
+
+ add = git.add();
+ for (int i = 100; i < 100 + nrOfAutoCrlfTestFiles; i++) {
+ writeTrashFile("Test_" + i + ".txt", "Hello " + i
+ + " world\nX\nY\n");
+ add.addFilepattern("Test_" + i + ".txt");
+ }
+ fsTick(null);
+ add.call();
+ git.commit().setMessage("add more").call();
+
+ git.checkout().setName(c1.getName()).call();
+
+ boolean foundUnsmudged = false;
+ DirCache dc = db.readDirCache();
+ for (int i = 100; i < 100 + nrOfAutoCrlfTestFiles; i++) {
+ DirCacheEntry entry = dc.getEntry(
+ "Test_" + i + ".txt");
+ if (!entry.isSmudged()) {
+ foundUnsmudged = true;
+ assertEquals("unexpected file length in git index", 28,
+ entry.getLength());
+ }
+ }
+ org.junit.Assume.assumeTrue(foundUnsmudged);
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
index c7dd03dd46..692cc8fb58 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
@@ -1245,9 +1245,9 @@ public class DirCacheCheckout {
} finally {
channel.close();
}
- entry.setLength(opt.getAutoCRLF() == AutoCRLF.TRUE
- ? f.length() // AutoCRLF wants on-disk-size
- : (int) ol.getSize());
+ entry.setLength(opt.getAutoCRLF() == AutoCRLF.TRUE ? //
+ tmpFile.length() // AutoCRLF wants on-disk-size
+ : (int) ol.getSize());
if (opt.isFileMode() && fs.supportsExecute()) {
if (FileMode.EXECUTABLE_FILE.equals(entry.getRawMode())) {