theonedev/onedev · error · ExplicitException

No default branch

Error message

No default branch

What it means

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.

Source

Thrown at server-core/src/main/java/io/onedev/server/search/commit/Revision.java:73

	}
	
	public Build getValueAsBuild(Project project) {
		var buildReference = BuildReference.of(value, project);
		var buildService = OneDev.getInstance(BuildService.class);
		var build = buildService.find(buildReference.getProject(), buildReference.getNumber());
		if (build == null)
			throw new ExplicitException("Unable to find build: " + value);
		else
			return build;
	}

	public RevCommit getRevCommit(Project project) {
		if (type == Type.BRANCH) {
			String branch = value;
			if (branch == null) {
				branch = project.getDefaultBranch();
				if (branch == null) 
					throw new ExplicitException("No default branch");
			}
			return project.getRevCommit(GitUtils.branch2ref(branch), true);
		} else if (type == Type.TAG) {
			return project.getRevCommit(GitUtils.tag2ref(value), true);
		} else if (type == Type.COMMIT) {
			return project.getRevCommit(value, true);
		} else if (type == Type.BUILD) {
			return project.getRevCommit(getValueAsBuild(project).getCommitHash(), true);
		} else {
			throw new RuntimeException("Unknown revision type: " + type);
		}
	}

	public boolean matchesRef(Project project, String refName) {
		if (type == Type.BRANCH) {
			var branch = value != null? value: project.getDefaultBranch();
			return refName.equals(GitUtils.branch2ref(branch));
		} else if (type == Type.TAG) {

View on GitHub (pinned to d44925c47c)

Solutions

  1. Push at least one branch to the repository
  2. Set the default branch in project settings (General > Default Branch)
  3. Use an explicit branch name in the query revision instead of the default

Example fix

// before
new Revision(Type.BRANCH, null).getRevCommit(emptyProject)
// after
Project setting: default branch = main (after pushing main), or use Revision("main")
Defensive patterns

Strategy: validation

Validate before calling

if (project.getDefaultBranch() == null) { throw new IllegalStateException("project " + project.getName() + " has no default branch; push a branch first"); }

Try / catch

try { project.getRevCommit(...); } catch (ExplicitException e) { /* prompt user to configure default branch */ }

Prevention

When it happens

Trigger: 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.

Common situations: Running a commit query on an empty repo; default branch renamed/deleted so the setting is stale; newly created project without any pushed branch.

Understand the failure class

Background: "missing required config value" errors: why libraries refuse to start when a configuration key is empty, unset, or blank — this error's family across 48 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/50d7ca26986ab089. Report an issue: GitHub.