JGit Java通过ssh

时间:2017-09-13 15:43:09

标签: java git ssh jgit

嗨大家我在使用jGit库连接到提供的ssh服务器时遇到问题。我当前遇到的问题是"引起:org.eclipse.jgit.api.errors.JGitInternalException:目标路径"测试"已存在且不是空目录"请记住,我已查看http://www.codeaffine.com/2014/12/09/jgit-authentication/和其他stackoverflow帖子,他们的答案没有解决我的问题。是否有人可以协助我做错了什么?

    try
    {
        String user = "username";
        String host = "ssh://"+user+"@the.server.address/";
        String password = "password";

        SshSessionFactory sshSessionFactory = new JschConfigSessionFactory()
        {
            @Override
            protected void configure(Host hc, Session session)
            {
                session.setPassword(password);
            }
        };

        CloneCommand cloneCommand = Git.cloneRepository();

        cloneCommand.setURI(host);
        cloneCommand.setTransportConfigCallback(new TransportConfigCallback()
        {
            @Override
            public void configure(Transport transport)
            {
                SshTransport sshTransport = (SshTransport) transport;
                sshTransport.setSshSessionFactory(sshSessionFactory);
            }
        });
        cloneCommand.call();

    }
    catch (Exception e)
    {
        System.out.println(e.getMessage());
        System.out.println("Exception: " + e);
    }

我得到的错误:

Caused by: org.eclipse.jgit.api.errors.JGitInternalException: Destination path "THE LOCAL DIR PATH" already exists and is not an empty directory at
org.eclipse.jgit.api.CloneCommand.verifyDirectories(CloneCom‌​mand.java:243)at
org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:179‌​) at 
assignment.MainFXMLDocumentController.buttonWidgetViewAction‌​(MainFXMLDocumentCon‌​troller.java:136) ... 58 more

1 个答案:

答案 0 :(得分:0)

我使用几乎相同的代码,并遇到以下问题。 screenshot

奇怪的是,如果我将密码短语设置为空,那么它将起作用。