Search in sources :

Example 1 with Conflict

use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.

the class RevertOpTest method testRevertModifiedFeatureConflictSolveAndContinue.

@Test
public void testRevertModifiedFeatureConflictSolveAndContinue() throws Exception {
    ObjectId oId1 = insertAndAdd(points1);
    RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    insertAndAdd(points1_modified);
    RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1).call();
    Feature points1_modifiedB = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
    insertAndAdd(points1_modifiedB);
    RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1 + " again").call();
    try {
        geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(c2.getId())).call();
        fail();
    } catch (RevertConflictsException e) {
        assertTrue(e.getMessage().contains(idP1));
    }
    Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
    assertTrue(ref.isPresent());
    assertEquals(c3.getId(), ref.get().getObjectId());
    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(points1_modifiedB).getId());
    assertEquals(conflicts.get(0).getTheirs(), RevFeatureBuilder.build(points1).getId());
    // solve, and continue
    insert(points1);
    geogig.command(AddOp.class).call();
    geogig.command(RevertOp.class).setContinue(true).call();
    Iterator<RevCommit> log = geogig.command(LogOp.class).call();
    RevCommit logCommit = log.next();
    assertEquals(c2.getAuthor().getName(), logCommit.getAuthor().getName());
    assertEquals(c2.getCommitter().getName(), logCommit.getCommitter().getName());
    assertEquals("Revert '" + c2.getMessage() + "'\nThis reverts " + c2.getId().toString(), logCommit.getMessage());
    assertNotSame(c2.getCommitter().getTimestamp(), logCommit.getCommitter().getTimestamp());
    assertNotSame(c2.getTreeId(), logCommit.getTreeId());
    final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD).call();
    final Optional<ObjectId> headTreeId = geogig.command(ResolveTreeish.class).setTreeish(currHead.get().getObjectId()).call();
    RevTree headTree = repo.getTree(headTreeId.get());
    Optional<NodeRef> points1Node = geogig.command(FindTreeChild.class).setChildPath(NodeRef.appendChild(pointsName, idP1)).setParent(headTree).call();
    assertTrue(points1Node.isPresent());
    assertEquals(oId1, points1Node.get().getNode().getObjectId());
    assertEquals(c3.getId(), log.next().getId());
    assertEquals(c2.getId(), log.next().getId());
    assertEquals(c1.getId(), log.next().getId());
    assertFalse(log.hasNext());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) ObjectId(org.locationtech.geogig.api.ObjectId) LogOp(org.locationtech.geogig.api.porcelain.LogOp) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) Feature(org.opengis.feature.Feature) NodeRef(org.locationtech.geogig.api.NodeRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) RevertConflictsException(org.locationtech.geogig.api.porcelain.RevertConflictsException) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 2 with Conflict

use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.

the class RemoveOp method _call.

/**
     * @see java.util.concurrent.Callable#call()
     */
protected WorkingTree _call() {
    // Check that all paths are valid and exist
    for (String pathToRemove : pathsToRemove) {
        NodeRef.checkValidPath(pathToRemove);
        Optional<NodeRef> node;
        node = command(FindTreeChild.class).setParent(workingTree().getTree()).setIndex(true).setChildPath(pathToRemove).call();
        List<Conflict> conflicts = index().getConflicted(pathToRemove);
        if (conflicts.size() > 0) {
            for (Conflict conflict : conflicts) {
                stagingDatabase().removeConflict(null, conflict.getPath());
            }
        } else {
            Preconditions.checkArgument(node.isPresent(), "pathspec '%s' did not match any feature or tree", pathToRemove);
        }
    }
    // separate trees from features an delete accordingly
    for (String pathToRemove : pathsToRemove) {
        Optional<NodeRef> node = command(FindTreeChild.class).setParent(workingTree().getTree()).setIndex(true).setChildPath(pathToRemove).call();
        if (!node.isPresent()) {
            continue;
        }
        switch(node.get().getType()) {
            case TREE:
                workingTree().delete(pathToRemove);
                break;
            case FEATURE:
                String parentPath = NodeRef.parentPath(pathToRemove);
                String name = node.get().name();
                workingTree().delete(parentPath, name);
                break;
            default:
                break;
        }
        final long numChanges = workingTree().countUnstaged(pathToRemove).count();
        Iterator<DiffEntry> unstaged = workingTree().getUnstaged(pathToRemove);
        index().stage(getProgressListener(), unstaged, numChanges);
    }
    return workingTree();
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) CanRunDuringConflict(org.locationtech.geogig.di.CanRunDuringConflict) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 3 with Conflict

use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.

the class RevertOp method applyNextCommit.

