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);
}
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;
}
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);
}
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());
}
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));
*
* }
*/
}
Aggregations