use of org.locationtech.geogig.api.porcelain.CloneOp in project GeoGig by boundlessgeo.
the class BranchListOpTest method setUpInternal.
@Override
protected void setUpInternal() throws Exception {
// Commit several features to the remote
insertAndAdd(remoteGeogig.geogig, points1);
remoteGeogig.geogig.command(CommitOp.class).call();
// Create and checkout branch1
remoteGeogig.geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("Branch1").call();
// Commit some changes to branch1
insertAndAdd(remoteGeogig.geogig, points2);
remoteGeogig.geogig.command(CommitOp.class).call();
insertAndAdd(remoteGeogig.geogig, points3);
remoteGeogig.geogig.command(CommitOp.class).call();
// Checkout master and commit some changes
remoteGeogig.geogig.command(CheckoutOp.class).setSource("master").call();
insertAndAdd(remoteGeogig.geogig, lines1);
remoteGeogig.geogig.command(CommitOp.class).call();
insertAndAdd(remoteGeogig.geogig, lines2);
remoteGeogig.geogig.command(CommitOp.class).call();
// clone from the remote
CloneOp clone = clone();
clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).setBranch("Branch1").call();
}
use of org.locationtech.geogig.api.porcelain.CloneOp 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.api.porcelain.CloneOp in project GeoGig by boundlessgeo.
the class FetchOpTest method prepareForFetch.
private void prepareForFetch(boolean doClone) throws Exception {
if (doClone) {
// clone the repository
CloneOp clone = clone();
clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
}
// 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 = Lists.newArrayList(logs);
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);
//
remoteGeogig.geogig.command(TagCreateOp.class).setMessage(//
"TestTag").setCommitId(//
commit.getId()).setName(//
"test").call();
// Make sure master has all of the commits
logs = remoteGeogig.geogig.command(LogOp.class).call();
logged = Lists.newArrayList(logs);
assertEquals(expectedMaster, logged);
}
use of org.locationtech.geogig.api.porcelain.CloneOp in project GeoGig by boundlessgeo.
the class FetchOpTest method testFetchNewRefWithShallowClone.
@Test
public void testFetchNewRefWithShallowClone() 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();
RevCommit originCommit = commit;
expectedMaster.addFirst(commit);
expectedBranch.addFirst(commit);
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
Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
List<RevCommit> logged = Lists.newArrayList(logs);
assertEquals(expectedMaster, logged);
// clone the repository
CloneOp clone = clone();
clone.setDepth(2);
clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
// Create and checkout branch1
remoteGeogig.geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("Branch1").setSource(originCommit.getId().toString()).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
logs = remoteGeogig.geogig.command(LogOp.class).call();
logged = Lists.newArrayList(logs);
assertEquals(expectedBranch, logged);
FetchOp fetch = fetch();
fetch.call();
// Make sure the local repository got all of the commits from master
localGeogig.geogig.command(CheckoutOp.class).setSource("refs/remotes/origin/master").call();
logs = localGeogig.geogig.command(LogOp.class).call();
logged = Lists.newArrayList(logs);
assertEquals(2, logged.size());
assertEquals(expectedMaster.get(0), logged.get(0));
assertEquals(expectedMaster.get(1), logged.get(1));
// Make sure the local repository got all of the commits from Branch1
localGeogig.geogig.command(CheckoutOp.class).setSource("refs/remotes/origin/Branch1").call();
logs = localGeogig.geogig.command(LogOp.class).call();
logged = Lists.newArrayList(logs);
assertEquals(2, logged.size());
assertEquals(expectedBranch.get(0), logged.get(0));
assertEquals(expectedBranch.get(1), logged.get(1));
}
use of org.locationtech.geogig.api.porcelain.CloneOp in project GeoGig by boundlessgeo.
the class FetchOpTest method testFetchDepth.
@Test
public void testFetchDepth() throws Exception {
prepareForFetch(false);
// clone the repository
CloneOp clone = clone();
clone.setDepth(2);
String repositoryURL = remoteGeogig.envHome.getCanonicalPath();
clone.setRepositoryURL(repositoryURL).call();
FetchOp fetch = fetch();
fetch.setDepth(3);
fetch.call();
// Make sure the local repository got all of the commits from master
localGeogig.geogig.command(CheckoutOp.class).setSource("refs/remotes/origin/master").call();
Iterator<RevCommit> logs = localGeogig.geogig.command(LogOp.class).call();
List<RevCommit> logged = Lists.newArrayList(logs);
assertEquals(3, logged.size());
assertEquals(expectedMaster.get(0), logged.get(0));
assertEquals(expectedMaster.get(1), logged.get(1));
assertEquals(expectedMaster.get(2), logged.get(2));
// Make sure the local repository got all of the commits from Branch1
localGeogig.geogig.command(CheckoutOp.class).setSource("refs/remotes/origin/Branch1").call();
logs = localGeogig.geogig.command(LogOp.class).call();
logged = Lists.newArrayList(logs);
assertEquals(3, logged.size());
assertEquals(expectedBranch.get(0), logged.get(0));
assertEquals(expectedBranch.get(1), logged.get(1));
assertEquals(expectedBranch.get(2), logged.get(2));
}
Aggregations