Search in sources :

Example 1 with PushOp

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

the class SparseCloneTest method testPushSparseMerge.

@Test
public void testPushSparseMerge() throws Exception {
    setupSparseClone();
    // create a branch off an early commit
    Iterator<RevCommit> logs = localGeogig.geogig.command(LogOp.class).call();
    RevCommit initialCommit = logs.next();
    ObjectId masterCommit = initialCommit.getId();
    while (logs.hasNext()) {
        initialCommit = logs.next();
    }
    localGeogig.geogig.command(BranchCreateOp.class).setName("Branch1").setAutoCheckout(true).setSource(initialCommit.getId().toString()).call();
    // Add some commits to the local (sparse) repository
    List<Feature> features = Arrays.asList(city1, city1_modified, road3);
    LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
    Map<Feature, ObjectId> oids = new HashMap<Feature, ObjectId>();
    for (Feature f : features) {
        ObjectId oId = insertAndAdd(localGeogig.geogig, f);
        oids.put(f, oId);
        final RevCommit commit = localGeogig.geogig.command(CommitOp.class).setMessage(f.getIdentifier().toString()).call();
        expected.addFirst(commit);
        Optional<RevObject> childObject = localGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
        assertTrue(childObject.isPresent());
    }
    // Merge master into Branch1
    MergeOp merge = localGeogig.geogig.command(MergeOp.class);
    MergeReport report = merge.addCommit(Suppliers.ofInstance(masterCommit)).setMessage("Merge").call();
    // Update master to the new merge commit
    localGeogig.geogig.command(UpdateRef.class).setName("refs/heads/master").setNewValue(report.getMergeCommit().getId()).call();
    // Checkout master
    localGeogig.geogig.command(CheckoutOp.class).setSource("master").call();
    PushOp push = push();
    push.addRefSpec("refs/heads/master").call();
    logs = remoteGeogig.geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals("Merge", logged.get(0).getMessage());
    assertFalse(report.getMergeCommit().getId().equals(logged.get(0).getId()));
    // Although we merged "Roads.2" commit into the "Roads.3" commit, making the "Roads.2"
    // commit the second parent, they should have been swapped when pushing to the full
    // repository to prevent any sparse data from being lost.
    ObjectId parent1Id = logged.get(0).getParentIds().get(0);
    ObjectId parent2Id = logged.get(0).getParentIds().get(1);
    RevCommit parent1 = remoteGeogig.geogig.getRepository().getCommit(parent1Id);
    assertNotNull(parent1);
    assertEquals("Roads.2", parent1.getMessage());
    RevCommit parent2 = remoteGeogig.geogig.getRepository().getCommit(parent2Id);
    assertNotNull(parent2);
    assertEquals("Roads.3", parent2.getMessage());
    // Verify they weren't swapped in the original
    parent1Id = report.getMergeCommit().getParentIds().get(0);
    parent2Id = report.getMergeCommit().getParentIds().get(1);
    parent1 = localGeogig.geogig.getRepository().getCommit(parent1Id);
    assertNotNull(parent1);
    assertEquals("Roads.3", parent1.getMessage());
    parent2 = localGeogig.geogig.getRepository().getCommit(parent2Id);
    assertNotNull(parent2);
    assertEquals("Roads.2", parent2.getMessage());
    assertExists(remoteGeogig, oids.get(city1), oids.get(city1_modified), oids.get(road3));
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) HashMap(java.util.HashMap) RevObject(org.locationtech.geogig.api.RevObject) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) MergeOp(org.locationtech.geogig.api.porcelain.MergeOp) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) Feature(org.opengis.feature.Feature) LinkedList(java.util.LinkedList) MergeReport(org.locationtech.geogig.api.porcelain.MergeOp.MergeReport) PushOp(org.locationtech.geogig.api.porcelain.PushOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 2 with PushOp

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

the class RemoteRepositoryTestCase method push.

protected PushOp push() {
    SendPack sendPack = spy(localGeogig.geogig.command(SendPack.class));
    doReturn(Optional.of(remoteRepo)).when(sendPack).getRemoteRepo(any(Remote.class));
    PushOp push = spy(localGeogig.geogig.command(PushOp.class));
    doReturn(sendPack).when(push).command(eq(SendPack.class));
    FetchOp fetch = fetch();
    // when(push.command(FetchOp.class)).thenReturn(fetch);
    doReturn(fetch).when(push).command(eq(FetchOp.class));
    LsRemote lsRemote = lsremote();
    // when(push.command(LsRemote.class)).thenReturn(lsRemote);
    doReturn(lsRemote).when(push).command(eq(LsRemote.class));
    return push;
}
Also used : PushOp(org.locationtech.geogig.api.porcelain.PushOp) SendPack(org.locationtech.geogig.api.plumbing.SendPack) FetchOp(org.locationtech.geogig.api.porcelain.FetchOp) LsRemote(org.locationtech.geogig.api.plumbing.LsRemote) Remote(org.locationtech.geogig.api.Remote) LsRemote(org.locationtech.geogig.api.plumbing.LsRemote)

Example 3 with PushOp

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

the class PushOpTest method testPushAll.

@Test
public void testPushAll() throws Exception {
    // Add a commit to the local repository
    insertAndAdd(localGeogig.geogig, lines3);
    RevCommit commit = localGeogig.geogig.command(CommitOp.class).call();
    expectedMaster.addFirst(commit);
    localGeogig.geogig.command(CheckoutOp.class).setSource("Branch1").call();
    insertAndAdd(localGeogig.geogig, points1_modified);
    RevCommit commit2 = localGeogig.geogig.command(CommitOp.class).call();
    expectedBranch.addFirst(commit2);
    // Push the commit
    PushOp push = push();
    push.setAll(true).call();
    // verify that the remote got the commit on both branches
    remoteGeogig.geogig.command(CheckoutOp.class).setSource("master").call();
    Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expectedMaster, logged);
    remoteGeogig.geogig.command(CheckoutOp.class).setSource("Branch1").call();
    logs = remoteGeogig.geogig.command(LogOp.class).call();
    logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expectedBranch, logged);
}
Also used : PushOp(org.locationtech.geogig.api.porcelain.PushOp) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 4 with PushOp

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

