use of org.locationtech.geogig.api.RevCommit 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.RevCommit 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.RevCommit in project GeoGig by boundlessgeo.
the class CherryPickOpTest method testCherryPickDirtyWorkTree.
@Test
public void testCherryPickDirtyWorkTree() throws Exception {
insertAndAdd(points1);
geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
// create branch1 and checkout
geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
insertAndAdd(points2);
RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
// checkout master and insert some features
geogig.command(CheckoutOp.class).setSource("master").call();
insert(points3);
CherryPickOp cherryPick = geogig.command(CherryPickOp.class);
cherryPick.setCommit(Suppliers.ofInstance(c1.getId()));
exception.expect(IllegalStateException.class);
cherryPick.call();
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class CherryPickOpTest method testCherryPickWithConflicts.
@Test
public void testCherryPickWithConflicts() throws Exception {
insertAndAdd(points1);
geogig.command(CommitOp.class).call();
// create branch1, checkout and add a commit
geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
insert(points2);
Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
insertAndAdd(points1Modified);
geogig.command(AddOp.class).call();
RevCommit branchCommit = geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource(Ref.MASTER).call();
Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
insert(points1ModifiedB);
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).call();
try {
geogig.command(CherryPickOp.class).setCommit(Suppliers.ofInstance(branchCommit.getId())).call();
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("conflict in Points/Points.1"));
}
Optional<Ref> cherrypickHead = geogig.command(RefParse.class).setName(Ref.CHERRY_PICK_HEAD).call();
assertTrue(cherrypickHead.isPresent());
// check that unconflicted changes are in index and working tree
Optional<RevObject> pts2 = geogig.command(RevObjectParse.class).setRefSpec(Ref.WORK_HEAD + ":" + NodeRef.appendChild(pointsName, idP2)).call();
assertTrue(pts2.isPresent());
assertEquals(RevFeatureBuilder.build(points2), pts2.get());
pts2 = geogig.command(RevObjectParse.class).setRefSpec(Ref.STAGE_HEAD + ":" + NodeRef.appendChild(pointsName, idP2)).call();
assertTrue(pts2.isPresent());
assertEquals(RevFeatureBuilder.build(points2), pts2.get());
// solve and commit
Feature points1Solved = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
insert(points1Solved);
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).setCommit(branchCommit).call();
Optional<RevObject> ptsSolved = geogig.command(RevObjectParse.class).setRefSpec(Ref.WORK_HEAD + ":" + NodeRef.appendChild(pointsName, idP1)).call();
assertTrue(pts2.isPresent());
assertEquals(RevFeatureBuilder.build(points1Solved), ptsSolved.get());
cherrypickHead = geogig.command(RefParse.class).setName(Ref.CHERRY_PICK_HEAD).call();
assertFalse(cherrypickHead.isPresent());
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class CherryPickOpTest method testCherryPickRootCommit.
@Ignore
// this test probably does not make sense with the current behaviour of cherry pick
@Test
public void testCherryPickRootCommit() throws Exception {
insertAndAdd(points1);
final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
CherryPickOp cherryPick = geogig.command(CherryPickOp.class);
cherryPick.setCommit(Suppliers.ofInstance(c1.getId()));
cherryPick.call();
Iterator<RevCommit> log = geogig.command(LogOp.class).call();
// Commit 2
RevCommit logC2 = log.next();
assertEquals(c1.getMessage(), logC2.getMessage());
assertEquals(c1.getAuthor(), logC2.getAuthor());
assertEquals(c1.getCommitter().getName(), logC2.getCommitter().getName());
assertEquals(c1.getCommitter().getEmail(), logC2.getCommitter().getEmail());
assertFalse(c1.getCommitter().getTimestamp() == logC2.getCommitter().getTimestamp());
assertEquals(c1.getTreeId(), logC2.getTreeId());
// Commit 1
RevCommit logC1 = log.next();
assertEquals(c1, logC1);
assertFalse(log.hasNext());
}
Aggregations