jGit using RevWalk to get RevCommit returns nothing

Viewed 4241

I'm newbie on jGit and Git. I'm trying to query the historic of commit of a git repository, but I would like to get only the commit of a specific user. Reading the docs I saw that RevWalk will allow me to add RevFilters in orther to limit the search.

First, I use a Git object and its log method to list the commits, and it works very well. But using RevWalk, nothing happens.

public static void main(String[] args) throws IOException, GitAPIException {
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository repository = builder.setGitDir(new File("/home/joan/testGit/testMockito/.git"))
    .readEnvironment().findGitDir().build();

    //This works but I get all the commits
    Git git = new Git(repository);
    Iterable<RevCommit> log = git.log().call();
    for (Iterator<RevCommit> iterator = log.iterator(); iterator.hasNext();) {
        RevCommit rev = iterator.next();
        System.out.println(rev.getAuthorIdent().getName());
        System.out.println(rev.getFullMessage());
    }

    RevWalk walk = new RevWalk(repository);
    for (Iterator<RevCommit> iterator = walk.iterator(); iterator.hasNext();) {
        //It never cames in this block

        RevCommit rev = iterator.next();
        System.out.println(rev.getAuthorIdent().getName());
        System.out.println(rev.getFullMessage());
    }

}

Any advice? Am I doing something wrong?

Thanks.

2 Answers
Related