theonedev/onedev · error · NotAcceptableException
No code in target project:
Error message
No code in target project:
What it means
After permission checks, the TOD create-pull-request endpoint resolves targetBranch, defaulting to targetProject.getDefaultBranch(). If no branch was specified and the target project has no default branch (typically an empty repository), it throws a JAX-RS NotAcceptableException (HTTP 406) naming the project path.
Source
Thrown at server-core/src/main/java/io/onedev/server/ai/TodResource.java:1291
if (!SecurityUtils.canReadCode(sourceProject))
throw new UnauthorizedException("No permission to read code of source project: " + sourceProjectPath);
Project targetProject;
if (targetProjectPath != null) {
targetProject = getProject(targetProjectPath);
} else {
targetProject = sourceProject.getForkedFrom();
if (targetProject == null)
targetProject = sourceProject;
}
if (!SecurityUtils.canReadCode(targetProject))
throw new UnauthorizedException("No permission to read code of target project: " + targetProjectPath);
if (targetBranch == null)
targetBranch = targetProject.getDefaultBranch();
if (targetBranch == null)
throw new NotAcceptableException("No code in target project: " + targetProject.getPath());
var target = new ProjectAndBranch(targetProject, targetBranch);
var source = new ProjectAndBranch(sourceProject, sourceBranch);
var info = new CreatePullRequestEssentialInfo();
info.currentProject = currentProject;
info.target = target;
info.source = source;
info.submitter = user;
return info;
}
private PullRequest getPullRequest(Project currentProject, String referenceString) {
var requestReference = PullRequestReference.of(referenceString, currentProject);
var request = pullRequestService.find(requestReference.getProject(), requestReference.getNumber());
if (request != null) {
if (!SecurityUtils.canReadCode(request.getProject()))View on GitHub (pinned to d44925c47c)
Solutions
- Explicitly pass a valid targetBranch that exists in the target project.
- Push an initial commit to the target project so a default branch exists.
- Set the project's default branch in project settings (branches section).
Example fix
// before
var data = new HashMap<String, Serializable>(); // no targetBranch
// after
data.put("targetBranch", "main"); // branch that exists in target project Defensive patterns
Strategy: validation
Validate before calling
String branch = targetBranch != null ? targetBranch : targetProject.getDefaultBranch();
if (branch == null || targetProject.getBranches().stream().noneMatch(b -> b.equals(branch)))
throw new IllegalStateException("Target project has no usable branch"); Try / catch
try {
callCreatePullRequest(params);
} catch (NotAcceptableException e) {
if (e.getMessage().startsWith("No code in target project")) {
// prompt user to pick/push a branch in the empty target
} else throw e;
} Prevention
- Always specify targetBranch explicitly for automation.
- Ensure target repositories have at least one commit before opening PRs.
- Verify default branch settings after repository migrations.
When it happens
Trigger: POST to create-pull-request with targetBranch omitted against a target project that is empty or has no default branch configured.
Common situations: Newly created project with no commits; default branch renamed/deleted so the setting is empty; targeting an empty fork parent.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Reviewer not found:
- Pull request submitter cannot be reviewer
- Assignee not found:
- No permission to read code of source project:
- No permission to read code of target project:
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/668ef5d5a6580c12.
Report an issue: GitHub.