use of org.locationtech.geogig.api.RevCommit 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);
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class PushOpTest method setUpInternal.
@Override
protected void setUpInternal() throws Exception {
// Commit several features to the remote
expectedMaster = new LinkedList<RevCommit>();
expectedBranch = new LinkedList<RevCommit>();
insertAndAdd(remoteGeogig.geogig, points1);
RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
expectedMaster.addFirst(commit);
expectedBranch.addFirst(commit);
// Create and checkout branch1
remoteGeogig.geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("Branch1").call();
// Commit some changes to branch1
insertAndAdd(remoteGeogig.geogig, points2);
commit = remoteGeogig.geogig.command(CommitOp.class).call();
expectedBranch.addFirst(commit);
insertAndAdd(remoteGeogig.geogig, points3);
commit = remoteGeogig.geogig.command(CommitOp.class).call();
expectedBranch.addFirst(commit);
// Make sure Branch1 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(expectedBranch, logged);
// Checkout master and commit some changes
remoteGeogig.geogig.command(CheckoutOp.class).setSource("master").call();
insertAndAdd(remoteGeogig.geogig, lines1);
commit = remoteGeogig.geogig.command(CommitOp.class).call();
expectedMaster.addFirst(commit);
insertAndAdd(remoteGeogig.geogig, lines2);
commit = remoteGeogig.geogig.command(CommitOp.class).call();
expectedMaster.addFirst(commit);
// Make sure master has all of the commits
logs = remoteGeogig.geogig.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expectedMaster, 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.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).setBranch("Branch1").call();
// Make sure the local repository got all of the commits
logs = localGeogig.geogig.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expectedBranch, logged);
// Make sure the local master matches the remote
localGeogig.geogig.command(CheckoutOp.class).setSource("master").call();
logs = localGeogig.geogig.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expectedMaster, logged);
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class LogOpTest method testPathFilterSingleFeature.
@Test
public void testPathFilterSingleFeature() throws Exception {
List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
List<RevCommit> allCommits = Lists.newArrayList();
RevCommit expectedCommit = null;
for (Feature f : features) {
insertAndAdd(f);
String id = f.getIdentifier().getID();
final RevCommit commit = geogig.command(CommitOp.class).call();
if (id.equals(lines1.getIdentifier().getID())) {
expectedCommit = commit;
}
allCommits.add(commit);
}
String path = NodeRef.appendChild(linesName, lines1.getIdentifier().getID());
List<RevCommit> feature2_1Commits = toList(logOp.addPath(path).call());
assertEquals(1, feature2_1Commits.size());
assertEquals(Collections.singletonList(expectedCommit), feature2_1Commits);
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class LogOpTest method testTemporalConstraint.
@Test
public void testTemporalConstraint() throws Exception {
List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
List<Long> timestamps = Arrays.asList(Long.valueOf(1000), Long.valueOf(2000), Long.valueOf(3000), Long.valueOf(4000), Long.valueOf(5000), Long.valueOf(6000));
LinkedList<RevCommit> allCommits = new LinkedList<RevCommit>();
for (int i = 0; i < features.size(); i++) {
Feature f = features.get(i);
Long timestamp = timestamps.get(i);
insertAndAdd(f);
final RevCommit commit = geogig.command(CommitOp.class).setCommitterTimestamp(timestamp).call();
allCommits.addFirst(commit);
}
// test time range exclusive
boolean minInclusive = false;
boolean maxInclusive = false;
Range<Date> commitRange = new Range<Date>(Date.class, new Date(2000), minInclusive, new Date(5000), maxInclusive);
logOp.setTimeRange(commitRange);
List<RevCommit> logged = toList(logOp.call());
List<RevCommit> expected = allCommits.subList(2, 4);
assertEquals(expected, logged);
// test time range inclusive
minInclusive = true;
maxInclusive = true;
commitRange = new Range<Date>(Date.class, new Date(2000), minInclusive, new Date(5000), maxInclusive);
logOp = geogig.command(LogOp.class).setTimeRange(commitRange);
logged = toList(logOp.call());
expected = allCommits.subList(1, 5);
assertEquals(expected, logged);
// test reset time range
logOp = geogig.command(LogOp.class).setTimeRange(commitRange).setTimeRange(null);
logged = toList(logOp.call());
expected = allCommits;
assertEquals(expected, logged);
}
use of org.locationtech.geogig.api.RevCommit in project GeoGig by boundlessgeo.
the class OSMUpdateOp method _call.
/**
* Executes the {@code OSMUpdateOp} operation.
*
* @return a {@link OSMDownloadReport} of the operation
*/
@Override
protected Optional<OSMReport> _call() {
final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call();
Preconditions.checkState(currHead.isPresent(), "Repository has no HEAD, can't update.");
Preconditions.checkState(currHead.get() instanceof SymRef, "Can't update from detached HEAD");
List<OSMLogEntry> entries = command(ReadOSMLogEntries.class).call();
checkArgument(!entries.isEmpty(), "Not in a geogig repository with OSM data");
Iterator<RevCommit> log = command(LogOp.class).setFirstParentOnly(false).setTopoOrder(false).call();
RevCommit lastCommit = null;
OSMLogEntry lastEntry = null;
while (log.hasNext()) {
RevCommit commit = log.next();
for (OSMLogEntry entry : entries) {
if (entry.getId().equals(commit.getTreeId())) {
lastCommit = commit;
lastEntry = entry;
break;
}
}
if (lastCommit != null) {
break;
}
}
checkNotNull(lastCommit, "The current branch does not contain OSM data");
command(BranchCreateOp.class).setSource(lastCommit.getId().toString()).setName(OSMUtils.OSM_FETCH_BRANCH).setAutoCheckout(true).setForce(true).call();
Optional<String> filter = command(ReadOSMFilterFile.class).setEntry(lastEntry).call();
Preconditions.checkState(filter.isPresent(), "Filter file not found");
message = message == null ? "Updated OSM data" : message;
Optional<OSMReport> report = command(OSMImportOp.class).setMessage(message).setFilter(filter.get()).setDataSource(apiUrl).setProgressListener(getProgressListener()).call();
if (!report.isPresent()) {
return report;
}
if (!getProgressListener().isCanceled()) {
command(CheckoutOp.class).setSource(((SymRef) currHead.get()).getTarget()).call();
Optional<Ref> upstreamRef = command(RefParse.class).setName(OSMUtils.OSM_FETCH_BRANCH).call();
Supplier<ObjectId> commitSupplier = Suppliers.ofInstance(upstreamRef.get().getObjectId());
if (rebase) {
getProgressListener().setDescription("Rebasing updated features...");
command(RebaseOp.class).setUpstream(commitSupplier).setProgressListener(getProgressListener()).call();
} else {
getProgressListener().setDescription("Merging updated features...");
command(MergeOp.class).addCommit(commitSupplier).setProgressListener(getProgressListener()).call();
}
}
return report;
}
Aggregations