|
|
@ -63,6 +63,7 @@ import org.eclipse.jgit.dircache.DirCache; |
|
|
|
import org.eclipse.jgit.dircache.DirCacheCheckout; |
|
|
|
import org.eclipse.jgit.dircache.DirCacheCheckout; |
|
|
|
import org.eclipse.jgit.dircache.DirCacheEditor; |
|
|
|
import org.eclipse.jgit.dircache.DirCacheEditor; |
|
|
|
import org.eclipse.jgit.dircache.DirCacheEntry; |
|
|
|
import org.eclipse.jgit.dircache.DirCacheEntry; |
|
|
|
|
|
|
|
import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit; |
|
|
|
import org.eclipse.jgit.errors.CheckoutConflictException; |
|
|
|
import org.eclipse.jgit.errors.CheckoutConflictException; |
|
|
|
import org.eclipse.jgit.errors.CorruptObjectException; |
|
|
|
import org.eclipse.jgit.errors.CorruptObjectException; |
|
|
|
import org.eclipse.jgit.errors.NoWorkTreeException; |
|
|
|
import org.eclipse.jgit.errors.NoWorkTreeException; |
|
|
@ -73,15 +74,15 @@ import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
public class DirCacheCheckoutTest extends RepositoryTestCase { |
|
|
|
public class DirCacheCheckoutTest extends RepositoryTestCase { |
|
|
|
private DirCacheCheckout dco; |
|
|
|
private DirCacheCheckout dco; |
|
|
|
protected Tree theHead; |
|
|
|
protected ObjectId theHead; |
|
|
|
protected Tree theMerge; |
|
|
|
protected ObjectId theMerge; |
|
|
|
private DirCache dirCache; |
|
|
|
private DirCache dirCache; |
|
|
|
|
|
|
|
|
|
|
|
private void prescanTwoTrees(Tree head, Tree merge) |
|
|
|
private void prescanTwoTrees(ObjectId head, ObjectId merge) |
|
|
|
throws IllegalStateException, IOException { |
|
|
|
throws IllegalStateException, IOException { |
|
|
|
DirCache dc = db.lockDirCache(); |
|
|
|
DirCache dc = db.lockDirCache(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
dco = new DirCacheCheckout(db, head.getId(), dc, merge.getId()); |
|
|
|
dco = new DirCacheCheckout(db, head, dc, merge); |
|
|
|
dco.preScanTwoTrees(); |
|
|
|
dco.preScanTwoTrees(); |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
dc.unlock(); |
|
|
|
dc.unlock(); |
|
|
@ -91,7 +92,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase { |
|
|
|
private void checkout() throws IOException { |
|
|
|
private void checkout() throws IOException { |
|
|
|
DirCache dc = db.lockDirCache(); |
|
|
|
DirCache dc = db.lockDirCache(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
dco = new DirCacheCheckout(db, theHead.getId(), dc, theMerge.getId()); |
|
|
|
dco = new DirCacheCheckout(db, theHead, dc, theMerge); |
|
|
|
dco.checkout(); |
|
|
|
dco.checkout(); |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
dc.unlock(); |
|
|
|
dc.unlock(); |
|
|
@ -239,10 +240,11 @@ public class DirCacheCheckoutTest extends RepositoryTestCase { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testRules1thru3_NoIndexEntry() throws IOException { |
|
|
|
public void testRules1thru3_NoIndexEntry() throws IOException { |
|
|
|
Tree head = new Tree(db); |
|
|
|
ObjectId head = buildTree(mk("foo")); |
|
|
|
head = buildTree(mk("foo")); |
|
|
|
TreeWalk tw = TreeWalk.forPath(db, "foo", head); |
|
|
|
ObjectId objectId = head.findBlobMember("foo").getId(); |
|
|
|
ObjectId objectId = tw.getObjectId(0); |
|
|
|
Tree merge = new Tree(db); |
|
|
|
ObjectId merge = db.newObjectInserter().insert(Constants.OBJ_TREE, |
|
|
|
|
|
|
|
new byte[0]); |
|
|
|
|
|
|
|
|
|
|
|
prescanTwoTrees(head, merge); |
|
|
|
prescanTwoTrees(head, merge); |
|
|
|
|
|
|
|
|
|
|
@ -253,7 +255,8 @@ public class DirCacheCheckoutTest extends RepositoryTestCase { |
|
|
|
assertEquals(objectId, getUpdated().get("foo")); |
|
|
|
assertEquals(objectId, getUpdated().get("foo")); |
|
|
|
|
|
|
|
|
|
|
|
merge = buildTree(mkmap("foo", "a")); |
|
|
|
merge = buildTree(mkmap("foo", "a")); |
|
|
|
ObjectId anotherId = merge.findBlobMember("foo").getId(); |
|
|
|
tw = TreeWalk.forPath(db, "foo", merge); |
|
|
|
|
|
|
|
ObjectId anotherId = tw.getObjectId(0); |
|
|
|
|
|
|
|
|
|
|
|
prescanTwoTrees(head, merge); |
|
|
|
prescanTwoTrees(head, merge); |
|
|
|
|
|
|
|
|
|
|
@ -291,28 +294,41 @@ public class DirCacheCheckoutTest extends RepositoryTestCase { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Tree buildTree(HashMap<String, String> headEntries) throws IOException { |
|
|
|
static final class AddEdit extends PathEdit { |
|
|
|
Tree tree = new Tree(db); |
|
|
|
|
|
|
|
if (headEntries == null) |
|
|
|
private final ObjectId data; |
|
|
|
return tree; |
|
|
|
|
|
|
|
FileTreeEntry fileEntry; |
|
|
|
private final long length; |
|
|
|
Tree parent; |
|
|
|
|
|
|
|
ObjectInserter oi = db.newObjectInserter(); |
|
|
|
public AddEdit(String entryPath, ObjectId data, long length) { |
|
|
|
try { |
|
|
|
super(entryPath); |
|
|
|
for (java.util.Map.Entry<String, String> e : headEntries.entrySet()) { |
|
|
|
this.data = data; |
|
|
|
fileEntry = tree.addFile(e.getKey()); |
|
|
|
this.length = length; |
|
|
|
fileEntry.setId(genSha1(e.getValue())); |
|
|
|
} |
|
|
|
parent = fileEntry.getParent(); |
|
|
|
|
|
|
|
while (parent != null) { |
|
|
|
@Override |
|
|
|
parent.setId(oi.insert(Constants.OBJ_TREE, parent.format())); |
|
|
|
public void apply(DirCacheEntry ent) { |
|
|
|
parent = parent.getParent(); |
|
|
|
ent.setFileMode(FileMode.REGULAR_FILE); |
|
|
|
|
|
|
|
ent.setLength(length); |
|
|
|
|
|
|
|
ent.setObjectId(data); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ObjectId buildTree(HashMap<String, String> headEntries) |
|
|
|
|
|
|
|
throws IOException { |
|
|
|
|
|
|
|
DirCache lockDirCache = DirCache.newInCore(); |
|
|
|
|
|
|
|
// assertTrue(lockDirCache.lock());
|
|
|
|
|
|
|
|
DirCacheEditor editor = lockDirCache.editor(); |
|
|
|
|
|
|
|
if (headEntries != null) { |
|
|
|
|
|
|
|
for (java.util.Map.Entry<String, String> e : headEntries.entrySet()) { |
|
|
|
|
|
|
|
AddEdit addEdit = new AddEdit(e.getKey(), |
|
|
|
|
|
|
|
genSha1(e.getValue()), e.getValue().length()); |
|
|
|
|
|
|
|
editor.add(addEdit); |
|
|
|
} |
|
|
|
} |
|
|
|
oi.flush(); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
oi.release(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return tree; |
|
|
|
editor.finish(); |
|
|
|
|
|
|
|
return lockDirCache.writeTree(db.newObjectInserter()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ObjectId genSha1(String data) { |
|
|
|
ObjectId genSha1(String data) { |
|
|
@ -463,8 +479,8 @@ public class DirCacheCheckoutTest extends RepositoryTestCase { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testDirectoryFileSimple() throws IOException { |
|
|
|
public void testDirectoryFileSimple() throws IOException { |
|
|
|
Tree treeDF = buildTree(mkmap("DF", "DF")); |
|
|
|
ObjectId treeDF = buildTree(mkmap("DF", "DF")); |
|
|
|
Tree treeDFDF = buildTree(mkmap("DF/DF", "DF/DF")); |
|
|
|
ObjectId treeDFDF = buildTree(mkmap("DF/DF", "DF/DF")); |
|
|
|
buildIndex(mkmap("DF", "DF")); |
|
|
|
buildIndex(mkmap("DF", "DF")); |
|
|
|
|
|
|
|
|
|
|
|
prescanTwoTrees(treeDF, treeDFDF); |
|
|
|
prescanTwoTrees(treeDF, treeDFDF); |
|
|
|