我希望将一个远程的Atlassian BitBucket私有代码库克隆到我的电脑上。
您能否描述一下如何完成这个过程。
我特别关心认证过程。我是否需要使用(针对Atlassian BitBucket)
更新:
我尝试了以下方案:
您能否描述一下如何完成这个过程。
我特别关心认证过程。我是否需要使用(针对Atlassian BitBucket)
UsernamePasswordCredentialsProvider
作为 CredentialsProvider
,还是需要执行其他步骤才能完成?更新:
我尝试了以下方案:
SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(Host host, Session session) {
session.setPassword( "password" );
session.setConfig("StrictHostKeyChecking", "no");
}
};
CloneCommand cloneCommand = Git.cloneRepository();
cloneCommand.setURI("ssh://user@bitbucket.org/reponame.git");
//cloneCommand.setURI("git@bitbucket.org:user/reponame.git");
cloneCommand.setDirectory(new File("reponame"));
cloneCommand.setTransportConfigCallback(new TransportConfigCallback() {
@Override
public void configure(Transport transport) {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sshSessionFactory);
}
});
cloneCommand.call();
但是它会出现以下异常:
Exception in thread "main" org.eclipse.jgit.api.errors.TransportException: git@bitbucket.org:user/reponame.git: Auth fail
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:248)
at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:306)
at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:200)
at com.bitbucket.BitBucketTest.cloneViaSsh(BitBucketTest.java:63)
at com.bitbucket.BitBucketTest.main(BitBucketTest.java:39)
Caused by: org.eclipse.jgit.errors.TransportException: git@bitbucket.org:user/reponame.git: Auth fail
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:172)
at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:140)
at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:280)
at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:170)
at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:137)
at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:123)
at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1269)
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:237)
... 4 more
Caused by: com.jcraft.jsch.JSchException: Auth fail
at com.jcraft.jsch.Session.connect(Session.java:519)
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:126)
... 11 more