theonedev/onedev · error · NotAcceptableException

Default branch is not available

Error message

Default branch is not available

What it means

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.

Source

Thrown at server-core/src/main/java/io/onedev/server/service/impl/DefaultIssueService.java:1491

		if (issue.getBranch() != null)
			return issue.getBranch();

		Project project = issue.getProject();
		String suggestedBranch = suggestBranch(issue);

		if (!SecurityUtils.canCreateBranch(project, suggestedBranch))
			throw new UnauthorizedException("No permission to create branch: " + suggestedBranch);

		if (project.getBranchRef(suggestedBranch) != null) {
			throw new NotAcceptableException(MessageFormat.format("Branch \"{0}\" already exists", suggestedBranch));
		} else {
			RevCommit commit = null;
			if (issue.getFieldCommitId() != null)
				commit = project.getRevCommit(issue.getFieldCommitId(), false);
			if (commit == null) {
				String defaultBranch = project.getDefaultBranch();
				if (defaultBranch == null) 
					throw new NotAcceptableException("Default branch is not available");
				else 
					commit = project.getRevCommit(defaultBranch, true);	
			}		
			if (!project.isCommitSignatureRequirementSatisfied(SecurityUtils.getUser(subject), suggestedBranch, commit)) {
				throw new NotAcceptableException("Valid signature required for head commit of this branch per branch protection rule");
			} else {
				gitService.createBranch(project, suggestedBranch, commit.name());
				return suggestedBranch;
			}
		}
	}
}

View on GitHub (pinned to d44925c47c)

Solutions

  1. Push at least one commit to the repository so a default branch exists
  2. Set the default branch explicitly in project/repo settings (Repository -> default branch)
  3. Ensure issue.fieldCommitId is set if you intend to branch from a specific commit
  4. Check that the repo's HEAD symlink points to an existing branch (git symbolic-ref refs/remotes/HEAD or equivalent)

Example fix

// before: creating branch from issue with no commit on an empty repo
issueService.openBranch(project, issue, suggestedBranch, subject);
// after: guard before calling
if (issue.getFieldCommitId() == null && project.getDefaultBranch() == null) {
    throw new ExplicitException("Repository has no default branch; push a commit first.");
}
issueService.openBranch(project, issue, suggestedBranch, subject);
Defensive patterns

Strategy: validation

Validate before calling

if (issue.getFieldCommitId() == null && project.getDefaultBranch() == null) {
    throw new ExplicitException("Cannot create branch: no commit and no default branch available.");
}

Type guard

function canCreateBranch(issue, project) {
    return issue.getFieldCommitId() != null || project.getDefaultBranch() != null;
}

Try / catch

try {
    issueService.openBranch(project, issue, branchName, subject);
} catch (NotAcceptableException e) {
    if (e.getMessage().contains("Default branch is not available")) {
        // prompt user to push initial commit / configure default branch
    } else throw e;
}

Prevention

When it happens

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

Common situations: 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.

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/3fdea011f3488ad7. Report an issue: GitHub.