Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 16:21 Go to next message
Thijs de Vries is currently offline Thijs de VriesFriend
Messages: 2
Registered: April 2012
Junior Member
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 16:25 Go to previous message
Thijs de Vries is currently offline Thijs de VriesFriend
Messages: 2
Registered: April 2012
Junior Member
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: Tue Sep 24 09:59:27 GMT 2024

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

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

Back to the top