use of org.locationtech.geogig.api.porcelain.MergeOp in project GeoGig by boundlessgeo.
the class MergeOpTest method testConflictingOctopusMerge.
@Test
public void testConflictingOctopusMerge() throws Exception {
// Create the following revision graph
// . o
// . |
// . o - Points 1 added
// . |\
// . | o - branch1 - Points 1 modified
// . |
// . o - Points 2 added
// ./|
// o | - branch2 - Point 1 modified B
// . |
// . o - master - HEAD - Point 1 modified C
insertAndAdd(points1);
geogig.command(CommitOp.class).call();
geogig.command(BranchCreateOp.class).setName("branch1").call();
insertAndAdd(points2);
geogig.command(CommitOp.class).call();
geogig.command(BranchCreateOp.class).setName("branch2").call();
Feature points1ModifiedC = feature(pointsType, idP1, "StringProp1_4", new Integer(3000), "POINT(1 3)");
insertAndAdd(points1ModifiedC);
geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("branch1").call();
Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
insertAndAdd(points1Modified);
geogig.command(CommitOp.class).call();
geogig.command(CheckoutOp.class).setSource("branch2").call();
Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 2)");
insertAndAdd(points1ModifiedB);
geogig.command(CommitOp.class).call();
// Now try to merge all branches into master
geogig.command(CheckoutOp.class).setSource("master").call();
Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
Ref branch2 = geogig.command(RefParse.class).setName("branch2").call().get();
MergeOp mergeOp = geogig.command(MergeOp.class);
mergeOp.addCommit(Suppliers.ofInstance(branch1.getObjectId()));
mergeOp.addCommit(Suppliers.ofInstance(branch2.getObjectId()));
try {
mergeOp.call();
fail();
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("Cannot merge more than two commits when conflicts exist"));
}
}
use of org.locationtech.geogig.api.porcelain.MergeOp in project GeoGig by boundlessgeo.
the class MergeWebOp 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("No transaction was specified, merge requires a transaction to preserve the stability of the repository.");
} else if (this.commit == null) {
throw new CommandSpecException("No commits were specified for merging.");
}
final GeogigTransaction transaction = (GeogigTransaction) this.getCommandLocator(context);
final Optional<Ref> currHead = transaction.command(RefParse.class).setName(Ref.HEAD).call();
if (!currHead.isPresent()) {
throw new CommandSpecException("Repository has no HEAD, can't merge.");
}
MergeOp merge = transaction.command(MergeOp.class);
merge.setAuthor(authorName.orNull(), authorEmail.orNull());
final Optional<ObjectId> oid = transaction.command(RevParse.class).setRefSpec(commit).call();
if (oid.isPresent()) {
merge.addCommit(Suppliers.ofInstance(oid.get()));
} else {
throw new CommandSpecException("Couldn't resolve '" + commit + "' to a commit.");
}
try {
final MergeReport report = merge.setNoCommit(noCommit).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeMergeResponse(Optional.fromNullable(report.getMergeCommit()), report.getReport().get(), transaction, report.getOurs(), report.getPairs().get(0).getTheirs(), report.getPairs().get(0).getAncestor());
out.finish();
}
});
} catch (Exception e) {
final RevCommit ours = context.getGeoGIG().getRepository().getCommit(currHead.get().getObjectId());
final RevCommit theirs = context.getGeoGIG().getRepository().getCommit(oid.get());
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();
}
});
}
}
Aggregations