1
我只是試圖開始與JGit一起工作,現在我堅持着一個奇怪的異常,同時做了大部分基本的事情。JGitInternalException添加文件時
我的代碼:
public class JGitTest {
public static void main(String[] args) throws Exception {
File worktree = new File(
"C:\\Users\\nils\\Desktop\\tmp\\gittest\\jgittest");
File repodir = new File(worktree, ".git");
Repository repository = FileRepositoryBuilder.create(repodir);
Git git = new Git(repository);
git.add().addFilepattern(".").call();
}
}
我得到下面的異常,在執行這段代碼時:
Exception in thread "main" org.eclipse.jgit.api.errors.JGitInternalException: Exception caught during execution of add command
at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:212)
at de.njo.test.JGitTest.main(JGitTest.java:18)
Caused by: java.io.IOException: Das System kann den angegebenen Pfad nicht finden
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createTempFile(Unknown Source)
at org.eclipse.jgit.internal.storage.file.ObjectDirectoryInserter.newTempFile(ObjectDirectoryInserter.java:233)
at org.eclipse.jgit.internal.storage.file.ObjectDirectoryInserter.toTemp(ObjectDirectoryInserter.java:199)
at org.eclipse.jgit.internal.storage.file.ObjectDirectoryInserter.insert(ObjectDirectoryInserter.java:91)
at org.eclipse.jgit.internal.storage.file.ObjectDirectoryInserter.insert(ObjectDirectoryInserter.java:102)
at org.eclipse.jgit.api.AddCommand.call(AddCommand.java:188)
... 1 more
我得到一個非常類似的異常,運行Java EE服務器上的這個片段時。我的錯誤在哪裏?
編輯:進一步的信息:
- 創建的存儲庫是完全空(無目錄:掛鉤,頭或 任何東西)
- 我使用JGit v3.7.0.201502260915-R
您是否打算在'C:\ Users \ nils \ Desktop \ tmp \ gittest \ jgittest'中創建一個存儲庫(即'git init'),或者該目錄是否已經包含一個存儲庫?儘管它的名字是'FileRepositoryBuilder.create()'不會創建一個存儲庫。要初始化存儲庫,請使用'Git.init()。setDirectory(「c:\ users \ ...」).call()'。 –
是的,我想做一個「git init」...我會嘗試你的建議。 –
它確實有效,但讓我非常疑惑...根據這個網站:https://git-scm.herokuapp.com/book/en/v2/Embedding-Git-in-your-Applications-JGit,FileRepositoryBuilder。創建(repodir)是去一個新的存儲庫的方式... –