Search in sources :

Example 16 with MergeReport

use of org.locationtech.geogig.api.porcelain.MergeOp.MergeReport in project GeoGig by boundlessgeo.

the class SquashOpTest method testSquashInMergedBranch.

@Test
public void testSquashInMergedBranch() throws Exception {
    // Try to squash the commits marked (*) in this history
    // o
    // |
    // o - Points 1 added
    // |\
    // | o - branch1 - Points 2 added*
    // | |
    // | o - Points 3 added*
    // | |
    // o | - Lines 1 added
    // |/
    // o - master - HEAD - Merge commit*
    insertAndAdd(points1);
    @SuppressWarnings("unused") final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
    insertAndAdd(points2);
    final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
    insertAndAdd(points3);
    @SuppressWarnings("unused") final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
    geogig.command(CheckoutOp.class).setSource("master").call();
    insertAndAdd(lines1);
    @SuppressWarnings("unused") final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
    Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
    MergeReport mergeReport = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getObjectId())).setMessage("My merge message.").call();
    try {
        geogig.command(SquashOp.class).setSince(c2).setUntil(mergeReport.getMergeCommit()).setMessage("Squashed").call();
    } catch (IllegalArgumentException e) {
        assertTrue(e.getMessage().equals("Cannot reach 'since' from 'until' commit through first parentage"));
    }
}
Also used : MergeReport(org.locationtech.geogig.api.porcelain.MergeOp.MergeReport) Ref(org.locationtech.geogig.api.Ref) BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) RefParse(org.locationtech.geogig.api.plumbing.RefParse) MergeOp(org.locationtech.geogig.api.porcelain.MergeOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 17 with MergeReport

use of org.locationtech.geogig.api.porcelain.MergeOp.MergeReport in project GeoGig by boundlessgeo.

the class MergeOpTest method testMergeFastForwardSecondCase.

@Test
public void testMergeFastForwardSecondCase() throws Exception {
    // Create the following revision graph
    // o - master - HEAD
    // .\
    // . o - branch1 - Points 1 added
    // create branch1 and checkout
    geogig.command(UpdateRef.class).setName(Ref.HEADS_PREFIX + "branch1").setNewValue(ObjectId.NULL).call();
    geogig.command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(Ref.HEADS_PREFIX + "branch1").call();
    insertAndAdd(points1);
    final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    // checkout master
    geogig.command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(Ref.HEADS_PREFIX + "master").call();
    // Merge branch1 into master to create the following revision graph
    // o
    // |
    // o - master - HEAD - branch1 - Points 1 added
    Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
    final MergeReport mergeReport = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getObjectId())).call();
    RevTree mergedTree = repo.getTree(mergeReport.getMergeCommit().getTreeId());
    String path = appendChild(pointsName, points1.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    Iterator<RevCommit> log = geogig.command(LogOp.class).call();
    // Commit 1
    RevCommit logC1 = log.next();
    assertEquals(c1.getAuthor(), logC1.getAuthor());
    assertEquals(c1.getCommitter(), logC1.getCommitter());
    assertEquals(c1.getMessage(), logC1.getMessage());
    assertEquals(c1.getTreeId(), logC1.getTreeId());
}
Also used : MergeReport(org.locationtech.geogig.api.porcelain.MergeOp.MergeReport) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) LogOp(org.locationtech.geogig.api.porcelain.LogOp) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) RefParse(org.locationtech.geogig.api.plumbing.RefParse) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 18 with MergeReport

use of org.locationtech.geogig.api.porcelain.MergeOp.MergeReport in project GeoGig by boundlessgeo.

the class MergeOpTest method testMergeNoCommitMessage.

