Skip to content

Instantly share code, notes, and snippets.

@timothyklim
Created February 23, 2012 17:48
Show Gist options
  • Save timothyklim/1893998 to your computer and use it in GitHub Desktop.
Save timothyklim/1893998 to your computer and use it in GitHub Desktop.
JGit test with DHT
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
public class Main {
static public void main(String[] args) throws IOException, URISyntaxException, InvalidRemoteException {
Repository repo = org.gitective.mongo.MongoDatabase.open("git_repo_test");
try {
repo.create(true);
}
catch ( org.eclipse.jgit.storage.dht.DhtException e) {}
StoredConfig config = repo.getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
URIish uri = new URIish("file://" + System.getProperty("user.dir") + "/test_git_repo");
remoteConfig.addURI(uri);
remoteConfig.update(config);
config.save();
repo.close();
// This code works only for non-dht code, but how I can clone repo from MongoDB? :3
// CloneCommand cloneCommand = new CloneCommand();
// cloneCommand.setURI(repo.getDirectory().getPath());
// cloneCommand.setDirectory(new File("/tmp/for_git_test"));
// cloneCommand.setBare(false);
// cloneCommand.call();
}
}
@kevinsawicki
Copy link

There currently isn't a way to do this besides hosting the repository backed by mongo using the JGit http server and cloning from there. You would just need to the JGit HTTP server to use the Mongo repository.

@timothyklim
Copy link
Author

OK, I will learn code deeper for cloning without http server(jgit servlet).
Thanks for help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment