use of org.locationtech.geogig.api.porcelain.SynchronizationException 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.SynchronizationException in project GeoGig by boundlessgeo.
the class Pull method runInternal.
/**
* Executes the pull command using the provided options.
*/
@Override
public void runInternal(GeogigCLI cli) throws IOException {
checkParameter(depth > 0 ? !fulldepth : true, "Cannot specify a depth and full depth. Use --depth <depth> or --fulldepth.");
GeoGIG geogig = cli.getGeogig();
if (depth > 0 || fulldepth) {
if (!geogig.getRepository().getDepth().isPresent()) {
throw new CommandFailedException("Depth operations can only be used on a shallow clone.");
}
}
PullOp pull = geogig.command(PullOp.class);
pull.setProgressListener(cli.getProgressListener());
pull.setAll(all).setRebase(rebase).setFullDepth(fulldepth);
pull.setDepth(depth);
if (args != null) {
if (args.size() > 0) {
pull.setRemote(args.get(0));
}
for (int i = 1; i < args.size(); i++) {
pull.addRefSpec(args.get(i));
}
}
try {
final PullResult result = pull.call();
ConsoleReader console = cli.getConsole();
TransferSummary fetchResult = result.getFetchResult();
FetchResultPrinter.print(fetchResult, console);
final Ref oldRef = result.getOldRef();
final Ref newRef = result.getNewRef();
if (oldRef == null && newRef == null) {
console.println("Nothing to pull.");
} else if (Objects.equal(oldRef, newRef)) {
String name = oldRef == null ? newRef.getName() : oldRef.getName();
name = Ref.localName(name);
console.println(name + " already up to date.");
} else {
String oldTreeish;
String newTreeish = newRef.getObjectId().toString();
if (oldRef == null) {
console.println("From " + result.getRemoteName());
console.println(" * [new branch] " + newRef.localName() + " -> " + newRef.getName());
oldTreeish = ObjectId.NULL.toString();
} else {
oldTreeish = oldRef.getObjectId().toString();
}
DiffObjectCount count = geogig.command(DiffCount.class).setOldVersion(oldTreeish).setNewVersion(newTreeish).call();
long added = count.getFeaturesAdded();
long removed = count.getFeaturesRemoved();
long modified = count.getFeaturesChanged();
console.println(String.format("Features Added: %,d Removed: %,d Modified: %,d", added, removed, modified));
}
} catch (SynchronizationException e) {
switch(e.statusCode) {
case HISTORY_TOO_SHALLOW:
default:
throw new CommandFailedException("Unable to pull, the remote history is shallow.", e);
}
}
}
use of org.locationtech.geogig.api.porcelain.SynchronizationException 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;
}
}
}
use of org.locationtech.geogig.api.porcelain.SynchronizationException in project GeoGig by boundlessgeo.
the class Fetch method runInternal.
/**
* Executes the fetch command using the provided options.
*/
@Override
public void runInternal(GeogigCLI cli) throws IOException {
checkParameter(depth > 0 ? !fulldepth : true, "Cannot specify a depth and full depth. Use --depth <depth> or --fulldepth.");
if (depth > 0 || fulldepth) {
checkParameter(cli.getGeogig().getRepository().getDepth().isPresent(), "Depth operations can only be used on a shallow clone.");
}
TransferSummary result;
try {
FetchOp fetch = cli.getGeogig().command(FetchOp.class);
fetch.setProgressListener(cli.getProgressListener());
fetch.setAll(all).setPrune(prune).setFullDepth(fulldepth);
fetch.setDepth(depth);
if (args != null) {
for (String repo : args) {
fetch.addRemote(repo);
}
}
result = fetch.call();
} catch (SynchronizationException e) {
switch(e.statusCode) {
case HISTORY_TOO_SHALLOW:
default:
throw new CommandFailedException("Unable to fetch, the remote history is shallow.", e);
}
} catch (IllegalArgumentException iae) {
throw new CommandFailedException(iae.getMessage(), iae);
} catch (IllegalStateException ise) {
throw new CommandFailedException(ise.getMessage(), ise);
}
ConsoleReader console = cli.getConsole();
if (result.getChangedRefs().isEmpty()) {
console.println("Already up to date.");
} else {
FetchResultPrinter.print(result, console);
}
}
use of org.locationtech.geogig.api.porcelain.SynchronizationException in project GeoGig by boundlessgeo.
the class AbstractMappedRemoteRepo 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(Ref ref, String refspec, ProgressListener progress) throws SynchronizationException {
Optional<Ref> remoteRef = getRemoteRef(refspec);
checkPush(ref, remoteRef);
beginPush();
PushCommitGatherer gatherer = new PushCommitGatherer(localRepository);
try {
gatherer.traverse(ref.getObjectId());
Stack<ObjectId> needed = gatherer.commits;
while (!needed.isEmpty()) {
ObjectId commitToPush = needed.pop();
pushSparseCommit(commitToPush);
}
ObjectId newCommitId = localRepository.graphDatabase().getMapping(ref.getObjectId());
ObjectId originalRemoteRefValue = ObjectId.NULL;
if (remoteRef.isPresent()) {
originalRemoteRefValue = remoteRef.get().getObjectId();
}
endPush(refspec, newCommitId, originalRemoteRefValue.toString());
} catch (Exception e) {
Throwables.propagate(e);
} finally {
}
}
Aggregations