【问题标题】:Cloning remote repository fails using JGit for http url使用 JGit for http url 克隆远程存储库失败
【发布时间】:2017-12-24 21:57:15
【问题描述】:

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

代码片段

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 版本

【问题讨论】:

    标签: git-clone jgit


    【解决方案1】:

    有了这个更改:https://git.eclipse.org/r/#/c/46261/,它于 2017 年 2 月合并,JGit 应该能够遵循 HTTP 301 状态代码(永久移动)。

    但是,CloneCommand 似乎还没有工作。我可以验证您的代码 sn-p 是否会抛出 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 中发布

    【讨论】:

    • @aoswal 我原来的答案不太正确,请查看更新后的答案。
    猜你喜欢
    • 2020-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多