2017-07-19 83 views
2

這裏的問題是,URL被重定向,而不是在JGit中處理。沒有報告相同的錯誤,也提到它們已經解決,但我仍然面臨這個問題。請讓我知道如果我做錯了什麼。運行代碼克隆遠程存儲庫失敗使用JGit的http url

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 

改變下面的代碼

後後

代碼段

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

異常


//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

隨着這一變化的嘗試: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年8月18日:的bug是固定的,並會在JGit 4.9

+0

發佈@aoswal我原來的答覆是不完全正確,請查看更新的答案。 –

相關問題