use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class RevertOpTest method testRevertToSameFeatureIsNotConflict.
@Test
public void testRevertToSameFeatureIsNotConflict() throws Exception {
@SuppressWarnings("unused") ObjectId oId1 = insertAndAdd(points1);
@SuppressWarnings("unused") RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
insertAndAdd(points1_modified);
RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1).call();
insertAndAdd(points1);
@SuppressWarnings("unused") RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1 + " again").call();
geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(c2.getId())).call();
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class RevertOpTest method testRevertModifiedFeatureConflictSolveAndContinue.
@Test
public void testRevertModifiedFeatureConflictSolveAndContinue() throws Exception {
ObjectId oId1 = insertAndAdd(points1);
RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
insertAndAdd(points1_modified);
RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1).call();
Feature points1_modifiedB = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
insertAndAdd(points1_modifiedB);
RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1 + " again").call();
try {
geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(c2.getId())).call();
fail();
} catch (RevertConflictsException e) {
assertTrue(e.getMessage().contains(idP1));
}
Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
assertTrue(ref.isPresent());
assertEquals(c3.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(points1_modifiedB).getId());
assertEquals(conflicts.get(0).getTheirs(), RevFeatureBuilder.build(points1).getId());
// solve, and continue
insert(points1);
geogig.command(AddOp.class).call();
geogig.command(RevertOp.class).setContinue(true).call();
Iterator<RevCommit> log = geogig.command(LogOp.class).call();
RevCommit logCommit = log.next();
assertEquals(c2.getAuthor().getName(), logCommit.getAuthor().getName());
assertEquals(c2.getCommitter().getName(), logCommit.getCommitter().getName());
assertEquals("Revert '" + c2.getMessage() + "'\nThis reverts " + c2.getId().toString(), logCommit.getMessage());
assertNotSame(c2.getCommitter().getTimestamp(), logCommit.getCommitter().getTimestamp());
assertNotSame(c2.getTreeId(), logCommit.getTreeId());
final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD).call();
final Optional<ObjectId> headTreeId = geogig.command(ResolveTreeish.class).setTreeish(currHead.get().getObjectId()).call();
RevTree headTree = repo.getTree(headTreeId.get());
Optional<NodeRef> points1Node = geogig.command(FindTreeChild.class).setChildPath(NodeRef.appendChild(pointsName, idP1)).setParent(headTree).call();
assertTrue(points1Node.isPresent());
assertEquals(oId1, points1Node.get().getNode().getObjectId());
assertEquals(c3.getId(), log.next().getId());
assertEquals(c2.getId(), log.next().getId());
assertEquals(c1.getId(), log.next().getId());
assertFalse(log.hasNext());
}
use of org.locationtech.geogig.api.ObjectId 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));
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class SparseCloneTest method testSparseCloneAllMatch.
@Test
public void testSparseCloneAllMatch() throws Exception {
Map<String, String> filter = new HashMap<String, String>();
filter.put("default", "BBOX(pp,0, -125, 40, -70,'EPSG:4326')");
createFilterFile(filter);
// Commit several features to the remote
List<Feature> features = Arrays.asList(city1, city2, city3, road1, road2, road3);
LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
Map<Feature, ObjectId> oids = new HashMap<Feature, ObjectId>();
for (Feature f : features) {
ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
oids.put(f, oId);
final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).setMessage(f.getIdentifier().toString()).call();
expected.addFirst(commit);
Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
assertTrue(childObject.isPresent());
}
// Make sure the remote has all of the commits
Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
List<RevCommit> logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
// Make sure the local repository has no commits prior to clone
logs = localGeogig.geogig.command(LogOp.class).call();
assertNotNull(logs);
assertFalse(logs.hasNext());
// clone from the remote
CloneOp clone = clone();
clone.setDepth(0);
clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).setBranch("master").call();
// Because all features match the filter, the history should be identical
// Make sure the local repository got the correct commits
logs = localGeogig.geogig.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
assertExists(localGeogig, oids.get(city1), oids.get(city2), oids.get(city3), oids.get(road1), oids.get(road2), oids.get(road3));
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class SparseCloneTest method testPullCommitThatPassesFilter.
@Test
public void testPullCommitThatPassesFilter() throws Exception {
setupSparseClone();
// Add a commit that passes our filter to the remote.
ObjectId oId = insertAndAdd(remoteGeogig.geogig, city1_modified);
final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).setMessage(city1_modified.getIdentifier().toString()).call();
Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
assertTrue(childObject.isPresent());
assertEquals(commit, remoteGeogig.geogig.getRepository().objectDatabase().getCommit(commit.getId()));
PullOp pull = pull();
pull.call();
Iterator<RevCommit> logs = localGeogig.geogig.command(LogOp.class).call();
List<RevCommit> logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals("Cities.1", logged.get(0).getMessage());
assertFalse(commit.getId().equals(logged.get(0).getId()));
assertExists(localGeogig, oId);
}
Aggregations