2011-12-17 18 views
7

Sto cercando di clonare il repository Git con JGit e ho un problema con UnsupportedCredentialItem.Repository clone JGit

Il mio codice:

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(); 

Avverrà Eccezione:

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).... 

Ma se elimino known_hosts di file in .ssh \ Avverrà Eccezione diversa

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).... 

C'è qualche possibilità di digitare "sì" a quella domanda o semplicemente saltarla?

Grazie!

risposta

4

penso che se si effettua il login con nome utente e password, è necessario https. Per ssh avrai bisogno di una chiave pubblica che corrisponda a quella registrata su github.

2

Ho avuto lo stesso problema. Il motivo era la passphrase impostata per la chiave privata rsa. Quando rimuovo passphrase per questa chiave, inizia a funzionare senza alcun CredentialsProvider.

UsernamePasswordCredentialsProvider probabilmente non supportano passphrase. Se si desidera avere insieme passphrase, è possibile definire si possiede CredentialProvider, che sosterrà, ad esempio:

CloneCommand clone = Git.cloneRepository() 
    .setURI("...") 
    .setCredentialsProvider(new CredentialsProvider() { 

     @Override 
     public boolean supports(CredentialItem... items) { 
      return true; 
     } 

     @Override 
     public boolean isInteractive() { 
      return true; 
     } 

     @Override 
     public boolean get(URIish uri, CredentialItem... items) 
       throws UnsupportedCredentialItem { 

      for (CredentialItem item : items) { 
        if (item instanceof CredentialItem.StringType) { 
         ((CredentialItem.StringType) item). 
          setValue(new String("YOUR_PASSPHRASE")); 
         continue; 
        } 
       } 
       return true; 
      } 
     }); 

clone.call(); 

Funziona per me;)

3

Questo lo farà (come @michals, solo meno codice) se si utilizza il nome utente/password con ssh

public void gitClone() throws GitAPIException { 
    final File localPath = new File("./TestRepo"); 
    Git.cloneRepository() 
     .setURI(REMOTE_URL) 
     .setDirectory(localPath) 
     .setCredentialsProvider(new UsernamePasswordCredentialsProvider("***", "***")) 
     .call(); 
}