Search in sources :

Example 1 with CommitOp

use of org.locationtech.geogig.api.porcelain.CommitOp in project GeoGig by boundlessgeo.

the class CommitOpTest method testCommitWithAllOption.

@Test
public void testCommitWithAllOption() throws Exception {
    try {
        geogig.command(AddOp.class).addPattern(".").call();
        geogig.command(CommitOp.class).call();
        fail("expected NothingToCommitException");
    } catch (NothingToCommitException e) {
        assertTrue(true);
    }
    insertAndAdd(points1);
    geogig.command(AddOp.class).addPattern(".").call();
    RevCommit commit = geogig.command(CommitOp.class).call();
    ObjectId oid = insertAndAdd(points1_modified);
    CommitOp commitCommand = geogig.command(CommitOp.class);
    commit = commitCommand.setAll(true).call();
    assertNotNull(commit);
    assertNotNull(commit.getParentIds());
    assertEquals(1, commit.getParentIds().size());
    assertNotNull(commit.getId());
    ObjectId treeId = commit.getTreeId();
    assertNotNull(treeId);
    RevTree root = repo.getTree(treeId);
    assertNotNull(root);
    Optional<Node> typeTreeId = repo.getTreeChild(root, pointsName);
    assertTrue(typeTreeId.isPresent());
    RevTree typeTree = repo.getTree(typeTreeId.get().getObjectId());
    assertNotNull(typeTree);
    String featureId = points1.getIdentifier().getID();
    Optional<Node> featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
    assertTrue(featureBlobId.isPresent());
    assertEquals(oid, featureBlobId.get().getObjectId());
    ObjectId commitId = geogig.command(RevParse.class).setRefSpec(Ref.HEAD).call().get();
    assertEquals(commit.getId(), commitId);
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevParse(org.locationtech.geogig.api.plumbing.RevParse) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) Node(org.locationtech.geogig.api.Node) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 2 with CommitOp

use of org.locationtech.geogig.api.porcelain.CommitOp in project GeoGig by boundlessgeo.

the class CommitOpTest method testCommitEmptyTreeOnNonEmptyRepo.

@Test
public void testCommitEmptyTreeOnNonEmptyRepo() throws Exception {
    insertAndAdd(points1, points2);
    geogig.command(CommitOp.class).call();
    // insertAndAdd(lines1, lines2);
    WorkingTree workingTree = geogig.getRepository().workingTree();
    final String emptyTreeName = "emptyTree";
    workingTree.createTypeTree(emptyTreeName, pointsType);
    {
        List<DiffEntry> unstaged = toList(workingTree.getUnstaged(null));
        assertEquals(unstaged.toString(), 1, unstaged.size());
        // assertEquals(NodeRef.ROOT, unstaged.get(0).newName());
        assertEquals(emptyTreeName, unstaged.get(0).newName());
    }
    geogig.command(AddOp.class).call();
    {
        StagingArea index = geogig.getRepository().index();
        List<DiffEntry> staged = toList(index.getStaged(null));
        assertEquals(staged.toString(), 1, staged.size());
        // assertEquals(NodeRef.ROOT, staged.get(0).newName());
        assertEquals(emptyTreeName, staged.get(0).newName());
    }
    CommitOp commitCommand = geogig.command(CommitOp.class);
    RevCommit commit = commitCommand.call();
    assertNotNull(commit);
    RevTree head = geogig.command(RevObjectParse.class).setObjectId(commit.getTreeId()).call(RevTree.class).get();
    Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(emptyTreeName).setParent(head).call();
    assertTrue(ref.isPresent());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) WorkingTree(org.locationtech.geogig.repository.WorkingTree) NodeRef(org.locationtech.geogig.api.NodeRef) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) StagingArea(org.locationtech.geogig.repository.StagingArea) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 3 with CommitOp

use of org.locationtech.geogig.api.porcelain.CommitOp in project GeoGig by boundlessgeo.

