我正在尝试使用JGit克隆git存储库。
public static void main(String[] args) throws IOException, InvalidRemoteException, GitAPIException {
String name = "username";
String password = "password";
remotePath = "https://user@stash.gto.intranet.db.com:8081/scm/paragon/paragongit.git";
CredentialsProvider cp = new UsernamePasswordCredentialsProvider(name, password);
File localPath = new File("C:/Users/13 dec/");
if (!localPath.delete()) {
throw new IOException("Could not delete temporary file" + localPath);
}
System.out.println("localPath " + localPath.getAbsolutePath());
System.out.println("Cloning from" + remotePath + "to" + localPath);
Git git = Git.init().setDirectory(localPath).call();
System.out.println("The End");
Git result = Git.cloneRepository().setURI(remotePath).setDirectory(localPath).setCredentialsProvider(cp).call();
System.out.println("The end of program");
}
但是我收到了JGitInternalException
Error->Exception in thread "main" org.eclipse.jgit.api.errors.JGitInternalException: Destination path "13 dec" already exists and is not an empty directory
at org.eclipse.jgit.api.CloneCommand.verifyDirectories(CloneCommand.java:253)
at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:189)
at testInAction.main(testInAction.java:39)
答案 0 :(得分:1)
错误消息告诉您您正在尝试在现有非空目录的顶部克隆git repo。
您不能那样做。而且您也无法通过从命令行运行git clone
来做到这一点;查看https://stackoverflow.com/a/42561781/139985
基本上,git
试图阻止您用脚射击。
答案 1 :(得分:0)
当我们在C:\ Users中创建目录时,将其创建为只读目录,即使使用从Windows正常删除,我们也需要管理员权限才能删除它。