Search in sources :

Example 31 with Conflict

use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.

the class MongoConflictsTest method testConflicts.

@Test
public void testConflicts() {
    StagingDatabase db = geogig.getRepository().stagingDatabase();
    List<Conflict> conflicts = db.getConflicts(null, null);
    assertTrue(conflicts.isEmpty());
    Conflict conflict = new Conflict(idP1, ObjectId.forString("ancestor"), ObjectId.forString("ours"), ObjectId.forString("theirs"));
    Conflict conflict2 = new Conflict(idP2, ObjectId.forString("ancestor2"), ObjectId.forString("ours2"), ObjectId.forString("theirs2"));
    db.addConflict(null, conflict);
    Optional<Conflict> returnedConflict = db.getConflict(null, idP1);
    assertTrue(returnedConflict.isPresent());
    assertEquals(conflict, returnedConflict.get());
    db.removeConflict(null, idP1);
    conflicts = db.getConflicts(null, null);
    assertTrue(conflicts.isEmpty());
    db.addConflict(null, conflict);
    db.addConflict(null, conflict2);
    assertEquals(2, db.getConflicts(null, null).size());
    db.removeConflicts(null);
    conflicts = db.getConflicts(null, null);
    assertTrue(conflicts.isEmpty());
    final String NS = "ns";
    db.addConflict(NS, conflict);
    db.addConflict(null, conflict2);
    returnedConflict = db.getConflict(NS, idP1);
    assertTrue(returnedConflict.isPresent());
    assertEquals(conflict, returnedConflict.get());
    assertEquals(1, db.getConflicts(NS, null).size());
    db.removeConflict(NS, idP1);
    conflicts = db.getConflicts(NS, null);
    assertTrue(conflicts.isEmpty());
    db.addConflict(NS, conflict);
    db.addConflict(NS, conflict2);
    assertEquals(2, db.getConflicts(NS, null).size());
    assertEquals(1, db.getConflicts(null, null).size());
    db.removeConflicts(NS);
    conflicts = db.getConflicts(NS, null);
    assertTrue(conflicts.isEmpty());
    conflicts = db.getConflicts(null, null);
    assertFalse(conflicts.isEmpty());
}
Also used : Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) StagingDatabase(org.locationtech.geogig.storage.StagingDatabase) Test(org.junit.Test)

Example 32 with Conflict

use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.

the class AddOp method stage.

/**
     * Stages the object addressed by {@code pathFilter}, or all unstaged objects if
     * {@code pathFilter == null} to be added, if it is/they are marked as an unstaged change. Does
     * nothing otherwise.
     * <p>
     * To stage changes not yet staged, a diff tree walk is performed using the current staged
     * {@link RevTree} as the old object and the current unstaged {@link RevTree} as the new object.
     * Then all the differences are traversed and the staged tree is updated with the changes
     * reported by the diff walk (neat).
     * </p>
     * 
     * @param progress the progress listener for this process
     * @param pathFilter the filter to use
     */
public void stage(final ProgressListener progress, @Nullable final String pathFilter) {
    // working tree, so it's just a matter of updating the index ref to working tree RevTree id
    if (null == pathFilter && !index().getStaged(null).hasNext() && !updateOnly && index().countConflicted(null) == 0) {
        progress.started();
        Optional<ObjectId> workHead = command(RevParse.class).setRefSpec(Ref.WORK_HEAD).call();
        if (workHead.isPresent()) {
            command(UpdateRef.class).setName(Ref.STAGE_HEAD).setNewValue(workHead.get()).call();
        }
        progress.setProgress(100f);
        progress.complete();
        return;
    }
    final long numChanges = workingTree().countUnstaged(pathFilter).count();
    Iterator<DiffEntry> unstaged = workingTree().getUnstaged(pathFilter);
    if (updateOnly) {
        unstaged = Iterators.filter(unstaged, new Predicate<DiffEntry>() {

            @Override
            public boolean apply(@Nullable DiffEntry input) {
                // HACK: avoid reporting changed trees
                if (input.isChange() && input.getOldObject().getType().equals(TYPE.TREE)) {
                    return false;
                }
                return input.getOldObject() != null;
            }
        });
    }
    index().stage(progress, unstaged, numChanges);
    List<Conflict> conflicts = index().getConflicted(pathFilter);
    for (Conflict conflict : conflicts) {
        // if we are staging unmerged files, the conflict should get solved. However, if the
        // working index object is the same as the staging area one (for instance, after running
        // checkout --ours), it will not be reported by the getUnstaged method. We solve that
        // here.
        stagingDatabase().removeConflict(null, conflict.getPath());
    }
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) CanRunDuringConflict(org.locationtech.geogig.di.CanRunDuringConflict) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) Nullable(javax.annotation.Nullable) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Predicate(com.google.common.base.Predicate)

Example 33 with Conflict

