Skip to main content



      Home
Home » Eclipse Projects » EGit / JGit » Struggling with Hello World JGit program(See Title)
Struggling with Hello World JGit program [message #853033] Sun, 22 April 2012 12:21 Go to next message
Eclipse UserFriend
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?
Re: Struggling with Hello World JGit program [message #853037 is a reply to message #853033] Sun, 22 April 2012 12:25 Go to previous message
Eclipse UserFriend
Ok,
found the answer myself, esssentially you want the file to point to:

/path/to/working/git/repo/.git/

Previous Topic:Egit + Github question
Next Topic:egit team synchronize bugs
Goto Forum:
  


Current Time: Thu Jun 12 08:26:57 EDT 2025

Powered by FUDForum. Page generated in 0.04024 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top