use of org.locationtech.geogig.api.plumbing.merge.Conflict 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.plumbing.merge.Conflict in project GeoGig by boundlessgeo.
the class AddOpTest method testAdditionFixesConflict.
@Test
public void testAdditionFixesConflict() throws Exception {
Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
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();
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(true);
}
geogig.command(AddOp.class).call();
List<Conflict> conflicts = geogig.getRepository().stagingDatabase().getConflicts(null, null);
assertTrue(conflicts.isEmpty());
geogig.command(CommitOp.class).call();
Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
assertFalse(ref.isPresent());
}
use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.
the class JEConflictsTest method testConflicts.
@Test
public void testConflicts() {
StagingDatabase db = geogig.getRepository().stagingDatabase();
List<Conflict> conflicts = db.getConflicts(null, null);
assertTrue(conflicts.isEmpty());
Conflict conflict = new Conflict(idP1, ObjectId.forString("ancestor"), ObjectId.forString("ours"), ObjectId.forString("theirs"));
Conflict conflict2 = new Conflict(idP2, ObjectId.forString("ancestor2"), ObjectId.forString("ours2"), ObjectId.forString("theirs2"));
db.addConflict(null, conflict);
Optional<Conflict> returnedConflict = db.getConflict(null, idP1);
assertTrue(returnedConflict.isPresent());
assertEquals(conflict, returnedConflict.get());
db.removeConflict(null, idP1);
conflicts = db.getConflicts(null, null);
assertTrue(conflicts.isEmpty());
db.addConflict(null, conflict);
db.addConflict(null, conflict2);
assertEquals(2, db.getConflicts(null, null).size());
db.removeConflicts(null);
conflicts = db.getConflicts(null, null);
assertTrue(conflicts.isEmpty());
final String NS = "ns";
db.addConflict(NS, conflict);
db.addConflict(null, conflict2);
returnedConflict = db.getConflict(NS, idP1);
assertTrue(returnedConflict.isPresent());
assertEquals(conflict, returnedConflict.get());
assertEquals(1, db.getConflicts(NS, null).size());
db.removeConflict(NS, idP1);
conflicts = db.getConflicts(NS, null);
assertTrue(conflicts.isEmpty());
db.addConflict(NS, conflict);
db.addConflict(NS, conflict2);
assertEquals(2, db.getConflicts(NS, null).size());
assertEquals(1, db.getConflicts(null, null).size());
db.removeConflicts(NS);
conflicts = db.getConflicts(NS, null);
assertTrue(conflicts.isEmpty());
conflicts = db.getConflicts(null, null);
assertFalse(conflicts.isEmpty());
}
use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.
the class JEStagingDatabase method removeConflict.
/**
* Removes a conflict from the database.
*
* @param namespace the namespace of the conflict
* @param path the path of feature whose conflict should be removed
*/
@Override
public void removeConflict(@Nullable String namespace, final String path) {
checkNotNull(path, "path is null");
final Object monitor = resolveConflictsMonitor(namespace);
checkState(monitor != null, "Either not inside a repository directory or the staging area is closed");
synchronized (monitor) {
final File file = resolveConflictsFile(namespace);
if (file == null || !file.exists()) {
return;
}
try {
List<Conflict> conflicts = getConflicts(namespace, null);
StringBuilder sb = new StringBuilder();
for (Conflict conflict : conflicts) {
if (!path.equals(conflict.getPath())) {
sb.append(conflict.toString() + "\n");
}
}
String s = sb.toString();
if (s.isEmpty()) {
file.delete();
} else {
Files.write(s, file, Charsets.UTF_8);
}
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
}
use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.
the class MongoStagingDatabase method getConflict.
@Override
public Optional<Conflict> getConflict(@Nullable String namespace, String path) {
DBObject query = new BasicDBObject();
query.put("path", path);
if (namespace != null) {
query.put("namespace", namespace);
}
DBObject result = conflicts.findOne(query);
if (result == null) {
return Optional.absent();
} else {
ObjectId ancestor = ObjectId.valueOf((String) result.get("ancestor"));
ObjectId ours = ObjectId.valueOf((String) result.get("ours"));
ObjectId theirs = ObjectId.valueOf((String) result.get("theirs"));
return Optional.of(new Conflict(path, ancestor, ours, theirs));
}
}
Aggregations