the class CommitOpTest method testCommitWithCustomAuthorAndCommitter.

@Test
public void testCommitWithCustomAuthorAndCommitter() throws Exception {
    try {
        geogig.command(AddOp.class).addPattern(".").call();
        geogig.command(CommitOp.class).call();
        fail("expected NothingToCommitException");
    } catch (NothingToCommitException e) {
        assertTrue(true);
    }
    ObjectId oid1 = insertAndAdd(points1);
    ObjectId oid2 = insertAndAdd(points2);
    geogig.command(AddOp.class).addPattern(".").call();
    CommitOp commitCommand = geogig.command(CommitOp.class);
    commitCommand.setAuthor("John Doe", "John@Doe.com");
    commitCommand.setCommitter("Jane Doe", "Jane@Doe.com");
    RevCommit commit = commitCommand.call();
    assertNotNull(commit);
    assertNotNull(commit.getParentIds());
    assertEquals(0, commit.getParentIds().size());
    assertFalse(commit.parentN(0).isPresent());
    assertNotNull(commit.getId());
    assertEquals("John Doe", commit.getAuthor().getName().get());
    assertEquals("John@Doe.com", commit.getAuthor().getEmail().get());
    assertEquals("Jane Doe", commit.getCommitter().getName().get());
    assertEquals("Jane@Doe.com", commit.getCommitter().getEmail().get());
    ObjectId treeId = commit.getTreeId();
    assertNotNull(treeId);
    RevTree root = repo.getTree(treeId);
    assertNotNull(root);
    Optional<Node> typeTreeId = repo.getTreeChild(root, pointsName);
    assertTrue(typeTreeId.isPresent());
    RevTree typeTree = repo.getTree(typeTreeId.get().getObjectId());
    assertNotNull(typeTree);
    String featureId = points1.getIdentifier().getID();
    Optional<Node> featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
    assertTrue(featureBlobId.isPresent());
    assertEquals(oid1, featureBlobId.get().getObjectId());
    featureId = points2.getIdentifier().getID();
    featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
    assertTrue(featureBlobId.isPresent());
    assertEquals(oid2, featureBlobId.get().getObjectId());
    ObjectId commitId = geogig.command(RevParse.class).setRefSpec(Ref.HEAD).call().get();
    assertEquals(commit.getId(), commitId);
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevParse(org.locationtech.geogig.api.plumbing.RevParse) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) Node(org.locationtech.geogig.api.Node) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 4 with CommitOp

use of org.locationtech.geogig.api.porcelain.CommitOp in project GeoGig by boundlessgeo.

the class Commit method runInternal.

