Search in sources :

Example 1 with RevTag

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

the class ResolveTreeish method call.

/**
     * @param resolved an {@link Optional} with an ObjectId to resolve
     * @return an {@link Optional} of the {@link ObjectId} that was resolved, or
     *         {@link Optional#absent()} if it did not resolve.
     */
private Optional<ObjectId> call(Optional<ObjectId> resolved) {
    if (!resolved.isPresent()) {
        return Optional.absent();
    }
    ObjectId objectId = resolved.get();
    if (objectId.isNull()) {
        // might be an empty commit ref
        return Optional.of(RevTree.EMPTY_TREE_ID);
    }
    final TYPE objectType = command(ResolveObjectType.class).setObjectId(objectId).call();
    switch(objectType) {
        case TREE:
            // ok
            break;
        case COMMIT:
            {
                Optional<RevCommit> commit = command(RevObjectParse.class).setObjectId(objectId).call(RevCommit.class);
                if (commit.isPresent()) {
                    objectId = commit.get().getTreeId();
                } else {
                    objectId = null;
                }
                break;
            }
        case TAG:
            {
                Optional<RevTag> tag = command(RevObjectParse.class).setObjectId(objectId).call(RevTag.class);
                if (tag.isPresent()) {
                    ObjectId commitId = tag.get().getCommitId();
                    return call(Optional.of(commitId));
                }
            }
        default:
            throw new IllegalArgumentException(String.format("Provided ref spec ('%s') doesn't resolve to a tree-ish object: %s", treeishRefSpec, String.valueOf(objectType)));
    }
    return Optional.fromNullable(objectId);
}
Also used : Optional(com.google.common.base.Optional) RevTag(org.locationtech.geogig.api.RevTag) ObjectId(org.locationtech.geogig.api.ObjectId) TYPE(org.locationtech.geogig.api.RevObject.TYPE) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 2 with RevTag

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

the class RevParse method resolveCommit.

/**
     * @param objectId
     * @return
     */
private RevCommit resolveCommit(ObjectId objectId) {
    final Optional<RevObject> object = command(RevObjectParse.class).setObjectId(objectId).call();
    checkArgument(object.isPresent(), "No object named %s could be found", objectId);
    final RevObject revObject = object.get();
    RevCommit commit;
    switch(revObject.getType()) {
        case COMMIT:
            commit = (RevCommit) revObject;
            break;
        case TAG:
            ObjectId commitId = ((RevTag) revObject).getCommitId();
            commit = command(RevObjectParse.class).setObjectId(commitId).call(RevCommit.class).get();
            break;
        default:
            throw new IllegalArgumentException(String.format("%s did not resolve to a commit or tag: %s", objectId, revObject.getType()));
    }
    return commit;
}
Also used : RevTag(org.locationtech.geogig.api.RevTag) RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 3 with RevTag

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

the class HashObjectTest method testHashTags.

@Test
public void testHashTags() throws Exception {
    RevPerson tagger = new RevPersonImpl("volaya", "volaya@boundlessgeo.com", -1000, -1);
    RevPerson tagger2 = new RevPersonImpl("groldan", "groldan@boundlessgeo.com", 10000, 0);
    RevTag tag = new RevTagImpl(null, "tag1", ObjectId.forString("fake commit id"), "message", tagger);
    RevTag tag2 = new RevTagImpl(null, "tag2", ObjectId.forString("another fake commit id"), "another message", tagger2);
    ObjectId tagId = hashCommand.setObject(tag).call();
    ObjectId tagId2 = hashCommand.setObject(tag2).call();
    assertNotNull(tagId);
    assertNotNull(tagId2);
    assertNotSame(tagId, tagId2);
}
Also used : RevPersonImpl(org.locationtech.geogig.api.RevPersonImpl) RevPerson(org.locationtech.geogig.api.RevPerson) RevTag(org.locationtech.geogig.api.RevTag) ObjectId(org.locationtech.geogig.api.ObjectId) RevTagImpl(org.locationtech.geogig.api.RevTagImpl) Test(org.junit.Test)

Example 4 with RevTag

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

the class TagTest method testTagCreation.