use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.

the class RebaseOpTest method testRebaseSquashWithConflict.

@Test
public void testRebaseSquashWithConflict() throws Exception {
    // Create the following revision graph
    // o
    // |
    // o - Points 1,2 added
    // |\
    // | o - branch1 - Points 1 modifiedB, 2 removed, 3 added
    // |
    // o - Points 1 modified, 2 removed
    // |
    // o - master - HEAD - Lines 1 added
    insertAndAdd(points1, points2);
    geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("branch1").call();
    Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
    insert(points1Modified);
    delete(points2);
    geogig.command(AddOp.class).call();
    RevCommit masterCommit2 = geogig.command(CommitOp.class).setMessage("adding points1 modified, deleting point2").call();
    insert(lines1);
    geogig.command(AddOp.class).call();
    RevCommit masterCommit = geogig.command(CommitOp.class).setMessage("adding lines.1").call();
    geogig.command(CheckoutOp.class).setSource("branch1").call();
    insert(points3);
    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).setMessage("branch commit").call();
    geogig.command(CheckoutOp.class).setSource("master").call();
    Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
    try {
        geogig.command(RebaseOp.class).setUpstream(Suppliers.ofInstance(branch1.getObjectId())).setSquashMessage("squashed commit").call();
        fail();
    } catch (RebaseConflictsException 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());
    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());
    // solve, and continue
    Feature points1Merged = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
    insert(points1Merged);
    geogig.command(AddOp.class).call();
    geogig.command(RebaseOp.class).setContinue(true).call();
    Iterator<RevCommit> log = geogig.command(LogOp.class).call();
    RevCommit logCommit1 = log.next();
    assertEquals(masterCommit.getAuthor(), logCommit1.getAuthor());
    assertEquals(masterCommit.getCommitter().getName(), logCommit1.getCommitter().getName());
    assertEquals("squashed commit", logCommit1.getMessage());
    assertEquals(masterCommit.getAuthor().getTimeZoneOffset(), logCommit1.getAuthor().getTimeZoneOffset());
    assertEquals(masterCommit.getAuthor().getTimestamp(), logCommit1.getAuthor().getTimestamp());
    assertEquals(masterCommit.getCommitter().getTimeZoneOffset(), logCommit1.getCommitter().getTimeZoneOffset());
    assertNotSame(masterCommit.getCommitter().getTimestamp(), logCommit1.getCommitter().getTimestamp());
    assertNotSame(masterCommit.getTreeId(), logCommit1.getTreeId());
    RevCommit logCommit3 = log.next();
    assertEquals(branchCommit.getAuthor(), logCommit3.getAuthor());
    assertEquals(branchCommit.getCommitter().getName(), logCommit3.getCommitter().getName());
    assertEquals(branchCommit.getMessage(), logCommit3.getMessage());
    path = NodeRef.appendChild(linesName, idL1);
    Optional<RevFeature> lines = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertTrue(lines.isPresent());
    path = NodeRef.appendChild(pointsName, idP3);
    Optional<RevFeature> points = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertTrue(points.isPresent());
    path = NodeRef.appendChild(pointsName, idP1);
    points = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertTrue(points.isPresent());
    assertEquals(RevFeatureBuilder.build(points1Merged), points.get());
    ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
    assertFalse(ref.isPresent());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) RebaseConflictsException(org.locationtech.geogig.api.porcelain.RebaseConflictsException) LogOp(org.locationtech.geogig.api.porcelain.LogOp) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevFeature(org.locationtech.geogig.api.RevFeature) Feature(org.opengis.feature.Feature) Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) NodeRef(org.locationtech.geogig.api.NodeRef) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) RebaseOp(org.locationtech.geogig.api.porcelain.RebaseOp) RevFeature(org.locationtech.geogig.api.RevFeature) RefParse(org.locationtech.geogig.api.plumbing.RefParse) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 34 with Conflict

use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.

the class RebaseOpTest method testRebaseSkip.

