我在E中创建了一个目录,命名为gitrepo full path is(E:\ gitrepo)之后我用以下代码克隆了一个存储库
Git git=Git.cloneRepository()
.setURI("samplelink.git")
.setDirectory(new File("/E:/gitrepo"))
.call();
Run Code Online (Sandbox Code Playgroud)
然后我用这段代码打开了一个存储库
public Repository openRepository() throws IOException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File("/E:/gitrepo"))
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
log.info("Repository directory is {}", repository.getDirectory());
return repository;
}
Run Code Online (Sandbox Code Playgroud)
一切正常,直到这里我试图在这个本地存储库中添加一个文件
Repository repo = openRepository();
Git git = new Git(repo);
File myfile = new File(repo.getDirectory()/*.getParent()*/, "testfile");
if (!myfile.createNewFile()) {
throw new IOException("Could not create file " + myfile);
} …Run Code Online (Sandbox Code Playgroud)