// Each of these rules are from the read-tree manpage // go there to see what they mean. // Rule 0 is left out for obvious reasons :) public void testRules1thru3_NoIndexEntry() throws IOException { GitIndex index = new GitIndex(db); Tree head = new Tree(db); FileTreeEntry headFile = head.addFile("foo"); ObjectId objectId = ObjectId.fromString("ba78e065e2c261d4f7b8f42107588051e87e18e9"); headFile.setId(objectId); Tree merge = new Tree(db); Checkout readTree = getCheckoutImpl(head, index, merge); readTree.prescanTwoTrees(); assertTrue(readTree.removed().contains("foo")); readTree = getCheckoutImpl(merge, index, head); readTree.prescanTwoTrees(); assertEquals(objectId, readTree.updated().get("foo")); ObjectId anotherId = ObjectId.fromString("ba78e065e2c261d4f7b8f42107588051e87e18ee"); merge.addFile("foo").setId(anotherId); readTree = getCheckoutImpl(head, index, merge); readTree.prescanTwoTrees(); assertEquals(anotherId, readTree.updated().get("foo")); }
private Tree buildTree(HashMap<String, String> headEntries) throws IOException { Tree tree = new Tree(db); if (headEntries == null) return tree; for (java.util.Map.Entry<String, String> e : headEntries.entrySet()) { tree.addFile(e.getKey()).setId(genSha1(e.getValue())); } return tree; }
private Pointer commit(File file) throws Exception { LOG.info("about to commit " + file.getName()); Pointer result = null; if (file.isDirectory()) { Tree tree = new Tree(); for (File child : file.listFiles()) { LOG.info("child: " + child.getName()); Pointer p = commit(child); if (child.isDirectory()) { tree.addTree(child.getName(), p); } else { tree.addFile(child.getName(), p, child.length()); } } result = createRemoteTree(tree); } else { // file result = createRemoteFile(file); } return result; }
@Override public synchronized void commit(String remoteDir, File file) throws Exception { LOG.info("path = " + remoteDir); String[] dirnames = remoteDir.split("/"); if (remoteDir.equals("/")) { dirnames = new String[] {""}; } LOG.info("dirnames.length = " + dirnames.length); Tree[] trees = getTreeStack(dirnames); Pointer p = commit(file); Tree tree = trees[trees.length - 1]; if (file.isDirectory()) { tree.addTree(file.getName(), p); } else { tree.addFile(file.getName(), p, file.length()); } p = createRemoteTree(tree); for (int i = dirnames.length - 2; i >= 0; i--) { tree = trees[i]; tree.addTree(dirnames[i + 1], p); p = createRemoteTree(tree); } setRootPointer(p); }
private void addFileToTree(final Tree t, String filename, String content) throws IOException { FileTreeEntry f = t.addFile(filename); writeTrashFile(f.getName(), content); t.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); }