theonedev/onedev · error · NotAcceptableException

No common base for target and source

Error message

No common base for target and source

What it means

When opening a pull request without an explicit base commit, OneDev computes the merge base between target and source via gitService.getMergeBase(). If git finds no common ancestor the branches are unrelated, so a PR is meaningless and a NotAcceptableException is thrown.

Source

Thrown at server-core/src/main/java/io/onedev/server/service/impl/DefaultPullRequestService.java:455

		PullRequest existing = findOpen(target, source);
		if (existing != null)
			throw new NotAcceptableException("Another pull request already opened for this change");

		existing = findEffective(target, source);
		if (existing != null) {
			if (existing.isOpen())
				throw new NotAcceptableException("Another pull request already opened for this change");
			else
				throw new NotAcceptableException("Another pull request already merged the change");
		}

		if (request.getBaseCommitHash() == null) {
			ObjectId baseCommitId = gitService.getMergeBase(
					target.getProject(), target.getObjectId(),
					source.getProject(), source.getObjectId());
			if (baseCommitId == null)
				throw new NotAcceptableException("No common base for target and source");
			request.setBaseCommitHash(baseCommitId.name());
		}

		if (request.getBaseCommitHash().equals(source.getObjectName()))
			throw new NotAcceptableException("Target already up to date with source");

		if (request.getUpdates().isEmpty()) {
			PullRequestUpdate update = new PullRequestUpdate();
			request.getUpdates().add(update);
			request.setUpdates(request.getUpdates());
			update.setRequest(request);
			update.setHeadCommitHash(source.getObjectName());
			update.setTargetHeadCommitHash(target.getObjectName());
		}

		if (request.getAssignments().isEmpty()) {
			for (var assignee: target.getProject().findDefaultPullRequestAssignees()) {
				PullRequestAssignment assignment = new PullRequestAssignment();

View on GitHub (pinned to d44925c47c)

Solutions

  1. Recreate the source branch from the target branch so histories share an ancestor: git checkout target && git checkout -b source && add changes
  2. Merge/rebase with --allow-unrelated-histories locally to establish a common base, then push and retry
  3. Verify target and source point at the intended projects/refs — mismatched refs commonly cause this
  4. Explicitly set request.setBaseCommitHash(...) only if you truly know the intended base; otherwise fix the history

Example fix

// before
pullRequestService.open(request); // request.baseCommitHash == null, unrelated histories
// after
git checkout main && git checkout -b feature   # branch from target history
# commit and push, then:
pullRequestService.open(request);
Defensive patterns

Strategy: validation

Validate before calling

ObjectId base = gitService.getMergeBase(target.getProject(), target.getObjectId(),
        source.getProject(), source.getObjectId());
if (base == null)
    throw new IllegalStateException("Branches have no common ancestor; recreate source from target");

Try / catch

try {
    pullRequestService.open(request);
} catch (NotAcceptableException e) {
    if (e.getMessage().contains("No common base"))
        fixUnrelatedHistories(source, target); // rebase with --allow-unrelated-histories or rebranch
    else throw e;
}

Prevention

When it happens

Trigger: Calling open() where request.getBaseCommitHash() is null and git merge-base between target (project, objectId) and source (project, objectId) returns null — disjoint histories.

Common situations: Source branch created from an unrelated root (e.g. orphan branch); importing two separately-initialized repos into one project; a branch recreated with squashed/unrelated history; target repo pruned shared history.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


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