{"record":{"id":"668ef5d5a6580c12","repo":"theonedev/onedev","slug":"no-code-in-target-project","errorCode":null,"errorMessage":"No code in target project: ","messagePattern":"No code in target project: ","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/ai/TodResource.java","lineNumber":1291,"sourceCode":"\n        if (!SecurityUtils.canReadCode(sourceProject))\n            throw new UnauthorizedException(\"No permission to read code of source project: \" + sourceProjectPath);\n\n        Project targetProject;\n        if (targetProjectPath != null) {\n            targetProject = getProject(targetProjectPath);\n        } else {\n            targetProject = sourceProject.getForkedFrom();\n            if (targetProject == null)\n                targetProject = sourceProject;\n        }\n        if (!SecurityUtils.canReadCode(targetProject))\n            throw new UnauthorizedException(\"No permission to read code of target project: \" + targetProjectPath);\n\n        if (targetBranch == null)\n            targetBranch = targetProject.getDefaultBranch();\n        if (targetBranch == null)\n            throw new NotAcceptableException(\"No code in target project: \" + targetProject.getPath());\n\n        var target = new ProjectAndBranch(targetProject, targetBranch);\n        var source = new ProjectAndBranch(sourceProject, sourceBranch);\n\n        var info = new CreatePullRequestEssentialInfo();\n        info.currentProject = currentProject;\n        info.target = target;\n        info.source = source;\n        info.submitter = user;\n\n        return info;\n    }    \n\n    private PullRequest getPullRequest(Project currentProject, String referenceString) {\n        var requestReference = PullRequestReference.of(referenceString, currentProject);\n        var request = pullRequestService.find(requestReference.getProject(), requestReference.getNumber());\n        if (request != null) {\n            if (!SecurityUtils.canReadCode(request.getProject()))","sourceCodeStart":1273,"sourceCodeEnd":1309,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/ai/TodResource.java#L1273-L1309","documentation":"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.","triggerScenarios":"POST to create-pull-request with targetBranch omitted against a target project that is empty or has no default branch configured.","commonSituations":"Newly created project with no commits; default branch renamed/deleted so the setting is empty; targeting an empty fork parent.","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)."],"exampleFix":"// before\nvar data = new HashMap<String, Serializable>(); // no targetBranch\n// after\ndata.put(\"targetBranch\", \"main\"); // branch that exists in target project","handlingStrategy":"validation","validationCode":"String branch = targetBranch != null ? targetBranch : targetProject.getDefaultBranch();\nif (branch == null || targetProject.getBranches().stream().noneMatch(b -> b.equals(branch)))\n    throw new IllegalStateException(\"Target project has no usable branch\");","typeGuard":null,"tryCatchPattern":"try {\n    callCreatePullRequest(params);\n} catch (NotAcceptableException e) {\n    if (e.getMessage().startsWith(\"No code in target project\")) {\n        // prompt user to pick/push a branch in the empty target\n    } else throw e;\n}","preventionTips":["Always specify targetBranch explicitly for automation.","Ensure target repositories have at least one commit before opening PRs.","Verify default branch settings after repository migrations."],"tags":["pull-request","branch","empty-repository","onedev"],"backgroundTag":"resource-not-found","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"}