Reputation: 61
I am trying a simple java class to test the functionality of jGit (see below).
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import java.io.File;
import java.io.IOException;
public class CreateRepository {
public static void main( String[] args ){
Repository myrepo = createRepository("/mypath");
}
public static Repository createRepository(String repoPath) {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = null;
try {
repo = builder.setGitDir(new File(repoPath))
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return repo;
}
}
When i run this on Eclipse Indigo with latest jgit jar in my build path i get the error message "Need 2 arguments" - nothing else, no exceptions! :S
Thanks for any help in advance.
Upvotes: 1
Views: 179
Reputation: 329
First look into package org.eclipse.jgit.api. The easiest start is from class Git:
// clone a repository
Git git = Git.cloneRepository().setURI("git://yourserver/repo.git").call();
// init a fresh new repository in the current directory
Git git = Git.init().call();
// open a repository on your disk
Git git = Git.open(new File("/path/of/repo");
Then explore the commands available on the git object you get from these starting points.
Upvotes: 1
Reputation: 1324737
The only part of JGit which displays that error message is in the main() function of MyersDiff
.
/**
* @param args two filenames specifying the contents to be diffed
*/
public static void main(String[] args) {
if (args.length != 2) {
System.err.println(JGitText.get().need2Arguments);
System.exit(1);
}
// ...
}
So check your classpath and make sure your project (and your main()
) are before the jgit.jar, and that you don't somehow calls the wrong main()
.
Upvotes: 1