Anu Chawla
Anu Chawla

Reputation: 445

Get log of a range of revisions with JGit

I am executing

git log origin/<branch>..HEAD

in cmd and getting following information about commit yet not pushed to git.

error: cannot spawn less: No such file or directory

commit 436ab1eca3dfxxxxxxxxx569427f51badf2

Author: Chawla, Anukriti Date: Fri May 11 13:38:37 2018> +0530

Committed on : Fri May 11 13:38:37 IST 2018

I want its equivalent in JGit and tried the following but it didn't work:

for (RevCommit commit :git.log().add(git.getRepository().
  resolve("origin/<branch>..HEAD")).call()) {
  System.out.println(commit.getName());
}

Upvotes: 2

Views: 994

Answers (1)

R&#252;diger Herrmann
R&#252;diger Herrmann

Reputation: 21025

Whether a branch was pushed or not does not affect the LogCommand. What you are looking for is probably LogCommand::addRange to obtain the log for a range of commits.

For example:

ObjectId since = git.getRepository().resolve("refs/remotes/origin/some-branch");
ObjectId until = git.getRepository().resolve("HEAD");
for (RevCommit commit : git.log().addRange(since, until).call()) {
  // ...
}

Upvotes: 3

Related Questions