Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JGit http克隆存储库,但存储库可以';t拉动_Git_Http_Jgit - Fatal编程技术网

JGit http克隆存储库,但存储库可以';t拉动

JGit http克隆存储库,但存储库可以';t拉动,git,http,jgit,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, Invalid

克隆代码将显示为流动:

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();
下面是pull代码

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

它将很好地工作。

堆栈跟踪点在当前JGit源中没有任何意义。您使用哪个版本的JGit?除了NPE之外,pull命令将不起作用,因为没有设置凭据提供程序。我使用的JGit版本是3.1.0.201310021548-r,凭据是什么意思?谢谢,我应该在代码中设置凭据提供程序吗?你能给我举个例子吗?再次感谢。请像在CloneCommand中一样使用凭据提供程序:
pull.setCredentialsProvider(…)谢谢,它工作得很好。