@Test
public void testRebaseSkip() throws Exception {
    // Create the following revision graph
    // o
    // |
    // o - Points 1,2 added
    // |\
    // | o - branch1 - Points 1 modifiedB, 2 removed, 3 added
    // |
    // o - Points 1 modified, 2 removed
    // |
    // o - master - HEAD - Lines 1 added
    insertAndAdd(points1, points2);
    geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("branch1").call();
    Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
    insert(points1Modified);
    delete(points2);
    geogig.command(AddOp.class).call();
    geogig.command(CommitOp.class).setMessage("adding points1 modified, deleting point2").call();
    insert(lines1);
    geogig.command(AddOp.class).call();
    RevCommit masterCommit = geogig.command(CommitOp.class).setMessage("adding lines.1").call();
    geogig.command(CheckoutOp.class).setSource("branch1").call();
    insert(points3);
    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).setMessage("branch commit").call();
    geogig.command(CheckoutOp.class).setSource("master").call();
    Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
    try {
        geogig.command(RebaseOp.class).setUpstream(Suppliers.ofInstance(branch1.getObjectId())).call();
        fail();
    } catch (RebaseConflictsException e) {
        assertTrue(e.getMessage().contains("conflict"));
    }
    String path = NodeRef.appendChild(pointsName, idP1);
    Optional<RevFeature> points = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertTrue(points.isPresent());
    assertEquals(RevFeatureBuilder.build(points1ModifiedB), points.get());
    List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
    assertFalse(conflicts.isEmpty());
    geogig.command(RebaseOp.class).setSkip(true).call();
    conflicts = geogig.command(ConflictsReadOp.class).call();
    assertTrue(conflicts.isEmpty());
    Iterator<RevCommit> log = geogig.command(LogOp.class).call();
    RevCommit logCommit1 = log.next();
    assertEquals(masterCommit.getAuthor(), logCommit1.getAuthor());
    assertEquals(masterCommit.getCommitter().getName(), logCommit1.getCommitter().getName());
    assertEquals(masterCommit.getMessage(), logCommit1.getMessage());
    assertEquals(masterCommit.getAuthor().getTimeZoneOffset(), logCommit1.getAuthor().getTimeZoneOffset());
    assertEquals(masterCommit.getAuthor().getTimestamp(), logCommit1.getAuthor().getTimestamp());
    assertEquals(masterCommit.getCommitter().getTimeZoneOffset(), logCommit1.getCommitter().getTimeZoneOffset());
    assertNotSame(masterCommit.getCommitter().getTimestamp(), logCommit1.getCommitter().getTimestamp());
    assertNotSame(masterCommit.getTreeId(), logCommit1.getTreeId());
    RevCommit logCommit2 = log.next();
    assertEquals(branchCommit.getAuthor(), logCommit2.getAuthor());
    assertEquals(branchCommit.getCommitter().getName(), logCommit2.getCommitter().getName());
    assertEquals(branchCommit.getMessage(), logCommit2.getMessage());
    // check that the changes from conflicting commit haven't been introduced
    points = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertTrue(points.isPresent());
    assertEquals(RevFeatureBuilder.build(points1ModifiedB), points.get());
    Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
    assertFalse(ref.isPresent());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) RebaseConflictsException(org.locationtech.geogig.api.porcelain.RebaseConflictsException) LogOp(org.locationtech.geogig.api.porcelain.LogOp) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevFeature(org.locationtech.geogig.api.RevFeature) Feature(org.opengis.feature.Feature) Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) NodeRef(org.locationtech.geogig.api.NodeRef) 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) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 35 with Conflict

use of org.locationtech.geogig.api.plumbing.merge.Conflict in project GeoGig by boundlessgeo.

the class RemoveOpTest method testRemovalFixesConflict.

@Test
public void testRemovalFixesConflict() throws Exception {
    Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
    Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
    insertAndAdd(points1);
    geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("TestBranch").call();
    insertAndAdd(points1Modified);
    geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("TestBranch").call();
    insertAndAdd(points1ModifiedB);
    insertAndAdd(points2);
    geogig.command(CommitOp.class).call();
    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"));
    }
    String path = NodeRef.appendChild(pointsName, idP1);
    geogig.command(RemoveOp.class).addPathToRemove(path).call();
    List<Conflict> conflicts = geogig.getRepository().stagingDatabase().getConflicts(null, null);
    assertTrue(conflicts.isEmpty());
    geogig.command(CommitOp.class).call();
    Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
    assertFalse(ref.isPresent());
}
Also used : 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) RefParse(org.locationtech.geogig.api.plumbing.RefParse) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) Feature(org.opengis.feature.Feature) Test(org.junit.Test)

Aggregations

Conflict (org.locationtech.geogig.api.plumbing.merge.Conflict)36 Ref (org.locationtech.geogig.api.Ref)17 RevCommit (org.locationtech.geogig.api.RevCommit)17 Test (org.junit.Test)16 NodeRef (org.locationtech.geogig.api.NodeRef)14 ObjectId (org.locationtech.geogig.api.ObjectId)14 ConflictsReadOp (org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp)12 Feature (org.opengis.feature.Feature)12 RefParse (org.locationtech.geogig.api.plumbing.RefParse)11 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)10 SymRef (org.locationtech.geogig.api.SymRef)8 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)8 AddOp (org.locationtech.geogig.api.porcelain.AddOp)8 CanRunDuringConflict (org.locationtech.geogig.di.CanRunDuringConflict)8 MergeConflictsException (org.locationtech.geogig.api.porcelain.MergeConflictsException)7 File (java.io.File)6 IOException (java.io.IOException)6 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)6 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)6 Repository (org.locationtech.geogig.repository.Repository)6