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());
}
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));
}
}
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.");
}
}
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());
}
Aggregations