1

I am having problems with JGit version 3.0.0.201306101825-r. Here is my clone function:

public static void cloneRepository(String localRepositoryPath, String remoteRepositoryURI, String branch, String username, String password) throws IOException, InvalidRemoteException, GitAPIException {
    File workDir = createFolder(localRepositoryPath);
    CloneCommand clone = Git.cloneRepository();
    clone.setBare(false);
    clone.setCloneAllBranches(false);
    clone.setBranch(branch);
    clone.setDirectory(workDir).setURI(remoteRepositoryURI);
    if (StringUtils.isNotEmpty(username)) {
        UsernamePasswordCredentialsProvider credentials = new UsernamePasswordCredentialsProvider(username, password);
        clone.setCredentialsProvider(credentials);
    }
    Git git = clone.call();
}

I am trying to clone a repository from gerrit with everyone having access to read it. 'git clone ssh://gerrit.xx.com:29418/project/test' works correctly from terminal but with Jgit I cannot clone the repository. This is what I am getting as an error:

[INFO] [talledLocalContainer] Caused by: org.eclipse.jgit.errors.TransportException: ssh://gerrit.xx.com:29418/project/test: Auth fail
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:142) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:121) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:248) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:147) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:136) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:122) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1105) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:128) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   ... 55 more
[INFO] [talledLocalContainer] Caused by: com.jcraft.jsch.JSchException: Auth fail
[INFO] [talledLocalContainer]   at com.jcraft.jsch.Session.connect(Session.java:491) [jsch-0.1.49.jar:]
[INFO] [talledLocalContainer]   at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:116) [org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
[INFO] [talledLocalContainer]   ... 62 more
[INFO] [talledLocalContainer] 

Ideas how to fix this are more than welcome!

Beryllium
  • 12,808
  • 10
  • 56
  • 86
drodil
  • 2,292
  • 1
  • 22
  • 37

2 Answers2

4

I think git clone ssh://gerrit.xx.com:29418/project/test works because it uses the logged in user name on the client maschine and performs a key based authentication against gerrit.

In general you can not perform any anonymous communication using ssh. JGit may not know about its environment and you have to explicitly provide a username as well as an appropriate ssh key, especially when you run your Java code outside a ssh enabled user context. Using UsernamePasswordCredentialsProvider will not work at all using ssh to access gerrit.

I would suggest that you use HTTP for anonymous read access to gerrit. git clone http://gerrit.xx.com:[port]/test should do the job. Wher [port] is the port your gerrit installation listens for HTTP requests. I think default ist 8080.

roehrijn
  • 1,387
  • 1
  • 11
  • 20
1

If you're not using a program like Eclipse which has the support in place, you might try running your process with GIT_SSH set to an external executable, which may do the authentication on your behalf.

AlBlue
  • 23,254
  • 14
  • 71
  • 91