Search in sources :

Example 1 with Ref

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

the class ShowRef method runInternal.

@Override
public void runInternal(GeogigCLI cli) throws IOException {
    ConsoleReader console = cli.getConsole();
    GeoGIG geogig = cli.getGeogig();
    ForEachRef op = geogig.command(ForEachRef.class);
    Predicate<Ref> filter = new Predicate<Ref>() {

        @Override
        public boolean apply(Ref ref) {
            String name = ref.getName();
            if (!name.startsWith(Ref.REFS_PREFIX)) {
                return false;
            }
            boolean match = patterns.isEmpty() ? true : false;
            for (String pattern : patterns) {
                if (Strings.isNullOrEmpty(pattern)) {
                    match = true;
                } else if (name.endsWith("/" + pattern)) {
                    match = true;
                    break;
                }
            }
            return match;
        }
    };
    op.setFilter(filter);
    ImmutableSet<Ref> refs = op.call();
    for (Ref ref : refs) {
        console.println(ref.getObjectId() + " " + ref.getName());
    }
}
Also used : Ref(org.locationtech.geogig.api.Ref) ForEachRef(org.locationtech.geogig.api.plumbing.ForEachRef) ConsoleReader(jline.console.ConsoleReader) ForEachRef(org.locationtech.geogig.api.plumbing.ForEachRef) GeoGIG(org.locationtech.geogig.api.GeoGIG) Predicate(com.google.common.base.Predicate)

Example 2 with Ref

use of org.locationtech.geogig.api.Ref 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 3 with Ref

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

the class LocalMappedRemoteRepo method listRefs.

/**
     * List the remote's {@link Ref refs}.
     * 
     * @param getHeads whether to return refs in the {@code refs/heads} namespace
     * @param getTags whether to return refs in the {@code refs/tags} namespace
     * @return an immutable set of refs from the remote
     */
@Override
public ImmutableSet<Ref> listRefs(final boolean getHeads, final boolean getTags) {
    Predicate<Ref> filter = new Predicate<Ref>() {

        @Override
        public boolean apply(Ref input) {
            boolean keep = false;
            if (getHeads) {
                keep = input.getName().startsWith(Ref.HEADS_PREFIX);
            }
            if (getTags) {
                keep = keep || input.getName().startsWith(Ref.TAGS_PREFIX);
            }
            return keep;
        }
    };
    ImmutableSet<Ref> remoteRefs = remoteGeoGig.command(ForEachRef.class).setFilter(filter).call();
    // Translate the refs to their mapped values.
    ImmutableSet.Builder<Ref> builder = new ImmutableSet.Builder<Ref>();
    for (Ref remoteRef : remoteRefs) {
        Ref newRef = remoteRef;
        if (!(newRef instanceof SymRef) && localRepository.graphDatabase().exists(remoteRef.getObjectId())) {
            ObjectId mappedCommit = localRepository.graphDatabase().getMapping(remoteRef.getObjectId());
            if (mappedCommit != null) {
                newRef = new Ref(remoteRef.getName(), mappedCommit);
            }
        }
        builder.add(newRef);
    }
    return builder.build();
}
Also used : 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) ImmutableSet(com.google.common.collect.ImmutableSet) ObjectId(org.locationtech.geogig.api.ObjectId) CommitBuilder(org.locationtech.geogig.api.CommitBuilder) Predicate(com.google.common.base.Predicate)

Example 4 with Ref

use of org.locationtech.geogig.api.Ref 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 5 with Ref

use of org.locationtech.geogig.api.Ref 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)

Aggregations

Ref (org.locationtech.geogig.api.Ref)147 Test (org.junit.Test)75 RevCommit (org.locationtech.geogig.api.RevCommit)71 SymRef (org.locationtech.geogig.api.SymRef)62 NodeRef (org.locationtech.geogig.api.NodeRef)57 RefParse (org.locationtech.geogig.api.plumbing.RefParse)56 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)53 ObjectId (org.locationtech.geogig.api.ObjectId)46 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)40 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)37 LogOp (org.locationtech.geogig.api.porcelain.LogOp)30 BranchCreateOp (org.locationtech.geogig.api.porcelain.BranchCreateOp)23 Feature (org.opengis.feature.Feature)21 Conflict (org.locationtech.geogig.api.plumbing.merge.Conflict)17 RevTree (org.locationtech.geogig.api.RevTree)16 MergeOp (org.locationtech.geogig.api.porcelain.MergeOp)16 IOException (java.io.IOException)15 RevFeature (org.locationtech.geogig.api.RevFeature)14 AddOp (org.locationtech.geogig.api.porcelain.AddOp)14 MergeReport (org.locationtech.geogig.api.porcelain.MergeOp.MergeReport)14