9

JGit で Git リポジトリのクローンを作成しようとしていますが、UnsupportedCredentialItem に問題があります。

私のコード:

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

例外が発生します:

 org.eclipse.jgit.errors.UnsupportedCredentialItem: ssh://git@github.com:22: Passphrase for C:\Users\Marek\.ssh\id_rsa at
 org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider.get(UsernamePasswordCredentialsProvider.java:110)....

しかし、.ssh\ の known_hosts ファイルを削除すると、別の例外が発生します。

org.eclipse.jgit.errors.UnsupportedCredentialItem: ssh://git@github.com: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)....

その質問に「はい」と入力するか、単にスキップする可能性はありますか?

ありがとうございました!

4

7 に答える 7

5

ユーザー名とパスワードでログインする場合、https が必要だと思います。ssh の場合、github に記録されているものと一致する公開鍵が必要です。

于 2012-04-06T01:15:38.803 に答える
3

githubのヘルプを確認したいと思うでしょう:

http://help.github.com/win-set-up-git/

特に、ssh キーの生成に関する部分 ( ssh-keygen -t rsa -C "your_email@youremail.com")。お使いの環境の記事を読むと、より適切な構成を取得する方法が理解できます。

于 2011-12-19T22:51:00.557 に答える
3

sshでユーザー名/パスワードを使用する場合、これで実行できます(@michalsのように、コードが少ないだけです)

public void gitClone() throws GitAPIException {
    final File localPath = new File("./TestRepo");
    Git.cloneRepository()
        .setURI(REMOTE_URL)
        .setDirectory(localPath)
        .setCredentialsProvider(new UsernamePasswordCredentialsProvider("***", "***"))
        .call();
}
于 2014-01-12T20:00:23.807 に答える
2

私も同じ問題を抱えていました。その理由は、rsa 秘密鍵に設定されたパスフレーズでした。このキーのパスフレーズを削除すると、何もせずに機能し始めましたCredentialsProvider

UsernamePasswordCredentialsProviderおそらくパスフレーズをサポートしていません。パスフレーズを設定したい場合は、それをサポートする独自の CredentialProvider を定義できます。次に例を示します。

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

わたしにはできる ;)

于 2013-06-14T12:51:53.097 に答える