JGit clone repository

Scruger picture Scruger · Dec 17, 2011 · Viewed 18.2k times · Source

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!

Answer

moger777 picture moger777 · Apr 6, 2012

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.