I am working with jGit in Java and I have managed to clone an entire repository. But I can not find a way to download a single file inside a repository. I have tried:
- Change the URL specifying the path of the file.
- Change the URL by specifying a subdirectory.
Neither of them worked.
My code (clone whole repository) is as follows:
public File cloneRepository(String url, String path) throws GitAPIException {
File download = new File (path);
if (download.exists()){
System.out.println("Error");
return null;
}
else{
CloneCommand clone = Git.cloneRepository()
.setURI(url)
.setDirectory(download);
try (Git repositorio = clone.call()) {
return repositorio.getRepository().getWorkTree();
}
}
}
How could it be changed to download a single file?