Search in sources :

Example 51 with RevCommit

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

the class LocalRemoteRepo method pushNewData.

/**
     * Push all new objects from the specified {@link Ref} to the given refspec.
     * 
     * @param ref the local ref that points to new commit data
     * @param refspec the refspec to push to
     */
@Override
public void pushNewData(final Ref ref, final String refspec, final ProgressListener progress) throws SynchronizationException {
    Optional<Ref> remoteRef = remoteGeoGig.command(RefParse.class).setName(refspec).call();
    remoteRef = remoteRef.or(remoteGeoGig.command(RefParse.class).setName(Ref.TAGS_PREFIX + refspec).call());
    checkPush(ref, remoteRef);
    CommitTraverser traverser = getPushTraverser(remoteRef);
    traverser.traverse(ref.getObjectId());
    progress.setDescription("Uploading objects to " + refspec);
    progress.setProgress(0);
    while (!traverser.commits.isEmpty()) {
        ObjectId commitId = traverser.commits.pop();
        walkHead(commitId, false, progress);
    }
    String nameToSet = remoteRef.isPresent() ? remoteRef.get().getName() : Ref.HEADS_PREFIX + refspec;
    Ref updatedRef = remoteGeoGig.command(UpdateRef.class).setName(nameToSet).setNewValue(ref.getObjectId()).call().get();
    Ref remoteHead = headRef();
    if (remoteHead instanceof SymRef) {
        if (((SymRef) remoteHead).getTarget().equals(updatedRef.getName())) {
            remoteGeoGig.command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(ref.getName()).call();
            RevCommit commit = remoteGeoGig.getRepository().getCommit(ref.getObjectId());
            remoteGeoGig.getRepository().workingTree().updateWorkHead(commit.getTreeId());
            remoteGeoGig.getRepository().index().updateStageHead(commit.getTreeId());
        }
    }
}
Also used : UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) ForEachRef(org.locationtech.geogig.api.plumbing.ForEachRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) SymRef(org.locationtech.geogig.api.SymRef) ObjectId(org.locationtech.geogig.api.ObjectId) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 52 with RevCommit

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

the class LocalMappedRemoteRepo method updateRemoteRef.

/**
     * Updates the remote ref that matches the given refspec.
     * 
     * @param refspec the ref to update
     * @param commitId the new value of the ref
     * @param delete if true, the remote ref will be deleted
     * @return the updated ref
     */
@Override
protected Optional<Ref> updateRemoteRef(String refspec, ObjectId commitId, boolean delete) {
    Optional<Ref> updatedRef = remoteGeoGig.command(UpdateRef.class).setName(refspec).setNewValue(commitId).setDelete(delete).call();
    if (updatedRef.isPresent()) {
        final Ref remoteHead = headRef();
        if (remoteHead instanceof SymRef) {
            if (((SymRef) remoteHead).getTarget().equals(updatedRef.get().getName())) {
                remoteGeoGig.command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(updatedRef.get().getName()).call();
                RevCommit commit = remoteGeoGig.getRepository().getCommit(commitId);
                remoteGeoGig.getRepository().workingTree().updateWorkHead(commit.getTreeId());
                remoteGeoGig.getRepository().index().updateStageHead(commit.getTreeId());
            }
        }
    }
    return updatedRef;
}
Also used : UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) ForEachRef(org.locationtech.geogig.api.plumbing.ForEachRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) SymRef(org.locationtech.geogig.api.SymRef) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 53 with RevCommit

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

the class LogOpTest method testSinceUntil.

