@Test public void testEmptyRepo() { ObjectId root = command.call(); assertNotNull(root); assertEquals(RevTree.EMPTY_TREE_ID, root); }
@Test public void testEmptyRepo() { ObjectId root = command.call(); assertNotNull(root); assertEquals(RevTree.EMPTY_TREE_ID, root); }
@Test public void testEmptyRepoSingleStagedTree() { rightTree = createStageHeadTree(// indexTree("roads", "a1", "d1", 10)// ); ObjectId newRepoRoot = command.call(); assertNotNull(newRepoRoot); // print(newRepoRoot); // check all blobs have been moved from the index to the object database verifyRepositoryTree(NodeRef.ROOT, newRepoRoot); ImmutableMap<String, NodeRef> refsByPath = getTreeRefsByPath(newRepoRoot); assertEquals(1, refsByPath.size()); assertTrue(refsByPath.keySet().contains("roads")); }
@Test public void testEmptyRepoSingleStagedTree() { rightTree = createStageHeadTree(// indexTree("roads", "a1", "d1", 10)// ); ObjectId newRepoRoot = command.call(); assertNotNull(newRepoRoot); // print(newRepoRoot); // check all blobs have been moved from the index to the object database verifyRepositoryTree(NodeRef.ROOT, newRepoRoot); ImmutableMap<String, NodeRef> refsByPath = getTreeRefsByPath(newRepoRoot); assertEquals(1, refsByPath.size()); assertTrue(refsByPath.keySet().contains("roads")); }
/** * @return the differences between the given right tree(staged) and the resulting tree after * running {@link WriteTree2} with the given filters. The result's left refs are the * ones in the new tree, and the right refs the same as given in the rightTree */ private MapDifference<String, NodeRef> runWithPathFilter(RevTree leftTree, RevTree rightTree, String... filters) { // print(leftTree.getId()); // print(rightTree.getId()); final ObjectId newRepoRoot = command.setPathFilter(Arrays.asList(filters)).call(); assertNotNull(newRepoRoot); // print(newRepoRoot); // check all blobs have been moved from the index to the object database verifyRepositoryTree(NodeRef.ROOT, newRepoRoot); final boolean includeFeatures = true; ImmutableMap<String, NodeRef> stagedRefs = getRefsByPath(rightTree.getId(), includeFeatures); ImmutableMap<String, NodeRef> resultRefs = getRefsByPath(newRepoRoot, includeFeatures); MapDifference<String, NodeRef> difference = Maps.difference(resultRefs, stagedRefs); return difference; }
/** * @return the differences between the given right tree(staged) and the resulting tree after * running {@link WriteTree2} with the given filters. The result's left refs are the * ones in the new tree, and the right refs the same as given in the rightTree */ private MapDifference<String, NodeRef> runWithPathFilter(RevTree leftTree, RevTree rightTree, String... filters) { // print(leftTree.getId()); // print(rightTree.getId()); final ObjectId newRepoRoot = command.setPathFilter(Arrays.asList(filters)).call(); assertNotNull(newRepoRoot); // print(newRepoRoot); // check all blobs have been moved from the index to the object database verifyRepositoryTree(NodeRef.ROOT, newRepoRoot); final boolean includeFeatures = true; ImmutableMap<String, NodeRef> stagedRefs = getRefsByPath(rightTree.getId(), includeFeatures); ImmutableMap<String, NodeRef> resultRefs = getRefsByPath(newRepoRoot, includeFeatures); MapDifference<String, NodeRef> difference = Maps.difference(resultRefs, stagedRefs); return difference; }
@Test public void testRename() { leftTree = createHeadTree(// repoTree("roads", EMPTY_ID, null, 0) // ); rightTree = createStageHeadTree(// indexTree("roadsRenamed", EMPTY_ID, null, 0) // ); ObjectId newRepoRoot = command.call(); assertNotNull(newRepoRoot); // check all blobs have been moved from the index to the object database verifyRepositoryTree(NodeRef.ROOT, newRepoRoot); ImmutableMap<String, NodeRef> refsByPath = getTreeRefsByPath(newRepoRoot); assertEquals(1, refsByPath.size()); assertTrue(refsByPath.containsKey("roadsRenamed")); }
@Test public void testRename() { leftTree = createHeadTree(// repoTree("roads", EMPTY_ID, null, 0) // ); rightTree = createStageHeadTree(// indexTree("roadsRenamed", EMPTY_ID, null, 0) // ); ObjectId newRepoRoot = command.call(); assertNotNull(newRepoRoot); // check all blobs have been moved from the index to the object database verifyRepositoryTree(NodeRef.ROOT, newRepoRoot); ImmutableMap<String, NodeRef> refsByPath = getTreeRefsByPath(newRepoRoot); assertEquals(1, refsByPath.size()); assertTrue(refsByPath.containsKey("roadsRenamed")); }
@Test public void testRenameNested() { leftTree = createHeadTree(// repoTree("roads", EMPTY_ID, null, 0), // repoTree("roads/highways", "a2", "d1", 2), // repoTree("roads/streets", "a3", "d2", 2) // ); rightTree = createStageHeadTree(// indexTree("roads", EMPTY_ID, null, 0), // indexTree("roads/highways", "a2", "d1", 2), // indexTree("roads/streetsRenamed", "a3", "d2", 2) // ); ObjectId newRepoRoot = command.call(); assertNotNull(newRepoRoot); // check all blobs have been moved from the index to the object database verifyRepositoryTree(NodeRef.ROOT, newRepoRoot); ImmutableMap<String, NodeRef> refsByPath = getTreeRefsByPath(newRepoRoot); assertEquals(3, refsByPath.size()); assertTrue(refsByPath.containsKey("roads")); assertTrue(refsByPath.containsKey("roads/highways")); assertTrue(refsByPath.containsKey("roads/streetsRenamed")); }
@Test public void testRenameNested() { leftTree = createHeadTree(// repoTree("roads", EMPTY_ID, null, 0), // repoTree("roads/highways", "a2", "d1", 2), // repoTree("roads/streets", "a3", "d2", 2) // ); rightTree = createStageHeadTree(// indexTree("roads", EMPTY_ID, null, 0), // indexTree("roads/highways", "a2", "d1", 2), // indexTree("roads/streetsRenamed", "a3", "d2", 2) // ); ObjectId newRepoRoot = command.call(); assertNotNull(newRepoRoot); // check all blobs have been moved from the index to the object database verifyRepositoryTree(NodeRef.ROOT, newRepoRoot); ImmutableMap<String, NodeRef> refsByPath = getTreeRefsByPath(newRepoRoot); assertEquals(3, refsByPath.size()); assertTrue(refsByPath.containsKey("roads")); assertTrue(refsByPath.containsKey("roads/highways")); assertTrue(refsByPath.containsKey("roads/streetsRenamed")); }
@Test public void testMetadataIdChangeOnly() { leftTree = createHeadTree(// repoTree("buildings", EMPTY_ID, null, 0), // repoTree("buildings/stores", "a5", "d3", 5)// old md id is d3 ); rightTree = createStageHeadTree(// indexTree("buildings", EMPTY_ID, null, 0), // indexTree("buildings/stores", "a5", "d31", 5)// new md id is d31 ); ObjectId newRepoRoot = command.call(); assertNotNull(newRepoRoot); // check all blobs have been moved from the index to the object database verifyRepositoryTree(NodeRef.ROOT, newRepoRoot); ImmutableMap<String, NodeRef> refsByPath = getTreeRefsByPath(newRepoRoot); assertEquals(set("buildings", "buildings/stores"), refsByPath.keySet()); assertEquals(id("d31"), refsByPath.get("buildings/stores").getMetadataId()); }
@Test public void testMetadataIdChangeOnly() { leftTree = createHeadTree(// repoTree("buildings", EMPTY_ID, null, 0), // repoTree("buildings/stores", "a5", "d3", 5)// old md id is d3 ); rightTree = createStageHeadTree(// indexTree("buildings", EMPTY_ID, null, 0), // indexTree("buildings/stores", "a5", "d31", 5)// new md id is d31 ); ObjectId newRepoRoot = command.call(); assertNotNull(newRepoRoot); // check all blobs have been moved from the index to the object database verifyRepositoryTree(NodeRef.ROOT, newRepoRoot); ImmutableMap<String, NodeRef> refsByPath = getTreeRefsByPath(newRepoRoot); assertEquals(set("buildings", "buildings/stores"), refsByPath.keySet()); assertEquals(id("d31"), refsByPath.get("buildings/stores").getMetadataId()); }
@Test public void testSimpleChanges() { leftTree = createHeadTree(// repoTree("roads", "a1", "d1", 1), // repoTree("buildings", EMPTY_ID, null, 0)// ); rightTree = createStageHeadTree(// repoTree("roads", "a11", "d1", 2), // repoTree("buildings", "a41", null, 1)// ); // print(leftTree.getId()); // print(rightTree.getId()); final ObjectId newRepoRoot = command.call(); assertNotNull(newRepoRoot); // check all blobs have been moved from the index to the object database verifyRepositoryTree(NodeRef.ROOT, newRepoRoot); ImmutableMap<String, NodeRef> refsByPath = getRefsByPath(newRepoRoot, true); Set<String> expected = set("roads", "roads/roads.0", "roads/roads.1", "buildings", "buildings/buildings.0"); ImmutableSet<String> actual = refsByPath.keySet(); assertEquals(expected, actual); }
@Test public void testSimpleChanges() { leftTree = createHeadTree(// repoTree("roads", "a1", "d1", 1), // repoTree("buildings", EMPTY_ID, null, 0)// ); rightTree = createStageHeadTree(// repoTree("roads", "a11", "d1", 2), // repoTree("buildings", "a41", null, 1)// ); // print(leftTree.getId()); // print(rightTree.getId()); final ObjectId newRepoRoot = command.call(); assertNotNull(newRepoRoot); // check all blobs have been moved from the index to the object database verifyRepositoryTree(NodeRef.ROOT, newRepoRoot); ImmutableMap<String, NodeRef> refsByPath = getRefsByPath(newRepoRoot, true); Set<String> expected = set("roads", "roads/roads.0", "roads/roads.1", "buildings", "buildings/buildings.0"); ImmutableSet<String> actual = refsByPath.keySet(); assertEquals(expected, actual); }
@Test public void testDeleteAll() { leftTree = createHeadTree(// repoTree("roads", EMPTY_ID, null, 0), // repoTree("roads/highways", "a2", "d1", 10), // repoTree("roads/streets", "a3", "d2", 10), // repoTree("buildings", EMPTY_ID, null, 0), // repoTree("buildings/stores", "a5", "d3", 5), // repoTree("buildings/unknown", "a6", "d4", 5), // repoTree("buildings/towers", "a7", "d5", 5)// ); rightTree = createStageHeadTree(); final ObjectId newRepoRoot = command.call(); assertNotNull(newRepoRoot); ImmutableMap<String, NodeRef> refsByPath = getTreeRefsByPath(newRepoRoot); assertEquals(set(), refsByPath.keySet()); }
@Test public void testDeleteAll() { leftTree = createHeadTree(// repoTree("roads", EMPTY_ID, null, 0), // repoTree("roads/highways", "a2", "d1", 10), // repoTree("roads/streets", "a3", "d2", 10), // repoTree("buildings", EMPTY_ID, null, 0), // repoTree("buildings/stores", "a5", "d3", 5), // repoTree("buildings/unknown", "a6", "d4", 5), // repoTree("buildings/towers", "a7", "d5", 5)// ); rightTree = createStageHeadTree(); final ObjectId newRepoRoot = command.call(); assertNotNull(newRepoRoot); ImmutableMap<String, NodeRef> refsByPath = getTreeRefsByPath(newRepoRoot); assertEquals(set(), refsByPath.keySet()); }
private void createCommit(RevCommit commit) { // write new tree ObjectId newTreeId = command(WriteTree2.class).call(); long timestamp = platform().currentTimeMillis(); String committerName = resolveCommitter(); String committerEmail = resolveCommitterEmail(); // Create new commit CommitBuilder builder = new CommitBuilder(); builder.setParentIds(Arrays.asList(revertHead)); builder.setTreeId(newTreeId); builder.setCommitterTimestamp(timestamp); builder.setMessage( "Revert '" + commit.getMessage() + "'\nThis reverts " + commit.getId().toString()); builder.setCommitter(committerName); builder.setCommitterEmail(committerEmail); builder.setAuthor(committerName); builder.setAuthorEmail(committerEmail); RevCommit newCommit = builder.build(); objectDatabase().put(newCommit); revertHead = newCommit.getId(); command(UpdateRef.class).setName(currentBranch).setNewValue(revertHead).call(); command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(currentBranch).call(); workingTree().updateWorkHead(newTreeId); stagingArea().updateStageHead(newTreeId); }
@Test public void testNoChanges() { leftTree = createHeadTree(// repoTree("buildings", EMPTY_ID, null, 0), // repoTree("buildings/stores", "a5", "d3", 5), // repoTree("buildings/unknown", "a6", "d4", 5), // repoTree("buildings/towers", "a7", "d5", 5)// ); rightTree = createStageHeadTree(// repoTree("buildings", EMPTY_ID, null, 0), // repoTree("buildings/stores", "a5", "d3", 5), // repoTree("buildings/unknown", "a6", "d4", 5), // repoTree("buildings/towers", "a7", "d5", 5)// ); ObjectId newRepoRoot = command.call(); assertNotNull(newRepoRoot); // check all blobs have been moved from the index to the object database verifyRepositoryTree(NodeRef.ROOT, newRepoRoot); ImmutableMap<String, NodeRef> refsByPath = getTreeRefsByPath(newRepoRoot); assertEquals(4, refsByPath.size()); Set<String> expected = set("buildings", "buildings/stores", "buildings/unknown", "buildings/towers"); assertEquals(expected, refsByPath.keySet()); }
@Test public void testDeletes() { leftTree = createHeadTree(// repoTree("roads", EMPTY_ID, null, 0), // repoTree("roads/highways", "a2", "d1", 10), // repoTree("roads/streets", "a3", "d2", 10), // repoTree("buildings", EMPTY_ID, null, 0), // repoTree("buildings/stores", "a5", "d3", 5), // repoTree("buildings/unknown", "a6", "d4", 5), // repoTree("buildings/towers", "a7", "d5", 5)// ); rightTree = createStageHeadTree(// indexTree("roads", EMPTY_ID, null, 0), // indexTree("roads/highways", "a2", "d1", 10), // indexTree("buildings", EMPTY_ID, null, 0), // indexTree("buildings/stores", "a5", "d31", 5)// ); final ObjectId newRepoRoot = command.call(); assertNotNull(newRepoRoot); // check all blobs have been moved from the index to the object database verifyRepositoryTree(NodeRef.ROOT, newRepoRoot); ImmutableMap<String, NodeRef> refsByPath = getTreeRefsByPath(newRepoRoot); assertEquals(set("roads", "roads/highways", "buildings", "buildings/stores"), refsByPath.keySet()); }
@Test public void testDeletes() { leftTree = createHeadTree(// repoTree("roads", EMPTY_ID, null, 0), // repoTree("roads/highways", "a2", "d1", 10), // repoTree("roads/streets", "a3", "d2", 10), // repoTree("buildings", EMPTY_ID, null, 0), // repoTree("buildings/stores", "a5", "d3", 5), // repoTree("buildings/unknown", "a6", "d4", 5), // repoTree("buildings/towers", "a7", "d5", 5)// ); rightTree = createStageHeadTree(// indexTree("roads", EMPTY_ID, null, 0), // indexTree("roads/highways", "a2", "d1", 10), // indexTree("buildings", EMPTY_ID, null, 0), // indexTree("buildings/stores", "a5", "d31", 5)// ); final ObjectId newRepoRoot = command.call(); assertNotNull(newRepoRoot); // check all blobs have been moved from the index to the object database verifyRepositoryTree(NodeRef.ROOT, newRepoRoot); ImmutableMap<String, NodeRef> refsByPath = getTreeRefsByPath(newRepoRoot); assertEquals(set("roads", "roads/highways", "buildings", "buildings/stores"), refsByPath.keySet()); }