aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2015-12-18 14:31:20 -0800
committerShawn Pearce <spearce@spearce.org>2015-12-29 11:33:39 -0800
commit683c41af92d248c818dcddb4d86c1640eba79374 (patch)
tree160d044601a191dc725a8dca24f92056978e106b /org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache
parentb71ba69410db5e50dd10c5c40e96699c9de7e5e8 (diff)
downloadjgit-683c41af92d248c818dcddb4d86c1640eba79374.tar.gz
jgit-683c41af92d248c818dcddb4d86c1640eba79374.zip
DirCache: Do not create duplicate tree entries
If a file (e.g. "A") and a subtree file (e.g. "A/foo.c") both appear in the DirCache this cache should not be written out as a tree object. The "A" file and "A" subtree conflict with each other in the same tree and will fail fsck. Detect this condition during DirCacheBuilder and DirCacheEditor finish() so the application can be halted early before it updates a DirCache that might later write an invalid tree structure. Change-Id: I95660787e88df336297949b383f4c5fda52e75f5
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java
index 3988f6a4c4..39a0cdac5f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java
@@ -43,11 +43,13 @@
package org.eclipse.jgit.dircache;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit;
+import org.eclipse.jgit.errors.DirCacheNameConflictException;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.junit.Test;
@@ -212,6 +214,50 @@ public class DirCachePathEditTest {
assertEquals("e", dc.getEntry(4).getPathString());
}
+ @Test
+ public void testFileOverlapsTree() throws Exception {
+ DirCache dc = DirCache.newInCore();
+ DirCacheEditor editor = dc.editor();
+ editor.add(new AddEdit("a"));
+ editor.add(new AddEdit("a/b").setReplace(false));
+ try {
+ editor.finish();
+ fail("Expected DirCacheNameConflictException to be thrown");
+ } catch (DirCacheNameConflictException e) {
+ assertEquals("a a/b", e.getMessage());
+ assertEquals("a", e.getPath1());
+ assertEquals("a/b", e.getPath2());
+ }
+
+ editor = dc.editor();
+ editor.add(new AddEdit("A.c"));
+ editor.add(new AddEdit("A/c").setReplace(false));
+ editor.add(new AddEdit("A0c"));
+ editor.add(new AddEdit("A"));
+ try {
+ editor.finish();
+ fail("Expected DirCacheNameConflictException to be thrown");
+ } catch (DirCacheNameConflictException e) {
+ assertEquals("A A/c", e.getMessage());
+ assertEquals("A", e.getPath1());
+ assertEquals("A/c", e.getPath2());
+ }
+
+ editor = dc.editor();
+ editor.add(new AddEdit("A.c"));
+ editor.add(new AddEdit("A/b/c/d").setReplace(false));
+ editor.add(new AddEdit("A/b/c"));
+ editor.add(new AddEdit("A0c"));
+ try {
+ editor.finish();
+ fail("Expected DirCacheNameConflictException to be thrown");
+ } catch (DirCacheNameConflictException e) {
+ assertEquals("A/b/c A/b/c/d", e.getMessage());
+ assertEquals("A/b/c", e.getPath1());
+ assertEquals("A/b/c/d", e.getPath2());
+ }
+ }
+
private static DirCacheEntry createEntry(String path, int stage) {
DirCacheEntry entry = new DirCacheEntry(path, stage);
entry.setFileMode(FileMode.REGULAR_FILE);