{"record":{"id":"6f0fae0535199451","repo":"theonedev/onedev","slug":"no-common-base-for-target-and-source","errorCode":null,"errorMessage":"No common base for target and source","messagePattern":"No common base for target and source","errorType":"validation","errorClass":"NotAcceptableException","httpStatus":400,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/service/impl/DefaultPullRequestService.java","lineNumber":455,"sourceCode":"\n\t\tPullRequest existing = findOpen(target, source);\n\t\tif (existing != null)\n\t\t\tthrow new NotAcceptableException(\"Another pull request already opened for this change\");\n\n\t\texisting = findEffective(target, source);\n\t\tif (existing != null) {\n\t\t\tif (existing.isOpen())\n\t\t\t\tthrow new NotAcceptableException(\"Another pull request already opened for this change\");\n\t\t\telse\n\t\t\t\tthrow new NotAcceptableException(\"Another pull request already merged the change\");\n\t\t}\n\n\t\tif (request.getBaseCommitHash() == null) {\n\t\t\tObjectId baseCommitId = gitService.getMergeBase(\n\t\t\t\t\ttarget.getProject(), target.getObjectId(),\n\t\t\t\t\tsource.getProject(), source.getObjectId());\n\t\t\tif (baseCommitId == null)\n\t\t\t\tthrow new NotAcceptableException(\"No common base for target and source\");\n\t\t\trequest.setBaseCommitHash(baseCommitId.name());\n\t\t}\n\n\t\tif (request.getBaseCommitHash().equals(source.getObjectName()))\n\t\t\tthrow new NotAcceptableException(\"Target already up to date with source\");\n\n\t\tif (request.getUpdates().isEmpty()) {\n\t\t\tPullRequestUpdate update = new PullRequestUpdate();\n\t\t\trequest.getUpdates().add(update);\n\t\t\trequest.setUpdates(request.getUpdates());\n\t\t\tupdate.setRequest(request);\n\t\t\tupdate.setHeadCommitHash(source.getObjectName());\n\t\t\tupdate.setTargetHeadCommitHash(target.getObjectName());\n\t\t}\n\n\t\tif (request.getAssignments().isEmpty()) {\n\t\t\tfor (var assignee: target.getProject().findDefaultPullRequestAssignees()) {\n\t\t\t\tPullRequestAssignment assignment = new PullRequestAssignment();","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/service/impl/DefaultPullRequestService.java#L437-L473","documentation":"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.","triggerScenarios":"Calling open() where request.getBaseCommitHash() is null and git merge-base between target (project, objectId) and source (project, objectId) returns null — disjoint histories.","commonSituations":"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.","solutions":["Recreate the source branch from the target branch so histories share an ancestor: git checkout target && git checkout -b source && add changes","Merge/rebase with --allow-unrelated-histories locally to establish a common base, then push and retry","Verify target and source point at the intended projects/refs — mismatched refs commonly cause this","Explicitly set request.setBaseCommitHash(...) only if you truly know the intended base; otherwise fix the history"],"exampleFix":"// before\npullRequestService.open(request); // request.baseCommitHash == null, unrelated histories\n// after\ngit checkout main && git checkout -b feature   # branch from target history\n# commit and push, then:\npullRequestService.open(request);","handlingStrategy":"validation","validationCode":"ObjectId base = gitService.getMergeBase(target.getProject(), target.getObjectId(),\n        source.getProject(), source.getObjectId());\nif (base == null)\n    throw new IllegalStateException(\"Branches have no common ancestor; recreate source from target\");","typeGuard":null,"tryCatchPattern":"try {\n    pullRequestService.open(request);\n} catch (NotAcceptableException e) {\n    if (e.getMessage().contains(\"No common base\"))\n        fixUnrelatedHistories(source, target); // rebase with --allow-unrelated-histories or rebranch\n    else throw e;\n}","preventionTips":["Always branch source branches off the target branch","Avoid orphan branches for feature work","Verify target/source refs point at the same history line"],"tags":["pull-request","git","merge-base","unrelated-histories","onedev"],"backgroundTag":"git-command-failed","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}