Search in sources :

Example 26 with Conflict

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;
    }
}
Also used : Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) IOException(java.io.IOException) LineProcessor(com.google.common.io.LineProcessor) File(java.io.File)

Example 27 with Conflict

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());
}
Also used : Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) Ansi(org.fusesource.jansi.Ansi)

Example 28 with Conflict

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);
}
Also used : GeogigTransaction(org.locationtech.geogig.api.GeogigTransaction) ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) TransactionBegin(org.locationtech.geogig.api.plumbing.TransactionBegin) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 29 with Conflict

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);
}
Also used : ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) Test(org.junit.Test)

Example 30 with Conflict

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;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) ObjectId(org.locationtech.geogig.api.ObjectId) ArrayList(java.util.ArrayList) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Aggregations

Conflict (org.locationtech.geogig.api.plumbing.merge.Conflict)36 Ref (org.locationtech.geogig.api.Ref)17 RevCommit (org.locationtech.geogig.api.RevCommit)17 Test (org.junit.Test)16 NodeRef (org.locationtech.geogig.api.NodeRef)14 ObjectId (org.locationtech.geogig.api.ObjectId)14 ConflictsReadOp (org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp)12 Feature (org.opengis.feature.Feature)12 RefParse (org.locationtech.geogig.api.plumbing.RefParse)11 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)10 SymRef (org.locationtech.geogig.api.SymRef)8 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)8 AddOp (org.locationtech.geogig.api.porcelain.AddOp)8 CanRunDuringConflict (org.locationtech.geogig.di.CanRunDuringConflict)8 MergeConflictsException (org.locationtech.geogig.api.porcelain.MergeConflictsException)7 File (java.io.File)6 IOException (java.io.IOException)6 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)6 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)6 Repository (org.locationtech.geogig.repository.Repository)6