Struggling with Hello World JGit program [message #853033] |
Sun, 22 April 2012 12:21  |
Eclipse User |
|
|
|
Hello All, I'm trying to get a simple hello world working that just prints out the revision id of HEAD of a repository I already checkout out. Anyways, I just cloned a random repository from github and tried the following:
package hellogit;
import java.io.File;
import java.io.IOException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
/**
*
* @author tdevries
*/
public class HelloGit {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File("/Full/Path/To/Git/Repo/"))
.readEnvironment()
.findGitDir()
.build();
ObjectId head = repository.resolve("HEAD");
System.out.println(head);
}
}
However, when I run the above example it only prints out NULL. I cloned the repository using the git clone command. Perhaps I need to do this with the JGit program?
|
|
|
|
Powered by
FUDForum. Page generated in 0.04024 seconds