@Test
public void testTagCreation() throws Exception {
    insertAndAdd(points1);
    RevCommit commit = geogig.command(CommitOp.class).call();
    RevTag tag = geogig.command(TagCreateOp.class).setCommitId(commit.getId()).setName("Tag1").call();
    Optional<RevTag> databaseTag = geogig.command(RevObjectParse.class).setRefSpec("Tag1").call(RevTag.class);
    assertTrue(databaseTag.isPresent());
    assertEquals(tag, databaseTag.get());
}
Also used : RevTag(org.locationtech.geogig.api.RevTag) TagCreateOp(org.locationtech.geogig.api.porcelain.TagCreateOp) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 5 with RevTag

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

the class CloneOpTest method testCloneWithTags.

@Test
public void testCloneWithTags() throws Exception {
    // Commit several features to the remote
    List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
    LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
    List<RevTag> tags = Lists.newArrayList();
    for (Feature f : features) {
        ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
        final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
        expected.addFirst(commit);
        Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
        assertTrue(childObject.isPresent());
        RevTag tag = remoteGeogig.geogig.command(TagCreateOp.class).setCommitId(commit.getId()).setName(f.getIdentifier().getID()).call();
        tags.add(tag);
    }
    // Make sure the remote has all of the commits
    Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expected, logged);
    // Make sure the remote has all of the tags
    ImmutableList<RevTag> remoteTags = remoteGeogig.geogig.command(TagListOp.class).call();
    assertEquals(tags.size(), remoteTags.size());
    for (RevTag tag : tags) {
        assertTrue(remoteTags.contains(tag));
    }
    // Make sure the local repository has no commits prior to clone
    logs = localGeogig.geogig.command(LogOp.class).call();
    assertNotNull(logs);
    assertFalse(logs.hasNext());
    // clone from the remote
    CloneOp clone = clone();
    clone.setDepth(0);
    clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
    // Make sure the local repository got all of the commits
    logs = localGeogig.geogig.command(LogOp.class).call();
    logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expected, logged);
/*
         * This is commented out, since the clone operation does not clone tags yet This test
         * verifies that no errors are raised when the repo to clone contains tags, but not to
         * verify that tags are also cloned, since that is not supported
         * 
         * I leave this dommented code here, to uncomment it once tag support is implemented for the
         * clone operation
         * 
         * 
         * // Make sure the local repository got all of the tags
         * 
         * ImmutableList<RevTag> localTags = localGeogig.geogig.command(TagListOp.class).call();
         * 
         * assertEquals(tags.size(), localTags.size());
         * 
         * for (RevTag tag : tags) {
         * 
         * assertTrue(localTags.contains(tag));
         * 
         * }
         */
}
Also used : CloneOp(org.locationtech.geogig.api.porcelain.CloneOp) RevTag(org.locationtech.geogig.api.RevTag) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) Feature(org.opengis.feature.Feature) LinkedList(java.util.LinkedList) TagListOp(org.locationtech.geogig.api.porcelain.TagListOp) TagCreateOp(org.locationtech.geogig.api.porcelain.TagCreateOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Aggregations

RevTag (org.locationtech.geogig.api.RevTag)16 ObjectId (org.locationtech.geogig.api.ObjectId)8 RevCommit (org.locationtech.geogig.api.RevCommit)8 RevObject (org.locationtech.geogig.api.RevObject)6 Test (org.junit.Test)4 Ref (org.locationtech.geogig.api.Ref)3 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)3 TagCreateOp (org.locationtech.geogig.api.porcelain.TagCreateOp)3 TagListOp (org.locationtech.geogig.api.porcelain.TagListOp)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Context (org.locationtech.geogig.api.Context)2 GeoGIG (org.locationtech.geogig.api.GeoGIG)2 RevPerson (org.locationtech.geogig.api.RevPerson)2 RevTagImpl (org.locationtech.geogig.api.RevTagImpl)2 RevTree (org.locationtech.geogig.api.RevTree)2 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)2 CommandContext (org.locationtech.geogig.web.api.CommandContext)2 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)2 Optional (com.google.common.base.Optional)1