{"record":{"id":"36803adb08831c18","repo":"theonedev/onedev","slug":"no-permission-to-create-branch-s","errorCode":null,"errorMessage":"No permission to create branch: %s","messagePattern":"No permission to create branch: (.+?)","errorType":"http","errorClass":"UnauthorizedException","httpStatus":401,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/service/impl/DefaultIssueService.java","lineNumber":1480,"sourceCode":"\t\tif (normalizedTitle != null) {\n\t\t\tnormalizedTitle = StringUtils.stripEnd(StringUtils.abbreviate(normalizedTitle, \"\", MAX_BRANCH_TITLE_LENGTH), \"-\");\n\t\t\treturn prefixWithSlash + \"issue-\" + issue.getNumber() + \"-\" + normalizedTitle;\n\t\t} else {\n\t\t\treturn prefixWithSlash + \"issue-\" + issue.getNumber();\n\t\t}\n\t}\n\n\t@Sessional\n\t@Override\n\tpublic String ensureBranch(Subject subject, Issue issue) {\n\t\tif (issue.getBranch() != null)\n\t\t\treturn issue.getBranch();\n\n\t\tProject project = issue.getProject();\n\t\tString suggestedBranch = suggestBranch(issue);\n\n\t\tif (!SecurityUtils.canCreateBranch(project, suggestedBranch))\n\t\t\tthrow new UnauthorizedException(\"No permission to create branch: \" + suggestedBranch);\n\n\t\tif (project.getBranchRef(suggestedBranch) != null) {\n\t\t\tthrow new NotAcceptableException(MessageFormat.format(\"Branch \\\"{0}\\\" already exists\", suggestedBranch));\n\t\t} else {\n\t\t\tRevCommit commit = null;\n\t\t\tif (issue.getFieldCommitId() != null)\n\t\t\t\tcommit = project.getRevCommit(issue.getFieldCommitId(), false);\n\t\t\tif (commit == null) {\n\t\t\t\tString defaultBranch = project.getDefaultBranch();\n\t\t\t\tif (defaultBranch == null) \n\t\t\t\t\tthrow new NotAcceptableException(\"Default branch is not available\");\n\t\t\t\telse \n\t\t\t\t\tcommit = project.getRevCommit(defaultBranch, true);\t\n\t\t\t}\t\t\n\t\t\tif (!project.isCommitSignatureRequirementSatisfied(SecurityUtils.getUser(subject), suggestedBranch, commit)) {\n\t\t\t\tthrow new NotAcceptableException(\"Valid signature required for head commit of this branch per branch protection rule\");\n\t\t\t} else {\n\t\t\t\tgitService.createBranch(project, suggestedBranch, commit.name());","sourceCodeStart":1462,"sourceCodeEnd":1498,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/service/impl/DefaultIssueService.java#L1462-L1498","documentation":"ensureBranch verifies SecurityUtils.canCreateBranch for the suggested branch name in the issue's project and throws UnauthorizedException when the subject lacks permission, naming the branch that would have been created.","triggerScenarios":"Thrown at server-core/src/main/java/io/onedev/server/service/impl/DefaultIssueService.java:1480 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Grant the user 'Create Branch' permission (project role/authorization) in the issue's project.","Operate as a user with code-write rights."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}