the class PushOpTest method testPushToRemoteHEAD.

@Test
public void testPushToRemoteHEAD() throws Exception {
    insertAndAdd(localGeogig.geogig, lines3);
    localGeogig.geogig.command(CommitOp.class).call();
    PushOp push = push();
    try {
        push.setRemote("origin").addRefSpec("HEAD").call();
        fail();
    } catch (SynchronizationException e) {
        assertEquals(SynchronizationException.StatusCode.CANNOT_PUSH_TO_SYMBOLIC_REF, e.statusCode);
    }
}
Also used : PushOp(org.locationtech.geogig.api.porcelain.PushOp) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException) Test(org.junit.Test)

Example 5 with PushOp

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

the class Push method runInternal.

/**
     * Executes the push command using the provided options.
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    PushOp push = cli.getGeogig().command(PushOp.class);
    push.setProgressListener(cli.getProgressListener());
    push.setAll(all);
    if (args != null) {
        if (args.size() > 0) {
            push.setRemote(args.get(0));
        }
        for (int i = 1; i < args.size(); i++) {
            push.addRefSpec(args.get(i));
        }
    }
    try {
        // TODO: listen on progress?
        TransferSummary dataPushed = push.call();
        if (dataPushed.isEmpty()) {
            cli.getConsole().println("Nothing to push.");
        }
    } catch (SynchronizationException e) {
        switch(e.statusCode) {
            case REMOTE_HAS_CHANGES:
                throw new CommandFailedException("Push failed: The remote repository has changes that would be lost in the event of a push.", e);
            case HISTORY_TOO_SHALLOW:
                throw new CommandFailedException("Push failed: There is not enough local history to complete the push.", e);
            case CANNOT_PUSH_TO_SYMBOLIC_REF:
                throw new CommandFailedException("Push failed: Cannot push to a symbolic reference", e);
            default:
                break;
        }
    }
}
Also used : PushOp(org.locationtech.geogig.api.porcelain.PushOp) TransferSummary(org.locationtech.geogig.api.porcelain.TransferSummary) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException)

Aggregations

PushOp (org.locationtech.geogig.api.porcelain.PushOp)17 Test (org.junit.Test)14 RevCommit (org.locationtech.geogig.api.RevCommit)12 ArrayList (java.util.ArrayList)11 LogOp (org.locationtech.geogig.api.porcelain.LogOp)11 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)10 Ref (org.locationtech.geogig.api.Ref)4 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 ObjectId (org.locationtech.geogig.api.ObjectId)3 RevObject (org.locationtech.geogig.api.RevObject)3 SynchronizationException (org.locationtech.geogig.api.porcelain.SynchronizationException)3 Feature (org.opengis.feature.Feature)3 MergeOp (org.locationtech.geogig.api.porcelain.MergeOp)2 MergeReport (org.locationtech.geogig.api.porcelain.MergeOp.MergeReport)2 TransferSummary (org.locationtech.geogig.api.porcelain.TransferSummary)2 Context (org.locationtech.geogig.api.Context)1 Remote (org.locationtech.geogig.api.Remote)1 LsRemote (org.locationtech.geogig.api.plumbing.LsRemote)1 SendPack (org.locationtech.geogig.api.plumbing.SendPack)1