{"record":{"id":"3fdea011f3488ad7","repo":"theonedev/onedev","slug":"default-branch-is-not-available","errorCode":null,"errorMessage":"Default branch is not available","messagePattern":"Default branch is not available","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/service/impl/DefaultIssueService.java","lineNumber":1491,"sourceCode":"\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}\n\t}\n}\n","sourceCodeStart":1473,"sourceCodeEnd":1504,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/service/impl/DefaultIssueService.java#L1473-L1504","documentation":"OneDev throws this NotAcceptableException when code needs a commit to base a new branch on, but no commit is recorded on the issue and the project has no default branch configured. project.getDefaultBranch() returning null means the repository's HEAD cannot be resolved (no default branch set in repo/project settings). The library refuses to guess a fallback commit, so branch creation is aborted with HTTP 406.","triggerScenarios":"Calling the issue service method that suggests/creates a branch (e.g. when converting an issue to a branch) via this code path when issue.getFieldCommitId() is null AND the project's default branch is unset or unresolvable (empty repo, HEAD pointing to an unborn branch, default branch deleted).","commonSituations":"Newly created projects whose git repo has no commits yet; the configured default branch was renamed or deleted in repo settings; repository HEAD is broken after migration/import; automation hitting the API before the first push.","solutions":["Push at least one commit to the repository so a default branch exists","Set the default branch explicitly in project/repo settings (Repository -> default branch)","Ensure issue.fieldCommitId is set if you intend to branch from a specific commit","Check that the repo's HEAD symlink points to an existing branch (git symbolic-ref refs/remotes/HEAD or equivalent)"],"exampleFix":"// before: creating branch from issue with no commit on an empty repo\nissueService.openBranch(project, issue, suggestedBranch, subject);\n// after: guard before calling\nif (issue.getFieldCommitId() == null && project.getDefaultBranch() == null) {\n    throw new ExplicitException(\"Repository has no default branch; push a commit first.\");\n}\nissueService.openBranch(project, issue, suggestedBranch, subject);","handlingStrategy":"validation","validationCode":"if (issue.getFieldCommitId() == null && project.getDefaultBranch() == null) {\n    throw new ExplicitException(\"Cannot create branch: no commit and no default branch available.\");\n}","typeGuard":"function canCreateBranch(issue, project) {\n    return issue.getFieldCommitId() != null || project.getDefaultBranch() != null;\n}","tryCatchPattern":"try {\n    issueService.openBranch(project, issue, branchName, subject);\n} catch (NotAcceptableException e) {\n    if (e.getMessage().contains(\"Default branch is not available\")) {\n        // prompt user to push initial commit / configure default branch\n    } else throw e;\n}","preventionTips":["Always push an initial commit before automating issue-to-branch flows","Set and verify the default branch in project settings during project bootstrap","Monitor repos whose HEAD is unborn or points to a deleted branch"],"tags":["git","branch","configuration","empty-repository"],"backgroundTag":"missing-config-value","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"}