Package org.locationtech.geogig.api

Examples of org.locationtech.geogig.api.GeogigTransaction


        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);
    }
View Full Code Here


        // make a commit
        insertAndAdd(points1);
        RevCommit mainCommit = geogig.command(CommitOp.class).setMessage("Commit1").call();

        // start the first transaction
        GeogigTransaction transaction1 = geogig.command(TransactionBegin.class).call();

        // make a new branch
        transaction1.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();

        // perform a commit in the transaction
        insertAndAdd(transaction1, points2);
        RevCommit transaction1Commit = transaction1.command(CommitOp.class).setMessage("Commit2")
                .call();

        // Verify that the base repository is unchanged
        Iterator<RevCommit> logs = geogig.command(LogOp.class).call();
        assertEquals(logs.next(), mainCommit);
        assertFalse(logs.hasNext());

        // Verify that the transaction has the commit
        logs = transaction1.command(LogOp.class).call();
        assertEquals(logs.next(), transaction1Commit);
        assertEquals(logs.next(), mainCommit);
        assertFalse(logs.hasNext());

        // start the second transaction
        GeogigTransaction transaction2 = geogig.command(TransactionBegin.class).call();

        // make a new branch
        transaction2.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();

        // perform a commit in the transaction
        insertAndAdd(transaction2, points3);
        RevCommit transaction2Commit = transaction2.command(CommitOp.class).setMessage("Commit3")
                .call();

        // Verify that the base repository is unchanged
        logs = geogig.command(LogOp.class).call();
        assertEquals(logs.next(), mainCommit);
        assertFalse(logs.hasNext());

        // Verify that the transaction has the commit
        logs = transaction2.command(LogOp.class).call();
        assertEquals(logs.next(), transaction2Commit);
        assertEquals(logs.next(), mainCommit);
        assertFalse(logs.hasNext());

        // Commit the first transaction
View Full Code Here

        insertAndAdd(points1);
        RevCommit commit = geogig.command(CommitOp.class).call();
        expectedMain.addFirst(commit);

        // start a transaction
        GeogigTransaction t = geogig.command(TransactionBegin.class).call();

        // perform a commit in the transaction
        insertAndAdd(t, points2);
        commit = t.command(CommitOp.class).call();

        // Verify that the base repository is unchanged
        Iterator<RevCommit> logs = geogig.command(LogOp.class).call();
        List<RevCommit> logged = new ArrayList<RevCommit>();
        for (; logs.hasNext();) {
View Full Code Here

        // make a commit
        insertAndAdd(points1);
        geogig.command(CommitOp.class).call();

        // start a transaction
        GeogigTransaction t = geogig.command(TransactionBegin.class).call();

        // perform a commit in the transaction
        insertAndAdd(t, points2);
        t.command(CommitOp.class).call();

        // End the transaction
        exception.expect(IllegalStateException.class);
        t.command(TransactionEnd.class).setTransaction(t).call();

    }
View Full Code Here

        // make a commit
        insertAndAdd(points1);
        geogig.command(CommitOp.class).call();

        // start a transaction
        GeogigTransaction t = geogig.command(TransactionBegin.class).call();

        // start a transaction within the transaction
        exception.expect(IllegalStateException.class);
        t.command(TransactionBegin.class).call();

    }
View Full Code Here

        geogig.command(UpdateRef.class).setName(unchangedRemoteRef).setNewValue(headCommit.getId())
                .call().get();

        // start a transaction
        GeogigTransaction tx = geogig.command(TransactionBegin.class).call();

        // make a commit
        insertAndAdd(tx, points2);
        RevCommit newcommit = tx.command(CommitOp.class).call();
        // upadte remote
        Ref txRemoteHead = tx.command(UpdateRef.class).setName(remoteRef)
                .setNewValue(newcommit.getId()).call().get();
        assertEquals(newcommit.getId(), txRemoteHead.getObjectId());

        // commit transaction
        tx.commit();
        txRemoteHead = geogig.command(RefParse.class).setName(remoteRef).call().get();
        assertEquals(newcommit.getId(), txRemoteHead.getObjectId());

        txRemoteHead = geogig.command(RefParse.class).setName(unchangedRemoteRef).call().get();
        assertEquals(headCommit.getId(), txRemoteHead.getObjectId());
View Full Code Here

        if (this.getTransactionId() != null) {
            throw new CommandSpecException("Tried to start a transaction within a transaction.");
        }
        final GeoGIG geogig = context.getGeoGIG();

        final GeogigTransaction transaction = geogig.command(TransactionBegin.class).call();

        context.setResponseContent(new CommandResponse() {

            @Override
            public void write(ResponseWriter out) throws Exception {
                out.start();
                out.writeTransactionId(transaction.getTransactionId());
                out.finish();
            }
        });
    }
View Full Code Here

        if (!incomingIPs.remove(ipAddress)) {// remove and check for existence in one shot
            throw new RuntimeException("Tried to end a connection that didn't exist.");
        }

        // Do not use the geogig instance after this, but the tx one!
        GeogigTransaction tx = geogig.command(TransactionBegin.class).call();
        try {
            Optional<Ref> oldRef = tx.command(RefParse.class).setName(refspec).call();
            Optional<Ref> headRef = tx.command(RefParse.class).setName(Ref.HEAD).call();
            String refName = refspec;
            if (oldRef.isPresent()) {
                if (oldRef.get().getObjectId().equals(newCommit)) {
                    LOGGER.info("ref '{}' -> {} not updated, got same id", refName, newCommit);
                    return;
                }
                LOGGER.info("Updating ref '{}'[{}] -> {}", refName, oldRef.get().getObjectId(),
                        newCommit);
                refName = oldRef.get().getName();
            } else {
                LOGGER.info("Creating new ref '{}' -> {}", refName, newCommit);
            }
            if (headRef.isPresent() && headRef.get() instanceof SymRef) {
                if (((SymRef) headRef.get()).getTarget().equals(refName)) {
                    Optional<ObjectId> commitTreeId = tx.command(ResolveTreeish.class)
                            .setTreeish(newCommit).call();
                    checkState(commitTreeId.isPresent(), "Commit %s not found", newCommit);

                    tx.command(UpdateRef.class).setName(Ref.WORK_HEAD)
                            .setNewValue(commitTreeId.get()).call();
                    tx.command(UpdateRef.class).setName(Ref.STAGE_HEAD)
                            .setNewValue(commitTreeId.get()).call();
                }
            }
            tx.command(UpdateRef.class).setName(refName).setNewValue(newCommit).call();

            tx.commit();
        } catch (Exception e) {
            tx.abort();
            throw Throwables.propagate(e);
        }
    }
View Full Code Here

                    "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();
View Full Code Here

TOP

Related Classes of org.locationtech.geogig.api.GeogigTransaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.