首页 > 解决方案 > 线程“主”java.io.JGitInternalException 中的异常:无法删除临时文件 C:\Users\13 dec

问题描述

我正在尝试使用 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)

标签: jgit

解决方案


错误消息告诉您,您正在尝试在现有非空目录的顶部克隆 git 存储库。

你不能那样做。而且你也不能通过git clone从命令行运行来做到这一点;请参阅https://stackoverflow.com/a/42561781/139985上的评论

基本上,git是试图阻止你在脚下射击自己。


推荐阅读