Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] how to use the logcommand?

Dear JGit Developers-
 
I've been scouring the web, and I have not been able to find a working example of how to use the log command.
 
I have this code: (the file points to a current git checkout/clone).
 
if I navigate to that directory, and type "git log", I get output that makes sense.
 
when I run this code, it triggers the nohead exception:

no head exception :

org.eclipse.jgit.api.errors.NoHeadException: No HEAD exists and no explicit starting revision was specified
 
my questions are:
 
1) how do I get the log information?
2) how do I set switches (like -n for the number of logs) to the log command?
 
thanks
 
-Jill
 
>>>>>>>>>>>
 
  Code:

FileRepositoryBuilder builder =

new FileRepositoryBuilder();

Repository repository = builder.setGitDir(

new File("/home/jsinger/git-accessories/geminiDao"))

.readEnvironment()

// scan environment GIT_* variables

.findGitDir()

// scan up the file system tree

.build();

Git git =

new Git(repository);

LogCommand log = git.log();

try {

Iterable<RevCommit> logMsgs = log.call();

for(RevCommit commit : logMsgs) {

System.

out.println(commit);

System.

out.println(commit.getAuthorIdent().getName());

System.

out.println(commit.getAuthorIdent().getWhen());

System.

out.println(commit.getFullMessage());

}

}

catch (NoHeadException e) {

System.

out.println("no head exception : " + e);

}

 
 
-Jill Singer
Software Engineer

Back to the top