aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache
diff options
context:
space:
mode:
authorShawn Pearce <sop@google.com>2015-12-28 11:43:07 -0800
committerShawn Pearce <spearce@spearce.org>2015-12-29 11:33:39 -0800
commitb71ba69410db5e50dd10c5c40e96699c9de7e5e8 (patch)
treeade2fc61b6f11425e5508b88bc0d814650358042 /org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache
parent3776b14ab45ca1daf0771fa1a8245bc097ec2e12 (diff)
downloadjgit-b71ba69410db5e50dd10c5c40e96699c9de7e5e8.tar.gz
jgit-b71ba69410db5e50dd10c5c40e96699c9de7e5e8.zip
DirCacheEditor: Replace file-with-tree and tree-with-file
If a PathEdit tries to store a file where a subtree was, or a subtree where a file was, replace the entry in the DirCache with the new name(s). This supports switching between file and tree entry types using a DirCacheEditor. Add new unit tests to cover the conditions where these can happen. Change-Id: Ie843d9388825f9e3d918a5666aa04e47cd6306e7
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.java58
1 files changed, 58 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 63ec85861d..3988f6a4c4 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
@@ -154,6 +154,64 @@ public class DirCachePathEditTest {
assertEquals(DirCacheEntry.STAGE_3, entries.get(2).getStage());
}
+ @Test
+ public void testFileReplacesTree() throws Exception {
+ DirCache dc = DirCache.newInCore();
+ DirCacheEditor editor = dc.editor();
+ editor.add(new AddEdit("a"));
+ editor.add(new AddEdit("b/c"));
+ editor.add(new AddEdit("b/d"));
+ editor.add(new AddEdit("e"));
+ editor.finish();
+
+ editor = dc.editor();
+ editor.add(new AddEdit("b"));
+ editor.finish();
+
+ assertEquals(3, dc.getEntryCount());
+ assertEquals("a", dc.getEntry(0).getPathString());
+ assertEquals("b", dc.getEntry(1).getPathString());
+ assertEquals("e", dc.getEntry(2).getPathString());
+
+ dc.clear();
+ editor = dc.editor();
+ editor.add(new AddEdit("A.c"));
+ editor.add(new AddEdit("A/c"));
+ editor.add(new AddEdit("A0c"));
+ editor.finish();
+
+ editor = dc.editor();
+ editor.add(new AddEdit("A"));
+ editor.finish();
+ assertEquals(3, dc.getEntryCount());
+ assertEquals("A", dc.getEntry(0).getPathString());
+ assertEquals("A.c", dc.getEntry(1).getPathString());
+ assertEquals("A0c", dc.getEntry(2).getPathString());
+ }
+
+ @Test
+ public void testTreeReplacesFile() throws Exception {
+ DirCache dc = DirCache.newInCore();
+ DirCacheEditor editor = dc.editor();
+ editor.add(new AddEdit("a"));
+ editor.add(new AddEdit("ab"));
+ editor.add(new AddEdit("b"));
+ editor.add(new AddEdit("e"));
+ editor.finish();
+
+ editor = dc.editor();
+ editor.add(new AddEdit("b/c/d/f"));
+ editor.add(new AddEdit("b/g/h/i"));
+ editor.finish();
+
+ assertEquals(5, dc.getEntryCount());
+ assertEquals("a", dc.getEntry(0).getPathString());
+ assertEquals("ab", dc.getEntry(1).getPathString());
+ assertEquals("b/c/d/f", dc.getEntry(2).getPathString());
+ assertEquals("b/g/h/i", dc.getEntry(3).getPathString());
+ assertEquals("e", dc.getEntry(4).getPathString());
+ }
+
private static DirCacheEntry createEntry(String path, int stage) {
DirCacheEntry entry = new DirCacheEntry(path, stage);
entry.setFileMode(FileMode.REGULAR_FILE);