Search in sources :

Example 1 with RevertConflictsException

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

the class RevertOpTest method testRevertModifiedFeatureConflictSolveAndContinue.

@Test
public void testRevertModifiedFeatureConflictSolveAndContinue() throws Exception {
    ObjectId oId1 = insertAndAdd(points1);
    RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    insertAndAdd(points1_modified);
    RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1).call();
    Feature points1_modifiedB = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
    insertAndAdd(points1_modifiedB);
    RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1 + " again").call();
    try {
        geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(c2.getId())).call();
        fail();
    } catch (RevertConflictsException e) {
        assertTrue(e.getMessage().contains(idP1));
    }
    Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
    assertTrue(ref.isPresent());
    assertEquals(c3.getId(), ref.get().getObjectId());
    List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
    assertEquals(1, conflicts.size());
    String path = NodeRef.appendChild(pointsName, idP1);
    assertEquals(conflicts.get(0).getPath(), path);
    assertEquals(conflicts.get(0).getOurs(), RevFeatureBuilder.build(points1_modifiedB).getId());
    assertEquals(conflicts.get(0).getTheirs(), RevFeatureBuilder.build(points1).getId());
    // solve, and continue
    insert(points1);
    geogig.command(AddOp.class).call();
    geogig.command(RevertOp.class).setContinue(true).call();
    Iterator<RevCommit> log = geogig.command(LogOp.class).call();
    RevCommit logCommit = log.next();
    assertEquals(c2.getAuthor().getName(), logCommit.getAuthor().getName());
    assertEquals(c2.getCommitter().getName(), logCommit.getCommitter().getName());
    assertEquals("Revert '" + c2.getMessage() + "'\nThis reverts " + c2.getId().toString(), logCommit.getMessage());
    assertNotSame(c2.getCommitter().getTimestamp(), logCommit.getCommitter().getTimestamp());
    assertNotSame(c2.getTreeId(), logCommit.getTreeId());
    final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD).call();
    final Optional<ObjectId> headTreeId = geogig.command(ResolveTreeish.class).setTreeish(currHead.get().getObjectId()).call();
    RevTree headTree = repo.getTree(headTreeId.get());
    Optional<NodeRef> points1Node = geogig.command(FindTreeChild.class).setChildPath(NodeRef.appendChild(pointsName, idP1)).setParent(headTree).call();
    assertTrue(points1Node.isPresent());
    assertEquals(oId1, points1Node.get().getNode().getObjectId());
    assertEquals(c3.getId(), log.next().getId());
    assertEquals(c2.getId(), log.next().getId());
    assertEquals(c1.getId(), log.next().getId());
    assertFalse(log.hasNext());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) ObjectId(org.locationtech.geogig.api.ObjectId) LogOp(org.locationtech.geogig.api.porcelain.LogOp) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) Feature(org.opengis.feature.Feature) NodeRef(org.locationtech.geogig.api.NodeRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) RevertConflictsException(org.locationtech.geogig.api.porcelain.RevertConflictsException) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 2 with RevertConflictsException

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

the class RevertOpTest method testStillDeletedMergeConflictResolution.

@Test
public void testStillDeletedMergeConflictResolution() throws Exception {
    insertAndAdd(points1);
    @SuppressWarnings("unused") RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    deleteAndAdd(points1);
    RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for removing " + idP1).call();
    @SuppressWarnings("unused") ObjectId oId1 = insertAndAdd(points1);
    @SuppressWarnings("unused") RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP1 + " again").call();
    try {
        geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(c2.getId())).call();
        fail();
    } catch (RevertConflictsException e) {
        assertTrue(e.getMessage().contains(idP1));
    }
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevertConflictsException(org.locationtech.geogig.api.porcelain.RevertConflictsException) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 3 with RevertConflictsException

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

the class Revert method runInternal.

