当前位置: 首页 > 知识库问答 >
问题:

使用JGit for http url克隆远程存储库失败

左丘源
2023-03-14

这里的问题是,URL 被重定向,这在 JGit 中不处理。没有相同的错误报告,并且还提到它们已得到解决,但我仍然面临此问题。如果我做错了什么,请告诉我。

代码片段

private static Git cloneRepository(String url, String branch, String targetPath) throws IOException {
    Git result = null;
    try {
        CloneCommand cloneCommand = Git.cloneRepository().setCloneSubmodules(true)
                                        .setURI(url).setBranch(branch)
                                        .setCloneSubmodules(true)
                                        .setDirectory(new File(targetPath));
        result = cloneCommand.call();
    } catch (GitAPIException e) {
        e.printStackTrace();
    }
    return result;
}

public static void main(String[] args) throws IOException {
    cloneRepository("http://github.com/google/mathfu", "master", "D:/codebase");
    //cloneRepository("https://github.com/google/mathfu", "master", "D:/codebase");
}

运行代码后出现异常

org.eclipse.jgit.api.errors.TransportException: 'http://github.com/google/mathfu': 301 Moved Permanently
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:245)
at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:293)
at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:190)
at com.acellere.demo.GitDemo.App.cloneRepository(App.java:21)
at com.acellere.demo.GitDemo.App.main(App.java:31)
Caused by: org.eclipse.jgit.errors.TransportException: 'http://github.com/google/mathfu': 301 Moved Permanently
at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:545)
at org.eclipse.jgit.transport.TransportHttp.openFetch(TransportHttp.java:326)
at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:136)
at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:122)
at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1236)
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:234)
... 4 more

更改以下代码后

//cloneRepository("http://github.com/google/mathfu", "master", "D:/codebase");
cloneRepository("https://github.com/google/mathfu", "master", "D:/codebase");

例外

org.eclipse.jgit.api.errors.TransportException: 'http://github.com/google/fplutil.git': 301 Moved Permanently
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:245)
at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:293)
at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:190)
at org.eclipse.jgit.api.SubmoduleUpdateCommand.call(SubmoduleUpdateCommand.java:177)
at org.eclipse.jgit.api.CloneCommand.cloneSubmodules(CloneCommand.java:372)
at org.eclipse.jgit.api.CloneCommand.checkout(CloneCommand.java:353)
at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:215)
at com.acellere.demo.GitDemo.App.cloneRepository(App.java:16)
at com.acellere.demo.GitDemo.App.main(App.java:25)
Caused by: org.eclipse.jgit.errors.TransportException: 'http://github.com/google/fplutil.git': 301 Moved Permanently
at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:545)
at org.eclipse.jgit.transport.TransportHttp.openFetch(TransportHttp.java:326)
at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:136)
at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:122)
at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1236)
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:234)
... 8 more

详情:

使用以下 JGit 版本 4.8.0.201706111038-r

也尝试了4.4.x.xxxxx版本

共有1个答案

谭勇
2023-03-14

通过此更改:https://git.eclipse.org/r/#/c/46261/,即在 2017 年 2 月合并,JGit 应该能够遵循 HTTP 301 状态代码(永久移动)。

然而,CloneCommand似乎还不起作用。我可以验证您的代码段是否抛出TransportException

相应的错误报告可以在这里找到:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=465167·https://bugs.eclipse.org/bugs/show_bug.cgi?id=474094

我在指向这篇文章的错误报告中添加了一条评论。

更新2017-08-18:错误已修复,将在JGit 4.9中发布

 类似资料:
  • 我有一个远程存储库,我试图使用它在本地进行克隆 这对于安装所有包和重新创建都很有效,但是我在最后得到了一个错误,这个错误似乎与Symfony2-中目录结构的变化有关 Sensio\Bundle\分布式包\Composer\ScriptHandler::buildBootstrap Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::cl

  • 假设您是其中一位团队成员,把现有的远程数据库克隆到另一个目录( tutorial2 )。 Windows 请双击桌面上的任意地方,然后从右击菜单中选择“Git克隆”。 点击“Clone Repository" 按钮,再输入要克隆的远程数据库的URL和要保存的本地数据库的目录,然后点击“确定”。 这样就把上一页面中创建的数据库,以“tutorial2”的名称进行了克隆。 克隆将在以下画面开始进行。完

  • 如果远程数据库中有他人的修改记录,那么把它完整地复制下来您就可以接着进行工作了。 克隆 进行克隆(Clone)操作就可以复制远程数据库。 执行克隆后,远程数据库的全部内容都会被下载。之后您在另一台机器的本地数据库上进行操作。 Note 克隆后的本地数据库的变更履历也会被复制,所以可以像原始的数据库一样进行查看记录或其他操作。

  • 下面的示例显示了如何列出远程标记,而无需克隆repo: 如何像上面的例子一样远程编辑/添加/删除新标签,而无需克隆存储库? 需要克隆回购协议。 有没有办法在不克隆回购协议的情况下实现这一点?

  • 问题内容: 我真的很坚持这一点。我在哈德森(Hudson)创建了一个工作,并以与其他工作相同的方式进行了配置。我的项目和构建交付物存在于Git中。但是每次我尝试构建它时,都会出现以下错误: 在其他线程中,有人建议通过以jenkins用户身份登录来创建不同的私钥-公钥对,但我什至不知道如何在终端中执行此操作。我的意思是我知道如何使用“ sudo”命令以不同的用户身份登录,但我不认为有人建议使用sud

  • 本文向大家介绍Git 克隆SVN存储库,包括了Git 克隆SVN存储库的使用技巧和注意事项,需要的朋友参考一下 示例 您需要使用以下命令创建存储库的新本地副本 git svn clone SVN_REPO_ROOT_URL [DEST_FOLDER_PATH] -T TRUNK_REPO_PATH -t TAGS_REPO_PATH -b BRANCHES_REPO_PATH 如果您的SVN储存库