0
最後のJenkins Buildから抽出した日付のコミットの一覧が必要で、その日付以降のマージコミットの一覧が表示されます。 マージコミットの一覧を取得するためにこれまでにコーディングしました。特定の日付の間にこれらのコミットを抽出するソリューションが必要です。 リファレンスコード:Jgitを使用して2つの日付間のマージコミットのリストを取得するには?
public static void main(String[] args)throws IOException , GitAPIException{
ArrayList<String> CommitIds=new ArrayList<String>();
FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder();
repositoryBuilder.setMustExist(true);
repositoryBuilder.setGitDir(new File("/path/to/repo"));
Repository repo = repositoryBuilder.build();
Git git = Git.open(new File("/path/to/repo"));
RevWalk walk = new RevWalk(repo);
git.checkout().setName("branch").call();
String branchName=repo.getBranch();
System.out.println(branchName);
Iterable<RevCommit> commits = git.log().all().call();
RevCommit masterHead = walk.parseCommit(repo.resolve("refs/heads/master"));
for (RevCommit commit : commits) {
boolean foundInThisBranch = false;
RevCommit otherHead = walk.parseCommit(repo.resolve(
commit.getName()));
for (Map.Entry<String, Ref> e : repo.getAllRefs().entrySet()) {
if (e.getKey().startsWith(Constants.R_HEADS)) {
if (walk.isMergedInto(otherHead, walk.parseCommit(
e.getValue().getObjectId()))) {
String foundInBranch = e.getValue().getName();
if (branchName.equals(foundInBranch)) {
foundInThisBranch = true;
break;
}
}
}
}
if (foundInThisBranch)
{
CommitIds.add(commit.getName());
}
}
System.out.println(CommitIds);
}