private boolean applyNextCommit(boolean useCommitChanges) {
    File rebaseFolder = getRevertFolder();
    File nextFile = new File(rebaseFolder, "next");
    Repository repository = repository();
    try {
        String idx = Files.readFirstLine(nextFile, Charsets.UTF_8);
        File commitFile = new File(rebaseFolder, idx);
        if (commitFile.exists()) {
            String commitId = Files.readFirstLine(commitFile, Charsets.UTF_8);
            RevCommit commit = repository.getCommit(ObjectId.valueOf(commitId));
            List<Conflict> conflicts = Lists.newArrayList();
            if (useCommitChanges) {
                conflicts = applyRevertedChanges(commit);
            }
            if (createCommit && conflicts.isEmpty()) {
                createCommit(commit);
            } else {
                workingTree().updateWorkHead(repository.index().getTree().getId());
                if (!conflicts.isEmpty()) {
                    // mark conflicted elements
                    command(ConflictsWriteOp.class).setConflicts(conflicts).call();
                    // created exception message
                    StringBuilder msg = new StringBuilder();
                    msg.append("error: could not apply ");
                    msg.append(commit.getId().toString().substring(0, 7));
                    msg.append(" " + commit.getMessage() + "\n");
                    for (Conflict conflict : conflicts) {
                        msg.append("CONFLICT: conflict in " + conflict.getPath() + "\n");
                    }
                    throw new RevertConflictsException(msg.toString());
                }
            }
            commitFile.delete();
            int newIdx = Integer.parseInt(idx) + 1;
            Files.write(Integer.toString(newIdx), nextFile, Charsets.UTF_8);
            return true;
        } else {
            return false;
        }
    } catch (IOException e) {
        throw new IllegalStateException("Cannot read/write revert commits index file");
    }
}
Also used : Repository(org.locationtech.geogig.repository.Repository) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) CanRunDuringConflict(org.locationtech.geogig.di.CanRunDuringConflict) IOException(java.io.IOException) File(java.io.File) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 4 with Conflict

use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.

the class ResponseWriter method writeUnmerged.

public void writeUnmerged(List<Conflict> conflicts, int start, int length) throws XMLStreamException {
    Iterator<Conflict> entries = conflicts.iterator();
    Iterators.advance(entries, start);
    if (length < 0) {
        length = Integer.MAX_VALUE;
    }
    for (int i = 0; i < length && entries.hasNext(); i++) {
        Conflict entry = entries.next();
        out.writeStartElement("unmerged");
        writeElement("changeType", "CONFLICT");
        writeElement("path", entry.getPath());
        writeElement("ours", entry.getOurs().toString());
        writeElement("theirs", entry.getTheirs().toString());
        writeElement("ancestor", entry.getAncestor().toString());
        out.writeEndElement();
    }
}
Also used : Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict)

Example 5 with Conflict

use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.

the class Add method runInternal.

/**
     * Executes the add command using the provided options.
     * 
     * @param cli
     * @see org.locationtech.geogig.cli.AbstractCommand#runInternal(org.locationtech.geogig.cli.GeogigCLI)
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    final GeoGIG geogig = cli.getGeogig();
    final ConsoleReader console = cli.getConsole();
    String pathFilter = null;
    if (patterns.size() == 1) {
        pathFilter = patterns.get(0);
    } else if (patterns.size() > 1) {
        throw new InvalidParameterException("Only a single path is supported so far");
    }
    List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
    console.print("Counting unstaged elements...");
    console.flush();
    DiffObjectCount unstaged = geogig.getRepository().workingTree().countUnstaged(pathFilter);
    if (0 == unstaged.count() && conflicts.isEmpty()) {
        console.println();
        console.println("No unstaged elements, exiting.");
        return;
    } else {
        console.println(String.valueOf(unstaged.count()));
    }
    console.println("Staging changes...");
    AddOp op = geogig.command(AddOp.class);
    if (patterns.size() == 1) {
        op.addPattern(patterns.get(0));
    }
    WorkingTree workTree = op.setUpdateOnly(updateOnly).setProgressListener(cli.getProgressListener()).call();
    DiffObjectCount staged = geogig.getRepository().index().countStaged(null);
    unstaged = workTree.countUnstaged(null);
    console.println(staged.featureCount() + " features and " + staged.treeCount() + " trees staged for commit");
    console.println(unstaged.featureCount() + " features and " + unstaged.treeCount() + " trees not staged for commit");
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) WorkingTree(org.locationtech.geogig.repository.WorkingTree) DiffObjectCount(org.locationtech.geogig.api.plumbing.diff.DiffObjectCount) ConsoleReader(jline.console.ConsoleReader) ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) GeoGIG(org.locationtech.geogig.api.GeoGIG)

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