java - 启用 git lfs 的 Jgit 克隆存储库无法正常工作

标签 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);
    }
}

最佳答案

这看起来与此错误有关:https://bugs.eclipse.org/bugs/show_bug.cgi?id=535814

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

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

关于java - 启用 git lfs 的 Jgit 克隆存储库无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47305430/

相关文章:

git - 我有一个困惑的 git 存储库。如何清洗?

java - Eclipse git 插件和获取当前分支的方法 - 将 id 提交到 Java 代码版本信息字符串

eclipse - 如何使用 EGit 将 eclipse 项目替换为 head 的最新版本?

java - 如何知道哪些文件已被修改以修复从 git 提交开始的错误?

java - Android上动态添加TextView到ScrollView

java - 为什么 Java 文件仅以规范形式存在?

git - 有没有办法克隆 git 存储库(包括其远程存储库)?

git - 获取远程仓库 Git

java - 创建单元测试用例时无法将 @Autowired 与 @Mock 一起使用

java - 如何为所有平台公开用 Java 编写的服务?