use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.
the class JEStagingDatabase method getConflicts.
/**
* Gets all conflicts that match the specified path filter.
*
* @param namespace the namespace of the conflict
* @param pathFilter the path filter, if this is not defined, all conflicts will be returned
* @return the list of conflicts
*/
@Override
public List<Conflict> getConflicts(@Nullable String namespace, @Nullable final String pathFilter) {
final Object monitor = resolveConflictsMonitor(namespace);
if (null == monitor) {
return ImmutableList.of();
}
synchronized (monitor) {
final File file = resolveConflictsFile(namespace);
if (null == file || !file.exists() || file.length() == 0) {
return ImmutableList.of();
}
List<Conflict> conflicts;
try {
conflicts = Files.readLines(file, Charsets.UTF_8, new LineProcessor<List<Conflict>>() {
List<Conflict> conflicts = Lists.newArrayList();
@Override
public List<Conflict> getResult() {
return conflicts;
}
@Override
public boolean processLine(String s) throws IOException {
Conflict c = Conflict.valueOf(s);
if (pathFilter == null) {
conflicts.add(c);
} else if (c.getPath().startsWith(pathFilter)) {
conflicts.add(c);
}
return true;
}
});
} catch (IOException e) {
throw Throwables.propagate(e);
}
return conflicts;
}
}
use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.
the class Status method printUnmerged.
private void printUnmerged(final ConsoleReader console, final Iterable<Conflict> conflicts, final Color color, final int total) throws IOException {
StringBuilder sb = new StringBuilder();
Ansi ansi = newAnsi(console.getTerminal(), sb);
String path;
for (Conflict c : conflicts) {
path = c.getPath();
sb.setLength(0);
ansi.a("# ").fg(color).a("unmerged").a(" ").a(path).reset();
console.println(ansi.toString());
}
sb.setLength(0);
ansi.a("# ").a(String.format("%,d", total)).a(" total.");
console.println(ansi.toString());
}
use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.
the class GeogigTransactionTest method testConflictIsolation.
@Test
public void testConflictIsolation() throws Exception {
insertAndAdd(points2);
geogig.command(CommitOp.class).setMessage("foo").call();
geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
insertAndAdd(points1);
RevCommit mainCommit = geogig.command(CommitOp.class).setMessage("Commit1").call();
geogig.command(CheckoutOp.class).setSource("master").call();
insertAndAdd(points1_modified);
RevCommit modifiedCommit = geogig.command(CommitOp.class).setMessage("Commit2").call();
GeogigTransaction tx = geogig.command(TransactionBegin.class).call();
try {
tx.command(MergeOp.class).addCommit(Suppliers.ofInstance(mainCommit.getId())).call();
fail("Expected a merge conflict!");
} catch (org.locationtech.geogig.api.porcelain.MergeConflictsException e) {
// expected.
}
List<Conflict> txConflicts = tx.command(ConflictsReadOp.class).call();
List<Conflict> baseConflicts = geogig.command(ConflictsReadOp.class).call();
assertTrue("There should be no conflicts outside the transaction", baseConflicts.size() == 0);
assertTrue("There should be conflicts in the transaction", txConflicts.size() != 0);
}
use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.
the class ConflictsReadWriteOpTest method testReadWriteConflicts.
@Test
public void testReadWriteConflicts() throws Exception {
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"));
ArrayList<Conflict> conflicts = Lists.newArrayList(conflict, conflict2);
geogig.command(ConflictsWriteOp.class).setConflicts(conflicts).call();
List<Conflict> returnedConflicts = geogig.command(ConflictsReadOp.class).call();
assertEquals(conflicts, returnedConflicts);
}
use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.
the class MongoStagingDatabase method getConflicts.
@Override
public List<Conflict> getConflicts(@Nullable String namespace, @Nullable String pathFilter) {
DBObject query = new BasicDBObject();
if (namespace == null) {
query.put("namespace", 0);
} else {
query.put("namespace", namespace);
}
if (pathFilter != null) {
DBObject regex = new BasicDBObject();
regex.put("$regex", "^" + pathFilter);
query.put("path", regex);
}
DBCursor cursor = conflicts.find(query);
List<Conflict> results = new ArrayList<Conflict>();
while (cursor.hasNext()) {
DBObject element = cursor.next();
String path = (String) element.get("path");
ObjectId ancestor = ObjectId.valueOf((String) element.get("ancestor"));
ObjectId ours = ObjectId.valueOf((String) element.get("ours"));
ObjectId theirs = ObjectId.valueOf((String) element.get("theirs"));
results.add(new Conflict(path, ancestor, ours, theirs));
}
return results;
}
Aggregations