use of org.locationtech.geogig.api.porcelain.MergeConflictsException in project GeoGig by boundlessgeo.
the class DefaultStepDefinitions method I_have_a_merge_conflict_state.
@Given("^I have a merge conflict state$")
public void I_have_a_merge_conflict_state() throws Throwable {
I_have_conflicting_branches();
Ref branch = geogigCLI.getGeogig(Hints.readOnly()).command(RefParse.class).setName("branch1").call().get();
try {
geogigCLI.getGeogig(Hints.readWrite()).command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId())).call();
fail();
} catch (MergeConflictsException e) {
}
}
use of org.locationtech.geogig.api.porcelain.MergeConflictsException in project GeoGig by boundlessgeo.
the class EndTransaction method run.
/**
* Runs the command and builds the appropriate response.
*
* @param context - the context to use for this command
*
* @throws CommandSpecException
*/
@Override
public void run(CommandContext context) {
if (this.getTransactionId() == null) {
throw new CommandSpecException("There isn't a transaction to end.");
}
final Context transaction = this.getCommandLocator(context);
TransactionEnd endTransaction = context.getGeoGIG().command(TransactionEnd.class);
try {
final boolean closed = endTransaction.setCancel(cancel).setTransaction((GeogigTransaction) transaction).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
if (closed) {
out.writeTransactionId(null);
} else {
out.writeTransactionId(getTransactionId());
}
out.finish();
}
});
} catch (MergeConflictsException m) {
final RevCommit ours = context.getGeoGIG().getRepository().getCommit(m.getOurs());
final RevCommit theirs = context.getGeoGIG().getRepository().getCommit(m.getTheirs());
final Optional<ObjectId> ancestor = transaction.command(FindCommonAncestor.class).setLeft(ours).setRight(theirs).call();
context.setResponseContent(new CommandResponse() {
final MergeScenarioReport report = transaction.command(ReportMergeScenarioOp.class).setMergeIntoCommit(ours).setToMergeCommit(theirs).call();
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
Optional<RevCommit> mergeCommit = Optional.absent();
out.writeMergeResponse(mergeCommit, report, transaction, ours.getId(), theirs.getId(), ancestor.get());
out.finish();
}
});
} catch (RebaseConflictsException r) {
// TODO: Handle rebase exception
}
}
use of org.locationtech.geogig.api.porcelain.MergeConflictsException in project GeoGig by boundlessgeo.
the class MergeOpTest method testMergeConflictingBranches.
@Test
public void testMergeConflictingBranches() throws Exception {
// Create the following revision graph
// o
// |
// o - Points 1,2 added
// |\
// | o - TestBranch - Points 1 modified, 2 removed, 3 added
// |
// o - master - HEAD - Points 1 modifiedB, 2 removed
insertAndAdd(points1, points2);
geogig.command(CommitOp.class).call();
geogig.command(BranchCreateOp.class).setName("TestBranch").call();
Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
insert(points1Modified);
delete(points2);
insert(points3);
geogig.command(AddOp.class).call();
RevCommit masterCommit = geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("TestBranch").call();
Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
insert(points1ModifiedB);
delete(points2);
geogig.command(AddOp.class).call();
RevCommit branchCommit = geogig.command(CommitOp.class).call();
// Now try to merge branch into master
geogig.command(CheckoutOp.class).setSource("master").call();
Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get();
try {
geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId())).call();
fail();
} catch (MergeConflictsException e) {
assertTrue(e.getMessage().contains("conflict"));
}
Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
assertTrue(ref.isPresent());
assertEquals(masterCommit.getId(), ref.get().getObjectId());
ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
assertTrue(ref.isPresent());
assertEquals(branch.getObjectId(), ref.get().getObjectId());
String msg = geogig.command(ReadMergeCommitMessageOp.class).call();
assertFalse(Strings.isNullOrEmpty(msg));
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(points1Modified).getId());
assertEquals(conflicts.get(0).getTheirs(), RevFeatureBuilder.build(points1ModifiedB).getId());
// try to commit
try {
geogig.command(CommitOp.class).call();
fail();
} catch (IllegalStateException e) {
assertEquals(e.getMessage(), "Cannot run operation while merge conflicts exist.");
}
// solve, and commit
Feature points1Merged = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
insert(points1Merged);
geogig.command(AddOp.class).call();
RevCommit commit = geogig.command(CommitOp.class).call();
assertTrue(commit.getMessage().contains(idP1));
List<ObjectId> parents = commit.getParentIds();
assertEquals(2, parents.size());
assertEquals(masterCommit.getId(), parents.get(0));
assertEquals(branchCommit.getId(), parents.get(1));
Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertTrue(revFeature.isPresent());
assertEquals(RevFeatureBuilder.build(points1Merged), revFeature.get());
path = NodeRef.appendChild(pointsName, idP2);
revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertFalse(revFeature.isPresent());
path = NodeRef.appendChild(pointsName, idP3);
revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
assertTrue(revFeature.isPresent());
ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
assertFalse(ref.isPresent());
}
use of org.locationtech.geogig.api.porcelain.MergeConflictsException in project GeoGig by boundlessgeo.
the class CheckoutOpTest method createDeleteTheirsConflictedState.
private void createDeleteTheirsConflictedState() throws Exception {
// Create the following revision graph
// o
// |
// o - Points 1 added
// |\
// | o - TestBranch - Points 1 deleted and points 2 added
// |
// o - master - HEAD - Points 1 modified
insertAndAdd(points1);
geogig.command(CommitOp.class).call();
geogig.command(BranchCreateOp.class).setName("TestBranch").call();
insertAndAdd(points1Modified);
geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("TestBranch").call();
geogig.command(RemoveOp.class).addPathToRemove(NodeRef.appendChild(pointsName, idP1)).call();
insertAndAdd(points2);
geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("master").call();
Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get();
try {
geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId())).call();
fail();
} catch (MergeConflictsException e) {
assertTrue(e.getMessage().contains("conflict"));
}
}
use of org.locationtech.geogig.api.porcelain.MergeConflictsException in project GeoGig by boundlessgeo.
the class CheckoutOpTest method createDeleteOursConflictedState.
private void createDeleteOursConflictedState() throws Exception {
// Create the following revision graph
// o
// |
// o - Points 1 added
// |\
// | o - TestBranch - Points 1 deleted and points 2 added
// |
// o - master - HEAD - Points 1 modified
insertAndAdd(points1);
geogig.command(CommitOp.class).call();
geogig.command(BranchCreateOp.class).setName("TestBranch").call();
geogig.command(RemoveOp.class).addPathToRemove(NodeRef.appendChild(pointsName, idP1)).call();
geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("TestBranch").call();
insertAndAdd(points1ModifiedB);
insertAndAdd(points2);
geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("master").call();
Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get();
try {
geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId())).call();
fail();
} catch (MergeConflictsException e) {
assertTrue(e.getMessage().contains("conflict"));
}
}
Aggregations