### Question:
MergeBaseCalculator { public String calculateMergeBase(File repoDir, String ref1, String ref2) throws Exception { try (Git git = Git.open(repoDir); ObjectReader reader = git.getRepository().newObjectReader(); RevWalk rw = new RevWalk(git.getRepository())) { RevCommit commit1 = rw.parseCommit(git.getRepository().resolve(ref1)); RevCommit commit2 = rw.parseCommit(git.getRepository().resolve(ref2)); rw.setRevFilter(RevFilter.MERGE_BASE); rw.markStart(commit1); rw.markStart(commit2); RevCommit mergeBase = rw.next(); return mergeBase != null ? mergeBase.name() : ""; } }  String calculateMergeBase(File repoDir, String ref1, String ref2);  }### Answer:
@Test public void testCalculateMergeBase() throws Exception { try (Git git = new Git(db); ObjectReader reader = git.getRepository().newObjectReader()) { File repoDir = git.getRepository().getDirectory().getParentFile(); File file = new File(repoDir, "file.txt"); writeStringToFile(file, "hello\n"); git.add() .addFilepattern(file.getName()) .call(); RevCommit baseCommit = doCommit(git); writeStringToFile(file, "hello world\n"); git.add() .addFilepattern(file.getName()) .call(); RevCommit commit1 = doCommit(git); git.reset().setMode(ResetType.HARD).setRef(baseCommit.name()).call(); writeStringToFile(file, "hello code\n"); git.add() .addFilepattern(file.getName()) .call(); RevCommit commit2 = doCommit(git); String mergeBase = new MergeBaseCalculator() .calculateMergeBase(repoDir, commit1.name(), commit2.name()); Assert.assertEquals(baseCommit.name(), mergeBase); } }