Package org.locationtech.geogig.api

Examples of org.locationtech.geogig.api.CommitBuilder


        {// simulate a commit so the repo head points to this new tree
            ObjectInserter objectInserter = repo.newObjectInserter();
            List<ObjectId> parents = ImmutableList.of();

            RevCommit commit = new CommitBuilder().setTreeId(newRepoTreeId1).setParentIds(parents)
                    .build();
            ObjectId commitId = commit.getId();
            objectInserter.insert(commit);
            Optional<Ref> newHead = geogig.command(UpdateRef.class).setName("refs/heads/master")
                    .setNewValue(commitId).call();
            assertTrue(newHead.isPresent());
        }

        final ObjectId newRepoTreeId2;
        {
            // write comparing the the previously generated tree instead of the repository HEAD, as
            // it was not updated (no commit op was performed)
            newRepoTreeId2 = geogig.command(WriteTree2.class).setOldRoot(tree(newRepoTreeId1))
                    .call();

            // assertEquals(index.getDatabase().getStagedRootRef().getObjectId(), newRepoTreeId2);

            System.err.println("++++++++ new root 2:" + newRepoTreeId2 + " ++++++++++");
            RevTree newRepoTree = repo.getTree(newRepoTreeId2);

            // check feature1_2, feature1_2 and feature2_1
            Optional<Node> treeChild;
            assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(pointsName, idP2)));
            assertEquals(oId1_2, treeChild.get().getObjectId());

            assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(pointsName, idP3)));
            assertEquals(oId1_3, treeChild.get().getObjectId());

            assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(linesName, idL1)));
            assertEquals(oId2_1, treeChild.get().getObjectId());

            // as well as feature1_1 from the previous commit
            assertNotNull(treeChild = repo.getTreeChild(newRepoTree, appendChild(pointsName, idP1)));
            assertEquals(oId1_1, treeChild.get().getObjectId());
        }

        {// simulate a commit so the repo head points to this new tree
            ObjectInserter objectInserter = repo.newObjectInserter();
            List<ObjectId> parents = ImmutableList.of();
            RevCommit commit = new CommitBuilder().setTreeId(newRepoTreeId2).setParentIds(parents)
                    .build();
            ObjectId commitId = commit.getId();

            objectInserter.insert(commit);
            Optional<Ref> newHead = geogig.command(UpdateRef.class).setName("refs/heads/master")
View Full Code Here


        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();
View Full Code Here

    protected void setUp() throws Exception {

    }

    public void testBuildEmpty() throws Exception {
        CommitBuilder b = new CommitBuilder();
        try {
            b.build();
            fail("expected IllegalStateException on null tree id");
        } catch (IllegalStateException e) {
            assertTrue(e.getMessage().contains("tree"));
        }
    }
View Full Code Here

            assertTrue(e.getMessage().contains("tree"));
        }
    }

    public void testBuildFull() throws Exception {
        CommitBuilder b = new CommitBuilder();
        b.setAuthor("groldan");
        b.setAuthorEmail("groldan@boundlessgeo.com");
        b.setCommitter("jdeolive");
        b.setCommitterEmail("jdeolive@boundlessgeo.com");
        b.setMessage("cool this works");
        b.setCommitterTimestamp(1000);
        b.setCommitterTimeZoneOffset(10);
        b.setAuthorTimestamp(500);
        b.setAuthorTimeZoneOffset(-5);

        ObjectId treeId = ObjectId.forString("fake tree content");

        b.setTreeId(treeId);

        ObjectId parentId1 = ObjectId.forString("fake parent content 1");
        ObjectId parentId2 = ObjectId.forString("fake parent content 2");
        List<ObjectId> parentIds = ImmutableList.of(parentId1, parentId2);
        b.setParentIds(parentIds);

        RevCommit build = b.build();
        assertNotNull(build.getId());
        assertFalse(build.getId().isNull());
        assertEquals(treeId, build.getTreeId());
        assertEquals(parentIds, build.getParentIds());
        assertEquals("groldan", build.getAuthor().getName().get());
View Full Code Here

        assertEquals(-5, build.getAuthor().getTimeZoneOffset());
    }

    @Test
    public void testPassingNullToSetParentIds() throws Exception {
        CommitBuilder b = new CommitBuilder();
        b.setAuthor("groldan");
        b.setAuthorEmail("groldan@boundlessgeo.com");
        b.setCommitter("jdeolive");
        b.setCommitterEmail("jdeolive@boundlessgeo.com");
        b.setMessage("cool this works");
        b.setAuthorTimestamp(1000);

        ObjectId treeId = ObjectId.forString("fake tree content");

        b.setTreeId(treeId);

        b.setParentIds(null);

        assertEquals(ImmutableList.of(), b.getParentIds());
    }
View Full Code Here

        assertEquals(ImmutableList.of(), b.getParentIds());
    }

    @Test
    public void testNoMessage() throws Exception {
        CommitBuilder b = new CommitBuilder();
        b.setAuthor("groldan");
        b.setAuthorEmail("groldan@boundlessgeo.com");
        b.setCommitter("jdeolive");
        b.setCommitterEmail("jdeolive@boundlessgeo.com");
        b.setMessage(null);
        b.setAuthorTimestamp(1000);

        ObjectId treeId = ObjectId.forString("fake tree content");

        b.setTreeId(treeId);

        ObjectId parentId1 = ObjectId.forString("fake parent content 1");
        ObjectId parentId2 = ObjectId.forString("fake parent content 2");
        List<ObjectId> parentIds = ImmutableList.of(parentId1, parentId2);
        b.setParentIds(parentIds);

        assertEquals(null, b.getMessage());

        RevCommit commit2 = b.build();
        assertEquals("", commit2.getMessage());
    }
