theonedev/onedev · error · IllegalStateException

Cannot find merge base using first parent.

Error message

Cannot find merge base using first parent.

What it means

Thrown by StartGenerator.next() when a merge-base walk (RevFilter.MERGE_BASE) is started on a RevWalk configured with setFirstParent(true). The merge-base generator cannot operate correctly when traversal is restricted to first parents only, so JGit rejects the combination up front.

Source

Thrown at server-core/src/main/java/org/eclipse/jgit/revwalk/StartGenerator.java:65

	RevCommit next() throws MissingObjectException,
			IncorrectObjectTypeException, IOException {
		Generator g;

		final RevWalk w = walker;
		RevFilter rf = w.getRevFilter();
		final TreeFilter tf = w.getTreeFilter();
		AbstractRevQueue q = walker.queue;

		if (rf == RevFilter.MERGE_BASE) {
			// Computing for merge bases is a special case and does not
			// use the bulk of the generator pipeline.
			//
			if (tf != TreeFilter.ALL) {
				throw new IllegalStateException(MessageFormat.format(
						JGitText.get().cannotCombineTreeFilterWithRevFilter, tf, rf));
			}
			if (w.isFirstParent()) {
				throw new IllegalStateException(
						JGitText.get().cannotFindMergeBaseUsingFirstParent);
			}

			final MergeBaseGenerator mbg = new MergeBaseGenerator(w);
			walker.pending = mbg;
			walker.queue = AbstractRevQueue.EMPTY_QUEUE;
			mbg.init(q);
			return mbg.next();
		}

		final boolean uninteresting = q.anybodyHasFlag(RevWalk.UNINTERESTING);
		boolean boundary = walker.hasRevSort(RevSort.BOUNDARY);

		if (!boundary && walker instanceof ObjectWalk) {
			// The object walker requires boundary support to color
			// trees and blobs at the boundary uninteresting so it
			// does not produce those in the result.
			//

View on GitHub (pinned to d44925c47c)

Solutions

  1. Call walk.setFirstParent(false) before starting the merge-base walk
  2. Use a dedicated RevWalk instance for merge-base computation
  3. Use Repository/RevWalkUtils utilities (e.g. RevWalkUtils.findBranchesReachedFrom) or a separate algorithm that supports first-parent if that is genuinely required

Example fix

// before
walk.setFirstParent(true);
walk.setRevFilter(RevFilter.MERGE_BASE);
// after
walk.setFirstParent(false); // required for merge-base
walk.setRevFilter(RevFilter.MERGE_BASE);
Defensive patterns

Strategy: validation

Validate before calling

if (walk.getRevFilter() == RevFilter.MERGE_BASE && walk.isFirstParent()) {
    walk.setFirstParent(false);
}

Try / catch

try {
    for (RevCommit c : walk) { ... }
} catch (IllegalStateException e) {
    throw new ConfigurationException("merge-base walk cannot use first-parent mode");
}

Prevention

When it happens

Trigger: Calling RevWalk.setFirstParent(true) and RevWalk.setRevFilter(RevFilter.MERGE_BASE), then iterating with next().

Common situations: Reusing a shared RevWalk builder that enables first-parent for history simplification, then adding a merge-base filter for rename/detector or ancestor checks.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/5438026450d89da8. Report an issue: GitHub.