简体   繁体   English

jGit从Java克隆远程git存储库

[英]jGit clone remote git respository from Java

I am using the below java code to clone a git repo. 我正在使用下面的Java代码来克隆git repo。

localRepo = new FileRepository("/Users/myfolder/git" + "/.git");
            git = new Git(localRepo);
                   Git.cloneRepository().setURI("git@github.com:mygit/TestGit.git")
                    .setDirectory(new File("/Users/myfolder/git")).call();

I can see the project cloned in the folder /Users/myfolder/git, but in the console log I see the exception 我可以在文件夹/ Users / myfolder / git中看到克隆的项目,但是在控制台日志中看到了异常

fatal: Could not switch to

Any idea why the exception is being thrown even though everything works fine? 知道即使一切正常,为什么仍会引发异常?

That error comes from git itself in abspath.c#real_path_internal() , which returns the real path (ie, absolute path, with symlinks resolved and extra slashes removed) equivalent to the specified path. 该错误来自abspath.c#real_path_internal() git本身,它返回与指定路径等效的真实路径(即,绝对路径,已解析符号链接并去除了多余的斜杠)。

Make sure you are using an absolute path, and try using /Users/myfolder/git (without .git ), as in this cookbook example . 确保您使用的是绝对路径,然后尝试使用/Users/myfolder/git (不带.git ),如本食谱示例所示

不需要git Git结果= Git.cloneRepository()。setURI(REMOTE_URL).setDirectory(localPath).call()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM