What's the jgit equivalent codeo for "git merge-base --fork-point branchA branchB"?
I tried the code below but I'm not getting the correct answer. I'm using this to hunt for branch origin. foreach.branch (git merge-base --fork-point mybranch theirbranch) will yield null a commit id only for point of origin.
So, all I need to do is to figure out how to do this in jgit and I have a method for calculating branch origin when I don't already know it.
private String getMergeBase(Repository repository, ObjectId commitIdA, ObjectId commitIdB) {
RevWalk walk = new RevWalk(repository)
try {
RevCommit revA = walk.lookupCommit(commitIdA)
RevCommit revB = walk.lookupCommit(commitIdB)
walk.setRevFilter(RevFilter.MERGE_BASE)
walk.markStart([revA,revB])
RevCommit mergeBase = walk.next()
if (! mergeBase) { return null }
return mergeBase.name
} catch(Exception e) {
project.logger.error("GetMergeBase Failed: ${commitIdA}, ${commitIdB} because ${e.message}")
}
return null
}
here's a way to solve it. note, I'm writing in Gradle/Groovy so the code may look a little funky.
`