how do I get all commits of a branch with JGit, without changing the working directory?
Unfortunately the JGit docs are not very good ...
In ruby with grit i
A much shorter and clean solution can be done via the "log" command that JGit provides:
Repository repository = new FileRepository("pathToRepo/.git");
logs = new Git(repository).log()
.add(repository.resolve("remotes/origin/testbranch"))
.call();
count = 0;
for (RevCommit rev : logs) {
System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
count++;
}
System.out.println("Had " + count + " commits overall on test-branch");
See the full snippet at the jgit-cookbook