@Test
public void testMergeNoCommitMessage() throws Exception {
    // Create the following revision graph
    // o
    // |
    // o - Points 1 added
    // |\
    // | o - branch1 - Points 2 added
    // |
    // o - Points 3 added
    // |
    // o - master - HEAD - Lines 1 added
    insertAndAdd(points1);
    final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    // create branch1 and checkout
    geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
    insertAndAdd(points2);
    final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
    // checkout master
    geogig.command(CheckoutOp.class).setSource("master").call();
    insertAndAdd(points3);
    final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
    insertAndAdd(lines1);
    final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
    // Merge branch1 into master to create the following revision graph
    // o
    // |
    // o - Points 1 added
    // |\
    // | o - branch1 - Points 2 added
    // | |
    // o | - Points 3 added
    // | |
    // o | - Lines 1 added
    // |/
    // o - master - HEAD - Merge commit
    Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
    final MergeReport mergeReport = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getObjectId())).call();
    RevTree mergedTree = repo.getTree(mergeReport.getMergeCommit().getTreeId());
    String path = appendChild(pointsName, points2.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    path = appendChild(pointsName, points1.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    path = appendChild(pointsName, points3.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    path = appendChild(linesName, lines1.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    Iterator<RevCommit> log = geogig.command(LogOp.class).setFirstParentOnly(true).call();
    // Commit 4
    RevCommit logC4 = log.next();
    assertTrue(logC4.getMessage().contains("refs/heads/branch1"));
    assertEquals(2, logC4.getParentIds().size());
    assertEquals(c4.getId(), logC4.getParentIds().get(0));
    assertEquals(c2.getId(), logC4.getParentIds().get(1));
    // Commit 3
    RevCommit logC3 = log.next();
    assertEquals(c4.getAuthor(), logC3.getAuthor());
    assertEquals(c4.getCommitter(), logC3.getCommitter());
    assertEquals(c4.getMessage(), logC3.getMessage());
    assertEquals(c4.getTreeId(), logC3.getTreeId());
    // Commit 2
    RevCommit logC2 = log.next();
    assertEquals(c3.getAuthor(), logC2.getAuthor());
    assertEquals(c3.getCommitter(), logC2.getCommitter());
    assertEquals(c3.getMessage(), logC2.getMessage());
    assertEquals(c3.getTreeId(), logC2.getTreeId());
    // Commit 1
    RevCommit logC1 = log.next();
    assertEquals(c1.getAuthor(), logC1.getAuthor());
    assertEquals(c1.getCommitter(), logC1.getCommitter());
    assertEquals(c1.getMessage(), logC1.getMessage());
    assertEquals(c1.getTreeId(), logC1.getTreeId());
}
Also used : MergeReport(org.locationtech.geogig.api.porcelain.MergeOp.MergeReport) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) RefParse(org.locationtech.geogig.api.plumbing.RefParse) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 19 with MergeReport

use of org.locationtech.geogig.api.porcelain.MergeOp.MergeReport 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();
            }
        });
    }
}
Also used : GeogigTransaction(org.locationtech.geogig.api.GeogigTransaction) Optional(com.google.common.base.Optional) ObjectId(org.locationtech.geogig.api.ObjectId) MergeOp(org.locationtech.geogig.api.porcelain.MergeOp) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) MergeScenarioReport(org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) MergeReport(org.locationtech.geogig.api.porcelain.MergeOp.MergeReport) Ref(org.locationtech.geogig.api.Ref) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 20 with MergeReport

use of org.locationtech.geogig.api.porcelain.MergeOp.MergeReport in project GeoGig by boundlessgeo.

the class ResponseWriter method writePullResponse.

public void writePullResponse(PullResult result, Iterator<DiffEntry> iter, Context geogig) throws XMLStreamException {
    out.writeStartElement("Pull");
    writeFetchResponse(result.getFetchResult());
    if (iter != null) {
        writeElement("Remote", result.getRemoteName());
        writeElement("Ref", result.getNewRef().localName());
        int added = 0;
        int removed = 0;
        int modified = 0;
        while (iter.hasNext()) {
            DiffEntry entry = iter.next();
            if (entry.changeType() == ChangeType.ADDED) {
                added++;
            } else if (entry.changeType() == ChangeType.MODIFIED) {
                modified++;
            } else if (entry.changeType() == ChangeType.REMOVED) {
                removed++;
            }
        }
        writeElement("Added", Integer.toString(added));
        writeElement("Modified", Integer.toString(modified));
        writeElement("Removed", Integer.toString(removed));
    }
    if (result.getMergeReport().isPresent() && result.getMergeReport().get().getReport().isPresent()) {
        MergeReport report = result.getMergeReport().get();
        writeMergeResponse(Optional.fromNullable(report.getMergeCommit()), report.getReport().get(), geogig, report.getOurs(), report.getPairs().get(0).getTheirs(), report.getPairs().get(0).getAncestor());
    }
    out.writeEndElement();
}
Also used : MergeReport(org.locationtech.geogig.api.porcelain.MergeOp.MergeReport) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Aggregations

MergeReport (org.locationtech.geogig.api.porcelain.MergeOp.MergeReport)21 RevCommit (org.locationtech.geogig.api.RevCommit)19 Test (org.junit.Test)16 Ref (org.locationtech.geogig.api.Ref)14 BranchCreateOp (org.locationtech.geogig.api.porcelain.BranchCreateOp)13 MergeOp (org.locationtech.geogig.api.porcelain.MergeOp)13 RefParse (org.locationtech.geogig.api.plumbing.RefParse)11 ObjectId (org.locationtech.geogig.api.ObjectId)9 LogOp (org.locationtech.geogig.api.porcelain.LogOp)9 NodeRef (org.locationtech.geogig.api.NodeRef)8 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)7 RevTree (org.locationtech.geogig.api.RevTree)6 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)6 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)5 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 FindCommonAncestor (org.locationtech.geogig.api.plumbing.FindCommonAncestor)3 Optional (com.google.common.base.Optional)2 HashMap (java.util.HashMap)2 RevObject (org.locationtech.geogig.api.RevObject)2