Не удается клонировать удаленный репозиторий с помощью JGit для URL-адреса http

Проблема здесь в том, что 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


person aoswal    schedule 19.07.2017    source источник


Ответы (1)


С этим изменением: https://git.eclipse.org/r/#/c/46261/, который был объединен в феврале 2017 года, 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.

person Rüdiger Herrmann    schedule 19.07.2017
comment
@aoswal мой первоначальный ответ был не совсем правильным, посмотрите обновленный ответ. - person Rüdiger Herrmann; 21.07.2017