{"record":{"id":"38a3bb86bd867218","repo":"theonedev/onedev","slug":"branch-0-already-exists","errorCode":null,"errorMessage":"Branch \"{0}\" already exists","messagePattern":"Branch \"(.+?)\" already exists","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/service/impl/DefaultIssueService.java","lineNumber":1483,"sourceCode":"\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());\n\t\t\t\treturn suggestedBranch;\n\t\t\t}\n\t\t}","sourceCodeStart":1465,"sourceCodeEnd":1501,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/service/impl/DefaultIssueService.java#L1465-L1501","documentation":"ensureBranch builds a suggested branch name from the issue number and title; if a branch with that name already exists in the project (NotAcceptableException via MessageFormat), the issue cannot get its own ensure-branch under that name.","triggerScenarios":"Thrown at server-core/src/main/java/io/onedev/server/service/impl/DefaultIssueService.java:1483 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Point the issue at the existing branch or use a differently named branch.","Resolve the collision by choosing a unique branch suffix."],"exampleFix":null,"handlingStrategy":"validation","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-14T05:17:10.506Z"}