使用git lfs启用的Jgit克隆无法正常工作

时间:2017-11-15 10:49:09

标签: java git-clone jgit git-lfs

当前设置

我有一个存储库,它启用了git lfs。存在用于访问存储lfs内容的驱动器的另一级别的认证。当我从命令提示符运行以下代码时,它会询问用于访问lfs内容的用户名和密码,如下所示。

JGIT LFS issue

如果我们使用另一个没有对lfs内容进行身份验证的存储库,那么一切正常。 请告诉我如何禁止JGIT的身份验证或如何跳过LFS内容的获取。 如果我做错了,请告诉我。

详细说明:
1)使用以下JGit版本4.9.0.201710071750-r
2)安装了git lfs

代码段

public static void syncRepository(String uname, String pwd, String url, String destDir) throws Exception{
    String branch =  "refs/heads/master";
    System.out.println("Cloning from ["+url+"] branch ["+branch+"] to ["+destDir.toString()+"]");
    String workingDirPath = null;
    try {
        if (StringUtils.isNotEmpty(destDir)) {
            workingDirPath = FilenameUtils.normalize(destDir);
        } else {
            throw new Exception("Working directory for code sync not found : " + destDir);
        }
        Path path = Paths.get(workingDirPath);
        System.out.println("Deleting '" +workingDirPath+ "' and re-creating empty destination dir" );
        recursivelyDelete(path.toFile());
        Files.createDirectories(Paths.get(workingDirPath));
        Path targetPath = path.resolve("");

        // clone repository
        Git git = cloneRepository(url, uname, pwd, branch, targetPath);
        System.out.println("Git revision # " + getLastHash(git));
        System.out.println("SYNC Repository completed");
    } catch (GitAPIException e) {
        // if the import fails then we should try to remove the created directory
        System.out.println("Failed to clone git repository."+ e);
        throw new Exception("Failed to clone git repository", e);
    }
}
private static Git cloneRepository(String url, String username, String password, String branch, Path targetPath)
        throws Exception {
    Git result;
    try {
        CloneCommand cloneCommand = Git.cloneRepository()
                .setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out)))
                .setURI(url).setBranch(branch)
                .setDirectory(targetPath.toFile())
                .setTimeout(300)
                .setTransportConfigCallback(new TransportConfigCallback() {
                    public void configure(Transport transport) {
                        transport.setTimeout(300);
                    }
                });
        setCredentials(cloneCommand, username, password);
        result = cloneCommand.call();
        return result;
    } catch (GitAPIException e) {
        // if the import fails then we should try to remove the created directory
        throw new Exception("Failed to clone git repository", e);
    }
}

1 个答案:

答案 0 :(得分:0)

这似乎与以下错误有关:https://bugs.eclipse.org/bugs/show_bug.cgi?id=535814

查看代码,SmudgeFilter.downloadLfsResource()使用getLfsConnection()处理SSH身份验证,但不处理HTTP身份验证。

至少在我的测试中,下载失败并显示401异常(未经授权),而不是提示输入凭据。