/**
     * Executes the commit command using the provided options.
     * 
     * @param cli
     * @see org.locationtech.geogig.cli.AbstractCommand#runInternal(org.locationtech.geogig.cli.GeogigCLI)
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    final GeoGIG geogig = cli.getGeogig();
    if (message == null || Strings.isNullOrEmpty(message)) {
        message = geogig.command(ReadMergeCommitMessageOp.class).call();
    }
    checkParameter(!Strings.isNullOrEmpty(message) || commitToReuse != null || amend, "No commit message provided");
    ConsoleReader console = cli.getConsole();
    Ansi ansi = newAnsi(console.getTerminal());
    RevCommit commit;
    try {
        CommitOp commitOp = geogig.command(CommitOp.class).setMessage(message).setAmend(amend);
        if (commitTimestamp != null && !Strings.isNullOrEmpty(commitTimestamp)) {
            Long millis = geogig.command(ParseTimestamp.class).setString(commitTimestamp).call();
            commitOp.setCommitterTimestamp(millis.longValue());
        }
        if (commitToReuse != null) {
            Optional<ObjectId> commitId = geogig.command(RevParse.class).setRefSpec(commitToReuse).call();
            checkParameter(commitId.isPresent(), "Provided reference does not exist");
            TYPE type = geogig.command(ResolveObjectType.class).setObjectId(commitId.get()).call();
            checkParameter(TYPE.COMMIT.equals(type), "Provided reference does not resolve to a commit");
            commitOp.setCommit(geogig.getRepository().getCommit(commitId.get()));
        }
        commit = commitOp.setPathFilters(pathFilters).setProgressListener(cli.getProgressListener()).call();
    } catch (NothingToCommitException noChanges) {
        throw new CommandFailedException(noChanges.getMessage(), noChanges);
    }
    final ObjectId parentId = commit.parentN(0).or(ObjectId.NULL);
    console.println("[" + commit.getId() + "] " + commit.getMessage());
    console.print("Committed, counting objects...");
    Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(parentId).setNewVersion(commit.getId()).call();
    int adds = 0, deletes = 0, changes = 0;
    DiffEntry diffEntry;
    while (diff.hasNext()) {
        diffEntry = diff.next();
        switch(diffEntry.changeType()) {
            case ADDED:
                ++adds;
                break;
            case REMOVED:
                ++deletes;
                break;
            case MODIFIED:
                ++changes;
                break;
        }
    }
    ansi.fg(Color.GREEN).a(adds).reset().a(" features added, ").fg(Color.YELLOW).a(changes).reset().a(" changed, ").fg(Color.RED).a(deletes).reset().a(" deleted.").reset().newline();
    console.print(ansi.toString());
}
Also used : ConsoleReader(jline.console.ConsoleReader) ObjectId(org.locationtech.geogig.api.ObjectId) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) DiffOp(org.locationtech.geogig.api.porcelain.DiffOp) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) Ansi(org.fusesource.jansi.Ansi) TYPE(org.locationtech.geogig.api.RevObject.TYPE) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevCommit(org.locationtech.geogig.api.RevCommit) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 5 with CommitOp

use of org.locationtech.geogig.api.porcelain.CommitOp in project GeoGig by boundlessgeo.

the class CommitOpTest method testCommitEmptyTreeOnEmptyRepo.

@Test
public void testCommitEmptyTreeOnEmptyRepo() throws Exception {
    WorkingTree workingTree = geogig.getRepository().workingTree();
    final String emptyTreeName = "emptyTree";
    workingTree.createTypeTree(emptyTreeName, pointsType);
    geogig.command(AddOp.class).addPattern(emptyTreeName).call();
    CommitOp commitCommand = geogig.command(CommitOp.class);
    RevCommit commit = commitCommand.call();
    assertNotNull(commit);
    RevTree head = geogig.command(RevObjectParse.class).setObjectId(commit.getTreeId()).call(RevTree.class).get();
    Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(emptyTreeName).setParent(head).call();
    assertTrue(ref.isPresent());
}
Also used : WorkingTree(org.locationtech.geogig.repository.WorkingTree) NodeRef(org.locationtech.geogig.api.NodeRef) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Aggregations

CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)12 Test (org.junit.Test)9 NothingToCommitException (org.locationtech.geogig.api.porcelain.NothingToCommitException)9 RevCommit (org.locationtech.geogig.api.RevCommit)8 ObjectId (org.locationtech.geogig.api.ObjectId)5 RevTree (org.locationtech.geogig.api.RevTree)5 RevParse (org.locationtech.geogig.api.plumbing.RevParse)4 Node (org.locationtech.geogig.api.Node)3 NodeRef (org.locationtech.geogig.api.NodeRef)3 ConsoleReader (jline.console.ConsoleReader)2 GeoGIG (org.locationtech.geogig.api.GeoGIG)2 ProgressListener (org.locationtech.geogig.api.ProgressListener)2 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)2 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)2 AddOp (org.locationtech.geogig.api.porcelain.AddOp)2 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)2 WorkingTree (org.locationtech.geogig.repository.WorkingTree)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1