Я просто попытался начать работать с JGit, и теперь я застрял со странным исключением, делая самые основные вещи.
Мой код:
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-сервере. Где моя ошибка?
EDIT: Дополнительная информация:
Причиной JGitInternalException
является отсутствие репозитория в указанном месте.
Несмотря на свое имя, FileRepositoryBuilder.create()
не создает (т.е. git init
) репозиторий. FileRepositoryBuilder
может использоваться только для создания экземпляров Repository
(класса, представляющего репозиторий в JGit) для существующих репозиториев git. Подробнее об этом здесь.
Чтобы инициализировать новый репозиторий, используйте
Git git = Git.init().setDirectory( "c:\users\..." ).call();
И не забудьте git.close()
репозиторий, как только вы закончите использовать его.
C:\Users\nils\Desktop\tmp\gittest\jgittest
ли вы создать хранилище (например,git init
) вC:\Users\nils\Desktop\tmp\gittest\jgittest
или каталог уже содержит хранилище? Несмотря на свое имя,FileRepositoryBuilder.create()
не создает хранилище. Чтобы инициализировать репозиторий, используйтеGit.init().setDirectory( "c:\users\..." ).call()
.