View Full Code Here

        assertEquals("", commit2.getMessage());
    }

    @Test
    public void testNoAuthorTimeStamp() throws Exception {
        CommitBuilder b = new CommitBuilder();
        b.setAuthor("groldan");
        b.setAuthorEmail("groldan@boundlessgeo.com");
        b.setCommitter("jdeolive");
        b.setCommitterEmail("jdeolive@boundlessgeo.com");
        b.setCommitterTimestamp(1000);
        b.setMessage("cool this works");

        assertEquals(1000, b.getAuthorTimestamp());
    }
View Full Code Here

    }

    @Test
    public void testCommitBuilder() throws Exception {

        CommitBuilder b = new CommitBuilder();
        b.setAuthor("groldan");
        b.setAuthorEmail("groldan@boundlessgeo.com");
        b.setCommitter("jdeolive");
        b.setCommitterEmail("jdeolive@boundlessgeo.com");
        b.setMessage("cool this works");
        b.setAuthorTimestamp(1000);

        ObjectId treeId = ObjectId.forString("fake tree content");

        b.setTreeId(treeId);

        ObjectId parentId1 = ObjectId.forString("fake parent content 1");
        ObjectId parentId2 = ObjectId.forString("fake parent content 2");
        List<ObjectId> parentIds = ImmutableList.of(parentId1, parentId2);
        b.setParentIds(parentIds);

        RevCommit commit1 = b.build();

        CommitBuilder builder = new CommitBuilder(commit1);

        assertEquals("groldan", builder.getAuthor());
        assertEquals("jdeolive", builder.getCommitter());
        assertEquals("groldan@boundlessgeo.com", builder.getAuthorEmail());
        assertEquals("jdeolive@boundlessgeo.com", builder.getCommitterEmail());
        assertEquals(commit1.getMessage(), builder.getMessage());
        assertEquals(commit1.getParentIds(), builder.getParentIds());
        assertEquals(commit1.getTreeId(), builder.getTreeId());
        assertEquals(commit1.getAuthor().getTimestamp(), builder.getAuthorTimestamp());

        RevCommit commit2 = builder.build();

        assertEquals(commit1, commit2);
    }
View Full Code Here

        // Create new commit
        List<ObjectId> parents = Lists.newArrayList();
        parents.addAll(firstParents);
        parents.addAll(secondaryParents);
        ObjectId endTree = until.getTreeId();
        CommitBuilder builder = new CommitBuilder(until);
        Collection<ObjectId> filteredParents = Collections2.filter(parents,
                new Predicate<ObjectId>() {
                    @Override
                    public boolean apply(@Nullable ObjectId id) {
                        return !squashedIds.contains(id);
                    }

                });

        builder.setParentIds(Lists.newArrayList(filteredParents));
        builder.setTreeId(endTree);
        if (message == null) {
            message = since.getMessage();
        }
        long timestamp = platform.currentTimeMillis();
        builder.setMessage(message);
        builder.setCommitter(resolveCommitter());
        builder.setCommitterEmail(resolveCommitterEmail());
        builder.setCommitterTimestamp(timestamp);
        builder.setCommitterTimeZoneOffset(platform.timeZoneOffset(timestamp));
        builder.setAuthorTimestamp(until.getAuthor().getTimestamp());

        RevCommit newCommit = builder.build();
        repository.objectDatabase().put(newCommit);

        newHead = newCommit.getId();
        ObjectId newTreeId = newCommit.getTreeId();
View Full Code Here

        final Platform platform = platform();
        final Map<ObjectId, ObjectId> replacedCommits = Maps.newHashMap();
        replacedCommits.put(until.getId(), squashedId);
        ObjectId head = squashedId;
        for (RevCommit commit : commits) {
            CommitBuilder builder = new CommitBuilder(commit);
            Collection<ObjectId> parents = Collections2.transform(commit.getParentIds(),
                    new Function<ObjectId, ObjectId>() {
                        @Override
                        @Nullable
                        public ObjectId apply(@Nullable ObjectId id) {
                            if (replacedCommits.containsKey(id)) {
                                return replacedCommits.get(id);
                            } else {
                                return id;
                            }
                        }
                    });
            builder.setParentIds(Lists.newArrayList(parents));
            builder.setTreeId(commit.getTreeId());
            long timestamp = platform.currentTimeMillis();
            builder.setCommitterTimestamp(timestamp);
            builder.setCommitterTimeZoneOffset(platform.timeZoneOffset(timestamp));

            RevCommit newCommit = builder.build();
            replacedCommits.put(commit.getId(), newCommit.getId());
            objectDatabase().put(newCommit);
            head = newCommit.getId();
            ObjectId newTreeId = newCommit.getTreeId();
View Full Code Here

TOP

Related Classes of org.locationtech.geogig.api.CommitBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.