@Test
public void testSinceUntil() throws Exception {
    final ObjectId oid1_1 = insertAndAdd(points1);
    final RevCommit commit1_1 = geogig.command(CommitOp.class).call();
    insertAndAdd(points2);
    final RevCommit commit1_2 = geogig.command(CommitOp.class).call();
    insertAndAdd(lines1);
    final RevCommit commit2_1 = geogig.command(CommitOp.class).call();
    final ObjectId oid2_2 = insertAndAdd(lines2);
    final RevCommit commit2_2 = geogig.command(CommitOp.class).call();
    try {
        logOp = geogig.command(LogOp.class);
        logOp.setSince(oid1_1).call();
        fail("Expected ISE as since is not a commit");
    } catch (IllegalArgumentException e) {
        assertTrue(e.getMessage().contains("since"));
    }
    try {
        logOp = geogig.command(LogOp.class);
        logOp.setSince(null).setUntil(oid2_2).call();
        fail("Expected ISE as until is not a commit");
    } catch (IllegalArgumentException e) {
        assertTrue(e.getMessage().contains("until"));
    }
    List<RevCommit> logs;
    List<RevCommit> expected;
    logOp = geogig.command(LogOp.class);
    logs = toList(logOp.setSince(commit1_2.getId()).setUntil(null).call());
    expected = Arrays.asList(commit2_2, commit2_1);
    assertEquals(expected, logs);
    logOp = geogig.command(LogOp.class);
    logs = toList(logOp.setSince(commit2_2.getId()).setUntil(null).call());
    expected = Collections.emptyList();
    assertEquals(expected, logs);
    logOp = geogig.command(LogOp.class);
    logs = toList(logOp.setSince(commit1_2.getId()).setUntil(commit2_1.getId()).call());
    expected = Arrays.asList(commit2_1);
    assertEquals(expected, logs);
    logOp = geogig.command(LogOp.class);
    logs = toList(logOp.setSince(null).setUntil(commit2_1.getId()).call());
    expected = Arrays.asList(commit2_1, commit1_2, commit1_1);
    assertEquals(expected, logs);
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) LogOp(org.locationtech.geogig.api.porcelain.LogOp) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 54 with RevCommit

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

the class MergeOpTest method testMergeConflictingBranches.

