java - 在代码中传递 git url 时出现 InvalidPathException
问题描述
在我的代码中传递 url 时,我收到 java.nio.file.InvalidPathException 。我尝试了正斜杠和反斜杠,但仍然遇到同样的错误。代码-
import java.io.File;
import java.io.IOException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
public class testInAction
{
public static void main(String[] args) throws IOException
{
FileRepositoryBuilder builder = new FileRepositoryBuilder();
String repoUrl = "http://stash.gto.intranet.db.com:8081/projects/PARAGON/repos/paragongit/browse";
Repository repository = builder.setGitDir(new File(repoUrl)).readEnvironment().findGitDir().build();
listRepositoryContents(repository);
repository.close();
}
private static void listRepositoryContents(Repository repository) throws IOException {
for (Ref head : repository.getAllRefs().values()) {
String refName = head.getName();
ObjectId objId = head.getObjectId();
System.out.println("refName " + refName);
System.out.println("objId " + objId);
}
}
}
这可能是什么原因......建议一些
解决方案
根据我的阅读,输入setGitDir
应该是本地Git 存储库的相对或绝对路径,而不是远程存储库。因此,在那里使用远程 URL 没有任何意义,File(...)
使用 URL 调用也没有任何意义。尝试以下方式:
FileRepositoryBuilder builder = new FileRepositoryBuilder();
String gitPath = "\path\to\your\git\folder";
Repository repository = builder.setGitDir(new File(gitPath))
.readEnvironment().findGitDir().build();
listRepositoryContents(repository);
repository.close();
推荐阅读
- python - 无法从网页解析页面源中可用的字段
- php - 自动将带有值的新行添加到从 mysql 生成的 csv 文件中
- java - “getOnItemSelectedListener”方法不适用于微调器
- javascript - Javascript ArrayBuffer-无法将空值设置为arraybuffer
- python - 你怎么提
- google-chrome - 如何解析谷歌浏览器性能记录文件
- sql - 如何对不同分组下的同一列求和
- javascript - 添加 HTML 直到达到要求
- c - 为什么我可以用这个非法的 C 语句编译而没有任何错误?
- visual-studio-code - vscode到处给我无效的符号错误