我在使用 JGit 版本 3.0.0.201306101825-r 时遇到问题。这是我的克隆功能:
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();
}
我正在尝试从 gerrit 克隆一个存储库,每个人都可以访问它。'git clone ssh://gerrit.xx.com:29418/project/test' 从终端正常工作,但使用 Jgit 我无法克隆存储库。这是我得到的错误:
[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]
如何解决这个问题的想法非常受欢迎!