如何为jgit设置jschconfigsessionfactory的配置,以便拉动和推送工作? [英] How do you set the configuration for jschconfigsessionfactory for jgit so that pull and push work?
问题描述
我正在尝试使用带有以下代码的jgit的api执行git pull / push
I am trying to do a git pull/push using jgit's api with the following code
org.eclipse.jgit.api.Git.open(theRepoFile).pull().call()
但是我得到例外
JSchException Auth fail
com.jcraft.jsch.Session.connect (Session.java:461)
org.eclipse.jgit.transport.JschConfigSessionFactory.getSession (JschConfigSessionFactory.java:116)
org.eclipse.jgit.transport.SshTransport.getSession (SshTransport.java:121)
org.eclipse.jgit.transport.TransportGitSsh$SshPushConnection.<init> (TransportGitSsh.java:306)
org.eclipse.jgit.transport.TransportGitSsh.openPush (TransportGitSsh.java:152)
org.eclipse.jgit.transport.PushProcess.execute (PushProcess.java:130)
org.eclipse.jgit.transport.Transport.push (Transport.java:1127)
org.eclipse.jgit.api.PushCommand.call (PushCommand.java:153)
尽管使用cgit pull and push工作。
Even though using cgit pull and pushing works.
我试过检查SO以获取示例代码
I tried checking SO for example code
但上述问题并未提供完整的编码示例,说明使用通常经过身份验证的远程仓库进行git pull所需的操作通过ssh键。应该有办法从〜/ .ssh /
或等效的Windows中获取凭证信息。
but the above question does not provide a complete coded example of what is necessary to do a git pull with a remote repo that is normally authenticated via ssh keys. There should be a way to get the credential information from ~/.ssh/
or the windows equivalent.
推荐答案
问题是Jsch不支持 ssh-agent
s开箱即用。人们需要配置 https://github.com/ymnk/jsch-agent-proxy让它工作。
The problem is Jsch does not support ssh-agent
s out of the box. One will need to configure https://github.com/ymnk/jsch-agent-proxy to get it to work.
另一种方法是制作你自己的 org.eclipse.jgit.transport.CredentialsProvider
并将 org.eclipse.jgit.transport.CredentialItem
设置为正确的值(通过向用户请求或查找文件)。您可以使用 org.eclipse.jgit.transport.CredentialsProvider / setDefault
An alternative is to make your own org.eclipse.jgit.transport.CredentialsProvider
and set the org.eclipse.jgit.transport.CredentialItem
to the correct values (by requesting them from the user or looking up a file). You can change the default CredentialsProvider
with org.eclipse.jgit.transport.CredentialsProvider/setDefault
有关详细信息,请参阅我的clojure库dj: https://github.com/bmillare/dj/blob/library/src/dj/git.clj
See my clojure library dj for details: https://github.com/bmillare/dj/blob/library/src/dj/git.clj
这篇关于如何为jgit设置jschconfigsessionfactory的配置,以便拉动和推送工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!