/**
     * Executes the revert command.
     */
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(commits.size() > 0 || abort || continueRevert, "nothing specified for reverting");
    final GeoGIG geogig = cli.getGeogig();
    RevertOp revert = geogig.command(RevertOp.class);
    for (String st : commits) {
        Optional<ObjectId> commitId = geogig.command(RevParse.class).setRefSpec(st).call();
        checkParameter(commitId.isPresent(), "Couldn't resolve '" + st + "' to a commit, aborting revert.");
        revert.addCommit(Suppliers.ofInstance(commitId.get()));
    }
    try {
        revert.setCreateCommit(!noCommit).setAbort(abort).setContinue(continueRevert).call();
    } catch (RevertConflictsException e) {
        StringBuilder sb = new StringBuilder();
        sb.append(e.getMessage() + "\n");
        sb.append("When you have fixed these conflicts, run 'geogig revert --continue' to continue the revert operation.\n");
        sb.append("To abort the revert operation, run 'geogig revert --abort'\n");
        throw new CommandFailedException(sb.toString());
    }
    if (abort) {
        cli.getConsole().println("Revert aborted successfully.");
    }
}
Also used : RevertOp(org.locationtech.geogig.api.porcelain.RevertOp) ObjectId(org.locationtech.geogig.api.ObjectId) RevertConflictsException(org.locationtech.geogig.api.porcelain.RevertConflictsException) GeoGIG(org.locationtech.geogig.api.GeoGIG) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Example 4 with RevertConflictsException

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

the class RevertOpTest method testRevertModifiedFeatureConflictAndAbort.

@Test
public void testRevertModifiedFeatureConflictAndAbort() throws Exception {
    insertAndAdd(points1);
    @SuppressWarnings("unused") RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    insertAndAdd(points1_modified);
    RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1).call();
    Feature points1_modifiedB = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
    ObjectId oId = insertAndAdd(points1_modifiedB);
    RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1 + " again").call();
    try {
        geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(c2.getId())).call();
        fail();
    } catch (RevertConflictsException e) {
        assertTrue(e.getMessage().contains(idP1));
    }
    Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
    assertTrue(ref.isPresent());
    assertEquals(c3.getId(), ref.get().getObjectId());
    List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
    assertEquals(1, conflicts.size());
    String path = NodeRef.appendChild(pointsName, idP1);
    assertEquals(conflicts.get(0).getPath(), path);
    assertEquals(conflicts.get(0).getOurs(), RevFeatureBuilder.build(points1_modifiedB).getId());
    assertEquals(conflicts.get(0).getTheirs(), RevFeatureBuilder.build(points1).getId());
    geogig.command(RevertOp.class).setAbort(true).call();
    final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD).call();
    final Optional<ObjectId> headTreeId = geogig.command(ResolveTreeish.class).setTreeish(currHead.get().getObjectId()).call();
    RevTree headTree = repo.getTree(headTreeId.get());
    Optional<NodeRef> points1Node = geogig.command(FindTreeChild.class).setChildPath(NodeRef.appendChild(pointsName, idP1)).setParent(headTree).call();
    assertTrue(points1Node.isPresent());
    assertEquals(oId, points1Node.get().getNode().getObjectId());
}
Also used : ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) ObjectId(org.locationtech.geogig.api.ObjectId) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) Feature(org.opengis.feature.Feature) NodeRef(org.locationtech.geogig.api.NodeRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) RevertConflictsException(org.locationtech.geogig.api.porcelain.RevertConflictsException) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Aggregations

ObjectId (org.locationtech.geogig.api.ObjectId)4 RevertConflictsException (org.locationtech.geogig.api.porcelain.RevertConflictsException)4 Test (org.junit.Test)3 RevCommit (org.locationtech.geogig.api.RevCommit)3 NodeRef (org.locationtech.geogig.api.NodeRef)2 Ref (org.locationtech.geogig.api.Ref)2 RevTree (org.locationtech.geogig.api.RevTree)2 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)2 Conflict (org.locationtech.geogig.api.plumbing.merge.Conflict)2 ConflictsReadOp (org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp)2 Feature (org.opengis.feature.Feature)2 GeoGIG (org.locationtech.geogig.api.GeoGIG)1 AddOp (org.locationtech.geogig.api.porcelain.AddOp)1 LogOp (org.locationtech.geogig.api.porcelain.LogOp)1 RevertOp (org.locationtech.geogig.api.porcelain.RevertOp)1 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)1