use of org.locationtech.geogig.cli.CommandFailedException 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.cli.CommandFailedException 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.cli.CommandFailedException in project GeoGig by boundlessgeo.
the class Clone method runInternal.
/**
* Executes the clone command using the provided options.
*/
@Override
public void runInternal(GeogigCLI cli) throws IOException {
checkParameter(args != null && args.size() > 0, "You must specify a repository to clone.");
checkParameter(args.size() < 3, "Too many arguments provided.");
if (filterFile != null) {
checkParameter(branch != null, "Sparse Clone: You must explicitly specify a remote branch to clone by using '--branch <branch>'.");
}
String repoURL = args.get(0).replace('\\', '/');
File repoDir;
{
File currDir = cli.getPlatform().pwd();
// Construct a non-relative repository URL in case of a local remote
if (!repoURL.startsWith("http")) {
File repo = new File(repoURL);
if (!repo.isAbsolute()) {
repo = new File(currDir, repoURL).getCanonicalFile();
}
repoURL = repo.toURI().getPath();
}
if (args != null && args.size() == 2) {
String target = args.get(1);
File f = new File(target);
if (!f.isAbsolute()) {
f = new File(currDir, target).getCanonicalFile();
}
repoDir = f;
} else {
String[] sp = repoURL.split("/");
repoDir = new File(currDir, sp[sp.length - 1]).getCanonicalFile();
}
if (!repoDir.exists() && !repoDir.mkdirs()) {
throw new CommandFailedException("Can't create directory " + repoDir.getAbsolutePath());
}
}
GeoGIG geogig = new GeoGIG(cli.getGeogigInjector(), repoDir);
checkParameter(!geogig.command(ResolveGeogigDir.class).call().isPresent(), "Destination path already exists and is not an empty directory.");
geogig.command(InitOp.class).setConfig(Init.splitConfig(config)).setFilterFile(filterFile).call();
cli.setGeogig(geogig);
cli.getPlatform().setWorkingDir(repoDir);
cli.getConsole().println("Cloning into '" + cli.getPlatform().pwd().getName() + "'...");
CloneOp clone = cli.getGeogig().command(CloneOp.class);
clone.setProgressListener(cli.getProgressListener());
clone.setBranch(branch).setRepositoryURL(repoURL);
clone.setUserName(username).setPassword(password);
clone.setDepth(depth);
clone.call();
cli.getConsole().println("Done.");
}
use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.
the class Commit method runInternal.
/**
* Executes the commit command using the provided options.
*
* @param cli
* @see org.locationtech.geogig.cli.AbstractCommand#runInternal(org.locationtech.geogig.cli.GeogigCLI)
*/
@Override
public void runInternal(GeogigCLI cli) throws IOException {
final GeoGIG geogig = cli.getGeogig();
if (message == null || Strings.isNullOrEmpty(message)) {
message = geogig.command(ReadMergeCommitMessageOp.class).call();
}
checkParameter(!Strings.isNullOrEmpty(message) || commitToReuse != null || amend, "No commit message provided");
ConsoleReader console = cli.getConsole();
Ansi ansi = newAnsi(console.getTerminal());
RevCommit commit;
try {
CommitOp commitOp = geogig.command(CommitOp.class).setMessage(message).setAmend(amend);
if (commitTimestamp != null && !Strings.isNullOrEmpty(commitTimestamp)) {
Long millis = geogig.command(ParseTimestamp.class).setString(commitTimestamp).call();
commitOp.setCommitterTimestamp(millis.longValue());
}
if (commitToReuse != null) {
Optional<ObjectId> commitId = geogig.command(RevParse.class).setRefSpec(commitToReuse).call();
checkParameter(commitId.isPresent(), "Provided reference does not exist");
TYPE type = geogig.command(ResolveObjectType.class).setObjectId(commitId.get()).call();
checkParameter(TYPE.COMMIT.equals(type), "Provided reference does not resolve to a commit");
commitOp.setCommit(geogig.getRepository().getCommit(commitId.get()));
}
commit = commitOp.setPathFilters(pathFilters).setProgressListener(cli.getProgressListener()).call();
} catch (NothingToCommitException noChanges) {
throw new CommandFailedException(noChanges.getMessage(), noChanges);
}
final ObjectId parentId = commit.parentN(0).or(ObjectId.NULL);
console.println("[" + commit.getId() + "] " + commit.getMessage());
console.print("Committed, counting objects...");
Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(parentId).setNewVersion(commit.getId()).call();
int adds = 0, deletes = 0, changes = 0;
DiffEntry diffEntry;
while (diff.hasNext()) {
diffEntry = diff.next();
switch(diffEntry.changeType()) {
case ADDED:
++adds;
break;
case REMOVED:
++deletes;
break;
case MODIFIED:
++changes;
break;
}
}
ansi.fg(Color.GREEN).a(adds).reset().a(" features added, ").fg(Color.YELLOW).a(changes).reset().a(" changed, ").fg(Color.RED).a(deletes).reset().a(" deleted.").reset().newline();
console.print(ansi.toString());
}
use of org.locationtech.geogig.cli.CommandFailedException in project GeoGig by boundlessgeo.
the class Rebase method runInternal.
/**
* Executes the rebase command using the provided options.
*/
@Override
public void runInternal(GeogigCLI cli) throws IOException {
checkParameter(!(skip && continueRebase), "Cannot use both --skip and --continue");
checkParameter(!(skip && abort), "Cannot use both --skip and --abort");
checkParameter(!(abort && continueRebase), "Cannot use both --abort and --continue");
GeoGIG geogig = cli.getGeogig();
RebaseOp rebase = geogig.command(RebaseOp.class).setSkip(skip).setContinue(continueRebase).setAbort(abort).setSquashMessage(squash);
rebase.setProgressListener(cli.getProgressListener());
if (arguments == null || arguments.size() == 0) {
if (abort || skip || continueRebase) {
} else {
// Rebase onto remote branch
throw new UnsupportedOperationException("remote branch rebase not yet supported");
}
} else {
checkParameter(arguments.size() < 3, "Too many arguments specified.");
if (arguments.size() == 2) {
// Make sure branch is valid
Optional<ObjectId> branchRef = geogig.command(RevParse.class).setRefSpec(arguments.get(1)).call();
checkParameter(branchRef.isPresent(), "The branch reference could not be resolved.");
// Checkout <branch> prior to rebase
try {
geogig.command(CheckoutOp.class).setSource(arguments.get(1)).call();
} catch (CheckoutException e) {
throw new CommandFailedException(e.getMessage(), e);
}
}
Optional<Ref> upstreamRef = geogig.command(RefParse.class).setName(arguments.get(0)).call();
checkParameter(upstreamRef.isPresent(), "The upstream reference could not be resolved.");
rebase.setUpstream(Suppliers.ofInstance(upstreamRef.get().getObjectId()));
}
if (onto != null) {
Optional<ObjectId> ontoId = geogig.command(RevParse.class).setRefSpec(onto).call();
checkParameter(ontoId.isPresent(), "The onto reference could not be resolved.");
rebase.setOnto(Suppliers.ofInstance(ontoId.get()));
}
try {
rebase.call();
} catch (RebaseConflictsException e) {
StringBuilder sb = new StringBuilder();
sb.append(e.getMessage() + "\n");
sb.append("When you have fixed this conflicts, run 'geogig rebase --continue' to continue rebasing.\n");
sb.append("If you would prefer to skip this commit, instead run 'geogig rebase --skip.\n");
sb.append("To check out the original branch and stop rebasing, run 'geogig rebase --abort'\n");
throw new CommandFailedException(sb.toString());
}
if (abort) {
cli.getConsole().println("Rebase aborted successfully.");
}
}
Aggregations