Search in sources :

Example 81 with RevCommit

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);
}
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 82 with RevCommit

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;
}
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 83 with RevCommit

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();
}
Also used : CherryPickOp(org.locationtech.geogig.api.porcelain.CherryPickOp) BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 84 with RevCommit

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());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) RevObject(org.locationtech.geogig.api.RevObject) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) Feature(org.opengis.feature.Feature) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) RefParse(org.locationtech.geogig.api.plumbing.RefParse) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 85 with RevCommit

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());
}
Also used : CherryPickOp(org.locationtech.geogig.api.porcelain.CherryPickOp) LogOp(org.locationtech.geogig.api.porcelain.LogOp) RevCommit(org.locationtech.geogig.api.RevCommit) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

RevCommit (org.locationtech.geogig.api.RevCommit)291 Test (org.junit.Test)212 ObjectId (org.locationtech.geogig.api.ObjectId)109 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)107 LogOp (org.locationtech.geogig.api.porcelain.LogOp)86 Ref (org.locationtech.geogig.api.Ref)71 Feature (org.opengis.feature.Feature)52 NodeRef (org.locationtech.geogig.api.NodeRef)47 ArrayList (java.util.ArrayList)44 BranchCreateOp (org.locationtech.geogig.api.porcelain.BranchCreateOp)44 RevTree (org.locationtech.geogig.api.RevTree)36 SymRef (org.locationtech.geogig.api.SymRef)33 RefParse (org.locationtech.geogig.api.plumbing.RefParse)33 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)31 RevObject (org.locationtech.geogig.api.RevObject)30 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)30 MergeScenarioReport (org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport)30 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)26 LinkedList (java.util.LinkedList)24 AddOp (org.locationtech.geogig.api.porcelain.AddOp)21