assertEquals(bEntry.getLastModified(), mixedBEntry.getLastModified());
}
+ @Test
+ public void testMixedResetWithUnmerged() throws Exception {
+ git = new Git(db);
+
+ String file = "a.txt";
+ writeTrashFile(file, "data");
+ String file2 = "b.txt";
+ writeTrashFile(file2, "data");
+
+ git.add().addFilepattern(file).addFilepattern(file2).call();
+ git.commit().setMessage("commit").call();
+
+ DirCache index = db.lockDirCache();
+ DirCacheBuilder builder = index.builder();
+ builder.add(createEntry(file, FileMode.REGULAR_FILE, 1, ""));
+ builder.add(createEntry(file, FileMode.REGULAR_FILE, 2, ""));
+ builder.add(createEntry(file, FileMode.REGULAR_FILE, 3, ""));
+ assertTrue(builder.commit());
+
+ assertEquals("[a.txt, mode:100644, stage:1]"
+ + "[a.txt, mode:100644, stage:2]"
+ + "[a.txt, mode:100644, stage:3]",
+ indexState(0));
+
+ git.reset().setMode(ResetType.MIXED).call();
+
+ assertEquals("[a.txt, mode:100644]" + "[b.txt, mode:100644]",
+ indexState(0));
+ }
+
@Test
public void testPathsReset() throws Exception {
setupRepository();
import org.eclipse.jgit.dircache.DirCacheBuildIterator;
import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.dircache.DirCacheCheckout;
-import org.eclipse.jgit.dircache.DirCacheEditor;
-import org.eclipse.jgit.dircache.DirCacheEditor.DeletePath;
-import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.internal.JGitText;
DirCache dc = repo.lockDirCache();
TreeWalk walk = null;
try {
- DirCacheEditor editor = dc.editor();
+ DirCacheBuilder builder = dc.builder();
walk = new TreeWalk(repo);
walk.addTree(commit.getTree());
AbstractTreeIterator cIter = walk.getTree(0,
AbstractTreeIterator.class);
if (cIter == null) {
- editor.add(new DeletePath(walk.getPathString()));
+ // Not in commit, don't add to new index
continue;
}
entry.setLength(indexEntry.getLength());
}
- editor.add(new PathEdit(entry) {
-
- @Override
- public void apply(DirCacheEntry ent) {
- ent.copyMetaData(entry);
- }
- });
+ builder.add(entry);
}
- editor.commit();
+ builder.commit();
} finally {
dc.unlock();
if (walk != null)