JGit http克隆存储库但存储库无法拉动

时间:2014-04-21 13:38:10

标签: git http jgit

克隆代码流动:

private static final String REMOTE_URL = "http://localhost:8088/git/5.git";
private static String login = "xxxx@gmail.com";
private static String password = "123456";

public static Repository cloneRepository() throws IOException, InvalidRemoteException, TransportException, GitAPIException {

    File localPath = new File("E:/temp/TestGitRepositorygithub");
    System.out.println(localPath);
    if (!localPath.exists() && !localPath.isDirectory()) {
        localPath.mkdir();
    }
    localPath.delete();

    // then clone .setBranchesToClone(Arrays.asList("refs/heads/master"))
    System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
    CloneCommand clone = Git.cloneRepository().setURI(REMOTE_URL).setDirectory(localPath);
    if (REMOTE_URL.toString().contains("http") || REMOTE_URL.toString().contains("https")) {
        UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(login, password);
        clone.setCredentialsProvider(user);
    }

    Git repo1 = clone.call();

    for (Ref b : repo1.branchList().setListMode(ListMode.ALL).call())
        System.out.println("(standard): cloned branch " + b.getName());
    repo1.close();

下面的拉码

    File localPath = new File("E:/temp/TestGitRepositorygithub");
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository repository = builder.setGitDir(new File(localPath + "/.git")).readEnvironment().findGitDir().build();

    Git git = new Git(repository);
    PullCommand pull = git.pull();
    PullResult call = pull.call();

将报告以下异常

Exception in thread "main" java.lang.NullPointerException   
at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:477)
at org.eclipse.jgit.transport.TransportHttp.openFetch(TransportHttp.java:306)
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:1111)
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:130)
at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:248)

如果我像这样改变它

REMOTE_URL = "ssh://git@localhost:8999/5.git";

它会很好用。

0 个答案:

没有答案