Reputation: 1257
I just tried to start working with JGit and am now stuck with a strange exception, while doing most basic things.
My code:
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();
}
}
I get the following exception, when executing this snippet:
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
I get a very similar exception, when running this snippet on a Java EE-server. Where is my mistake?
EDIT: Further informations:
Upvotes: 1
Views: 1820
Reputation: 20985
The reason for the JGitInternalException
is that there is no repository at the specified location.
Despite its name, FileRepositoryBuilder.create()
does not create (i.e. git init
) a repository. The FileRepositoryBuilder
can only be used to create instances of Repository
(the class that represents a repository in JGit) for existing git repositories. Read more on this here.
To initialize a new repository, use
Git git = Git.init().setDirectory( "c:\users\..." ).call();
And don't forget to git.close()
the repository once you are done using it.
Upvotes: 1