Cloning remote repository fails using JGit for http url

不打扰是莪最后的温柔 提交于 2019-12-11 01:37:10

问题


The problem here is, URL is redirected which is not handled in JGit. There are no of bugs reported for same and it is also mentioned that they are resolved but I am still facing this issue. Please let me know if I am doing anything wrong.

Code Snippet

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");
}

Exception after running the code

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

After changing following code


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

Exception

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

Details:

using following JGit version 4.8.0.201706111038-r

Also tried with version 4.4.x.xxxxx too


回答1:


With this change: https://git.eclipse.org/r/#/c/46261/, that was merged in February 2017, JGit should be able to follow HTTP 301 status codes (moved permanently).

However, the CloneCommand does not seem to work yet. I can verify that your code snippet throws a TransportException.

The corresponding bug reports can be found here:

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

I have added a comment to the bug report that points to this post.

Update 2017-08-18: the bug is fixed and will be released in JGit 4.9



来源:https://stackoverflow.com/questions/45193770/cloning-remote-repository-fails-using-jgit-for-http-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!