use of org.locationtech.geogig.api.porcelain.PushOp 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.porcelain.PushOp in project GeoGig by boundlessgeo.
the class RemoteRepositoryTestCase method push.
protected PushOp push() {
SendPack sendPack = spy(localGeogig.geogig.command(SendPack.class));
doReturn(Optional.of(remoteRepo)).when(sendPack).getRemoteRepo(any(Remote.class));
PushOp push = spy(localGeogig.geogig.command(PushOp.class));
doReturn(sendPack).when(push).command(eq(SendPack.class));
FetchOp fetch = fetch();
// when(push.command(FetchOp.class)).thenReturn(fetch);
doReturn(fetch).when(push).command(eq(FetchOp.class));
LsRemote lsRemote = lsremote();
// when(push.command(LsRemote.class)).thenReturn(lsRemote);
doReturn(lsRemote).when(push).command(eq(LsRemote.class));
return push;
}
use of org.locationtech.geogig.api.porcelain.PushOp 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.porcelain.PushOp in project GeoGig by boundlessgeo.
the class PushOpTest method testPushToRemoteHEAD.
@Test
public void testPushToRemoteHEAD() throws Exception {
insertAndAdd(localGeogig.geogig, lines3);
localGeogig.geogig.command(CommitOp.class).call();
PushOp push = push();
try {
push.setRemote("origin").addRefSpec("HEAD").call();
fail();
} catch (SynchronizationException e) {
assertEquals(SynchronizationException.StatusCode.CANNOT_PUSH_TO_SYMBOLIC_REF, e.statusCode);
}
}
use of org.locationtech.geogig.api.porcelain.PushOp in project GeoGig by boundlessgeo.
the class Push method runInternal.
/**
* Executes the push command using the provided options.
*/
@Override
public void runInternal(GeogigCLI cli) throws IOException {
PushOp push = cli.getGeogig().command(PushOp.class);
push.setProgressListener(cli.getProgressListener());
push.setAll(all);
if (args != null) {
if (args.size() > 0) {
push.setRemote(args.get(0));
}
for (int i = 1; i < args.size(); i++) {
push.addRefSpec(args.get(i));
}
}
try {
// TODO: listen on progress?
TransferSummary dataPushed = push.call();
if (dataPushed.isEmpty()) {
cli.getConsole().println("Nothing to push.");
}
} catch (SynchronizationException e) {
switch(e.statusCode) {
case REMOTE_HAS_CHANGES:
throw new CommandFailedException("Push failed: The remote repository has changes that would be lost in the event of a push.", e);
case HISTORY_TOO_SHALLOW:
throw new CommandFailedException("Push failed: There is not enough local history to complete the push.", e);
case CANNOT_PUSH_TO_SYMBOLIC_REF:
throw new CommandFailedException("Push failed: Cannot push to a symbolic reference", e);
default:
break;
}
}
}
Aggregations