Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JGit clone repository

I'm trying to clone Git repository with JGit and I have problem with UnsupportedCredentialItem.

My code:

FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(PATH).readEnvironment().findGitDir().build();

Git git = new Git(repository);              
CloneCommand clone = git.cloneRepository();
clone.setBare(false);
clone.setCloneAllBranches(true);
clone.setDirectory(PATH).setURI(url);
UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(login, password);                
clone.setCredentialsProvider(user);
clone.call();   

It will occur Exception:

 org.eclipse.jgit.errors.UnsupportedCredentialItem: ssh://[email protected]:22: Passphrase for C:\Users\Marek\.ssh\id_rsa at
 org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider.get(UsernamePasswordCredentialsProvider.java:110)....

But if I delete file known_hosts in .ssh\ It will occur different Exception

org.eclipse.jgit.errors.UnsupportedCredentialItem: ssh://[email protected]:22: The authenticity of host 'github.com' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting?
at org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider.get(UsernamePasswordCredentialsProvider.java:110)....

Is there any possibility to type "yes" to that question or just skip it?

Thank you!

like image 217
Scruger Avatar asked Dec 17 '11 14:12

Scruger


People also ask

How do I clone a JGit repository?

build(); Git git = new Git(repository); CloneCommand clone = git. cloneRepository(); clone. setBare(false); clone. setCloneAllBranches(true); clone.

What is JGit used for?

JGit is a pure Java implementation of the Git version control system. It powers many Git related Java projects like the Git support in Eclipse or the Gerrit reviewer server. JGit is available as Java library and can be integrated into your project with the usual methods.

How do you clone a Phabricator repo?

Make sure SSH serving is enabled for the repository you're trying to clone. You can change this setting from a main repository screen in Diffusion by Edit Repository → Edit Hosting → Host Repository on Phabricator → Save and Continue → SSH Read Only or Read/Write → Save Changes.


2 Answers

It is not clear to me whether you want to do username/password authentication or public/private key authentication. Either way, CredentialsProvider will not be used, according to this. You need to configure the transport. First, create a transport configuration callback:

SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
  @Override
  protected void configure( Host host, Session session ) {
    // If you are using username/password authentication, add the following line
    session.setPassword( "password" );
  }
} );

TransportConfigCallback transportConfigCallback = new TransportConfigCallback() {
  @Override
  public void configure( Transport transport ) {
    SshTransport sshTransport = ( SshTransport )transport;
    sshTransport.setSshSessionFactory( sshSessionFactory );
  }
};

Then configure the command with it:

clone.setTransportConfigCallback( transportConfigCallback );
like image 63
Daniel C. Sobral Avatar answered Sep 20 '22 15:09

Daniel C. Sobral


I think if you login with username and password, you need https. For ssh you will need a public key that matches the one on record with github.

like image 38
moger777 Avatar answered Sep 22 '22 15:09

moger777