{"record":{"id":"50d7ca26986ab089","repo":"theonedev/onedev","slug":"no-default-branch","errorCode":null,"errorMessage":"No default branch","messagePattern":"No default branch","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/commit/Revision.java","lineNumber":73,"sourceCode":"\t}\n\t\n\tpublic Build getValueAsBuild(Project project) {\n\t\tvar buildReference = BuildReference.of(value, project);\n\t\tvar buildService = OneDev.getInstance(BuildService.class);\n\t\tvar build = buildService.find(buildReference.getProject(), buildReference.getNumber());\n\t\tif (build == null)\n\t\t\tthrow new ExplicitException(\"Unable to find build: \" + value);\n\t\telse\n\t\t\treturn build;\n\t}\n\n\tpublic RevCommit getRevCommit(Project project) {\n\t\tif (type == Type.BRANCH) {\n\t\t\tString branch = value;\n\t\t\tif (branch == null) {\n\t\t\t\tbranch = project.getDefaultBranch();\n\t\t\t\tif (branch == null) \n\t\t\t\t\tthrow new ExplicitException(\"No default branch\");\n\t\t\t}\n\t\t\treturn project.getRevCommit(GitUtils.branch2ref(branch), true);\n\t\t} else if (type == Type.TAG) {\n\t\t\treturn project.getRevCommit(GitUtils.tag2ref(value), true);\n\t\t} else if (type == Type.COMMIT) {\n\t\t\treturn project.getRevCommit(value, true);\n\t\t} else if (type == Type.BUILD) {\n\t\t\treturn project.getRevCommit(getValueAsBuild(project).getCommitHash(), true);\n\t\t} else {\n\t\t\tthrow new RuntimeException(\"Unknown revision type: \" + type);\n\t\t}\n\t}\n\n\tpublic boolean matchesRef(Project project, String refName) {\n\t\tif (type == Type.BRANCH) {\n\t\t\tvar branch = value != null? value: project.getDefaultBranch();\n\t\t\treturn refName.equals(GitUtils.branch2ref(branch));\n\t\t} else if (type == Type.TAG) {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/commit/Revision.java#L55-L91","documentation":"Revision.getRevCommit() resolves a BRANCH-type revision with a null branch value to project.getDefaultBranch(); if the project has no default branch configured, ExplicitException 'No default branch' is thrown.","triggerScenarios":"Resolving a bare/default revision (null branch) for a project whose default branch is unset — e.g. an empty repository or a project where the default branch was never set or points to a deleted branch.","commonSituations":"Running a commit query on an empty repo; default branch renamed/deleted so the setting is stale; newly created project without any pushed branch.","solutions":["Push at least one branch to the repository","Set the default branch in project settings (General > Default Branch)","Use an explicit branch name in the query revision instead of the default"],"exampleFix":"// before\nnew Revision(Type.BRANCH, null).getRevCommit(emptyProject)\n// after\nProject setting: default branch = main (after pushing main), or use Revision(\"main\")","handlingStrategy":"validation","validationCode":"if (project.getDefaultBranch() == null) { throw new IllegalStateException(\"project \" + project.getName() + \" has no default branch; push a branch first\"); }","typeGuard":null,"tryCatchPattern":"try { project.getRevCommit(...); } catch (ExplicitException e) { /* prompt user to configure default branch */ }","preventionTips":["Initialize repositories with at least one pushed branch before querying","Keep the project default-branch setting in sync with actual branches","Use explicit branch names in automated queries"],"tags":["git","configuration","onedev"],"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"}