@Test
public void testMergeConflictingBranches() throws Exception {
    // Create the following revision graph
    // o
    // |
    // o - Points 1,2 added
    // |\
    // | o - TestBranch - Points 1 modified, 2 removed, 3 added
    // |
    // o - master - HEAD - Points 1 modifiedB, 2 removed
    insertAndAdd(points1, points2);
    geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("TestBranch").call();
    Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
    insert(points1Modified);
    delete(points2);
    insert(points3);
    geogig.command(AddOp.class).call();
    RevCommit masterCommit = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("TestBranch").call();
    Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
    insert(points1ModifiedB);
    delete(points2);
    geogig.command(AddOp.class).call();
    RevCommit branchCommit = geogig.command(CommitOp.class).call();
    // Now try to merge branch into master
    geogig.command(CheckoutOp.class).setSource("master").call();
    Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get();
    try {
        geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId())).call();
        fail();
    } catch (MergeConflictsException e) {
        assertTrue(e.getMessage().contains("conflict"));
    }
    Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
    assertTrue(ref.isPresent());
    assertEquals(masterCommit.getId(), ref.get().getObjectId());
    ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
    assertTrue(ref.isPresent());
    assertEquals(branch.getObjectId(), ref.get().getObjectId());
    String msg = geogig.command(ReadMergeCommitMessageOp.class).call();
    assertFalse(Strings.isNullOrEmpty(msg));
    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(points1Modified).getId());
    assertEquals(conflicts.get(0).getTheirs(), RevFeatureBuilder.build(points1ModifiedB).getId());
    // try to commit
    try {
        geogig.command(CommitOp.class).call();
        fail();
    } catch (IllegalStateException e) {
        assertEquals(e.getMessage(), "Cannot run operation while merge conflicts exist.");
    }
    // solve, and commit
    Feature points1Merged = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
    insert(points1Merged);
    geogig.command(AddOp.class).call();
    RevCommit commit = geogig.command(CommitOp.class).call();
    assertTrue(commit.getMessage().contains(idP1));
    List<ObjectId> parents = commit.getParentIds();
    assertEquals(2, parents.size());
    assertEquals(masterCommit.getId(), parents.get(0));
    assertEquals(branchCommit.getId(), parents.get(1));
    Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertTrue(revFeature.isPresent());
    assertEquals(RevFeatureBuilder.build(points1Merged), revFeature.get());
    path = NodeRef.appendChild(pointsName, idP2);
    revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertFalse(revFeature.isPresent());
    path = NodeRef.appendChild(pointsName, idP3);
    revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertTrue(revFeature.isPresent());
    ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
    assertFalse(ref.isPresent());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) ObjectId(org.locationtech.geogig.api.ObjectId) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevFeature(org.locationtech.geogig.api.RevFeature) Feature(org.opengis.feature.Feature) 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) MergeConflictsException(org.locationtech.geogig.api.porcelain.MergeConflictsException) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) RevFeature(org.locationtech.geogig.api.RevFeature) RefParse(org.locationtech.geogig.api.plumbing.RefParse) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) ReadMergeCommitMessageOp(org.locationtech.geogig.api.plumbing.merge.ReadMergeCommitMessageOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 55 with RevCommit

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

the class MergeOpTest method testMergeMultiple.

@Test
public void testMergeMultiple() throws Exception {
    // Create the following revision graph
    // . o
    // . |
    // . o - Points 1 added
    // . |\
    // . | o - branch1 - Points 2 added
    // . |
    // . o - Points 3 added
    // ./|
    // o | - branch 2 - Lines 1 added
    // . |
    // . o - master - HEAD - Lines 2 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, then create branch2 and checkout
    geogig.command(CheckoutOp.class).setSource("master").call();
    insertAndAdd(points3);
    final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
    geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch2").call();
    insertAndAdd(lines1);
    final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
    geogig.command(CheckoutOp.class).setSource("master").call();
    insertAndAdd(lines2);
    final RevCommit c5 = geogig.command(CommitOp.class).setMessage("commit for " + idL2).call();
    // Merge branch1 and branch2 into master to create the following revision graph
    // . o
    // . |
    // . o - Points 1 added
    // . |\
    // . | o - branch1 - Points 2 added
    // . | |
    // . o | - Points 3 added
    // ./| |
    // o | | - branch 2 - Lines 1 added
    // | | |
    // | o | - Lines 2 added
    // .\|/
    // . o - master - HEAD - Merge commit
    Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
    Ref branch2 = geogig.command(RefParse.class).setName("branch2").call().get();
    final MergeReport mergeReport = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getObjectId())).addCommit(Suppliers.ofInstance(branch2.getObjectId())).setMessage("My merge message.").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());
    path = appendChild(pointsName, points2.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());
    path = appendChild(linesName, lines2.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();
    assertEquals("My merge message.", logC4.getMessage());
    assertEquals(3, logC4.getParentIds().size());
    assertEquals(c5.getId(), logC4.getParentIds().get(0));
    assertEquals(c2.getId(), logC4.getParentIds().get(1));
    assertEquals(c4.getId(), logC4.getParentIds().get(2));
    // Commit 3
    RevCommit logC3 = log.next();
    assertEquals(c5.getAuthor(), logC3.getAuthor());
    assertEquals(c5.getCommitter(), logC3.getCommitter());
    assertEquals(c5.getMessage(), logC3.getMessage());
    assertEquals(c5.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)

Aggregations

RevCommit (org.locationtech.geogig.api.RevCommit)291 Test (org.junit.Test)212 ObjectId (org.locationtech.geogig.api.ObjectId)109 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)107 LogOp (org.locationtech.geogig.api.porcelain.LogOp)86 Ref (org.locationtech.geogig.api.Ref)71 Feature (org.opengis.feature.Feature)52 NodeRef (org.locationtech.geogig.api.NodeRef)47 ArrayList (java.util.ArrayList)44 BranchCreateOp (org.locationtech.geogig.api.porcelain.BranchCreateOp)44 RevTree (org.locationtech.geogig.api.RevTree)36 SymRef (org.locationtech.geogig.api.SymRef)33 RefParse (org.locationtech.geogig.api.plumbing.RefParse)33 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)31 RevObject (org.locationtech.geogig.api.RevObject)30 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)30 MergeScenarioReport (org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport)30 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)26 LinkedList (java.util.LinkedList)24 AddOp (org.locationtech.geogig.api.porcelain.AddOp)21