当前设置
我有一个已启用 git lfs 的存储库。访问存储 lfs 内容的驱动器时还存在另一级身份验证。当我从命令提示符运行以下代码时,它会要求输入用户名和密码来访问 lfs 内容,如下所示。
如果我们使用另一个没有对 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/