你需要做这样的事情:
private static final class RepositoryResolverImplementation implements
RepositoryResolver<DaemonClient> {
@Override
public Repository open(DaemonClient client, String name)
throws RepositoryNotFoundException,
ServiceNotAuthorizedException, ServiceNotEnabledException,
ServiceMayNotContinueException {
InMemoryRepository repo = repositories.get(name);
if (repo == null) {
repo = new InMemoryRepository(
new DfsRepositoryDescription(name));
repositories.put(name, repo);
}
return repo;
}
}
private static Map<String, InMemoryRepository> repositories = new HashMap<String, InMemoryRepository>();
public static void main(String[] args) throws IOException {
Daemon server = new Daemon(new InetSocketAddress(9418));
boolean uploadsEnabled = true;
server.getService("git-receive-pack").setEnabled(uploadsEnabled);
server.setRepositoryResolver(new RepositoryResolverImplementation());
server.start();
}
然后您应该能够运行git clone git://localhost/repo.git
并且将创建一个新的内存中的“repo.git”存储库。如果要上传,请确保将 uploadsEnabled 设置为“true” - 默认情况下,它设置为“false”。