Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.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
Java 获取远程地址的存储库对象_Java_Git_Jgit - Fatal编程技术网

Java 获取远程地址的存储库对象

Java 获取远程地址的存储库对象,java,git,jgit,Java,Git,Jgit,我尝试从URL地址获取存储库对象,JGit使用如下代码: Repository repository = Git.lsRemoteRepository() .setHeads(true) .setTags(true) .setRemote(url) .setCredentialsProvider(credentials) .getRepository(); 但是,对于该代码,存储库是null。另一方面,使用此代码 Collection<Ref>

我尝试从URL地址获取
存储库
对象,JGit使用如下代码:

Repository repository = Git.lsRemoteRepository()
    .setHeads(true)
    .setTags(true)
    .setRemote(url)
    .setCredentialsProvider(credentials)
    .getRepository();
但是,对于该代码,
存储库
null
。另一方面,使用此代码

Collection<Ref> refs = Git.lsRemoteRepository()
    .setHeads(true)
    .setTags(true)
    .setRemote(urlString)
    .setCredentialsProvider(credentials)
    .call();
Collection refs=Git.lsRemoteRepository()
.setHeads(正确)
.setTags(真)
.setRemote(urlString)
.setCredentialsProvider(凭据)
.call();
可以获得Ref对象的集合,该方法似乎适用于远程URL

我可以从Ref对象获取存储库对象吗?如何从Ref对象开始查找文件?

尝试以下操作:

String repoUrl = "https://github.com/GovindParashar136/SpringBootWithRestOpenIdClientAuthentication.git";
String cloneDirectoryPath = "/path/to/directory/"; // Ex.in windows c:\\gitProjects\SpringBootWithRestOpenIdClientAuthentication\
try {
    System.out.println("Cloning "+repoUrl+" into "+repoUrl);
    Git.cloneRepository()
        .setURI(repoUrl)
        .setDirectory(Paths.get(cloneDirectoryPath).toFile())
        .setCredentialsProvider(new UsernamePasswordCredentialsProvider("username", "password"))
        .call();
    System.out.println("Completed Cloning");
} catch (GitAPIException e) {
    System.out.println("Exception occurred while cloning repo");
    e.printStackTrace();
}
试试这个:

String repoUrl = "https://github.com/GovindParashar136/SpringBootWithRestOpenIdClientAuthentication.git";
String cloneDirectoryPath = "/path/to/directory/"; // Ex.in windows c:\\gitProjects\SpringBootWithRestOpenIdClientAuthentication\
try {
    System.out.println("Cloning "+repoUrl+" into "+repoUrl);
    Git.cloneRepository()
        .setURI(repoUrl)
        .setDirectory(Paths.get(cloneDirectoryPath).toFile())
        .setCredentialsProvider(new UsernamePasswordCredentialsProvider("username", "password"))
        .call();
    System.out.println("Completed Cloning");
} catch (GitAPIException e) {
    System.out.println("Exception occurred while cloning repo");
    e.printStackTrace();
}

JGit的
Repository
类表示本地存储库,通常是远程存储库的克隆

Git::lsRemoteRepository
返回的
LsRemoteCommand
在本地存储库的上下文之外运行,因此对于
getRepository
返回
null

JGit中的
Ref
也没有对存储库的引用,因为它们可能来自没有本地表示的存储库。请记住,例如,
LsRemoteCommand
返回的引用没有本地存储库

要对存储库进行任何有用的操作,首先需要对其进行克隆。例如,使用:

Git Git=Git.cloneRepository().setURI(url.call();
//通过git.getRepostory()访问存储库
git.close();
该代码相当于git clone。如果url是
https://host.org/repo.git
,该命令将在当前工作目录的
repo
子目录中创建克隆


有关使用JGit克隆存储库的更多详细信息,请参见此处:

JGit的
存储库
类表示本地存储库,通常是远程存储库的克隆

Git::lsRemoteRepository
返回的
LsRemoteCommand
在本地存储库的上下文之外运行,因此对于
getRepository
返回
null

JGit中的
Ref
也没有对存储库的引用,因为它们可能来自没有本地表示的存储库。请记住,例如,
LsRemoteCommand
返回的引用没有本地存储库

要对存储库进行任何有用的操作,首先需要对其进行克隆。例如,使用:

Git Git=Git.cloneRepository().setURI(url.call();
//通过git.getRepostory()访问存储库
git.close();
该代码相当于git clone。如果url是
https://host.org/repo.git
,该命令将在当前工作目录的
repo
子目录中创建克隆

有关使用JGit克隆存储库的更多详细信息,请参见: