theonedev/onedev · error · NotAcceptableException

Commit not found: ${commitHash}

Error message

Commit not found: ${commitHash}

What it means

OneDev throws this 406 NotAcceptableException from the workspace creation REST endpoint when the commit hash supplied in the workspace spec data cannot be resolved to a commit in the target project's repository. The hash must parse as a valid ObjectId and exist as a revision in that project's git history.

Source

Thrown at server-core/src/main/java/io/onedev/server/rest/resource/WorkspaceResource.java:118

	public Long createWorkspace(@NotNull @Valid WorkspaceCreateData data) {
		var subject = SecurityUtils.getSubject();
		var user = SecurityUtils.getUser(subject);
		if (user == null)
			throw new UnauthorizedException();

		Project project = projectService.load(data.getProjectId());
		if (!SecurityUtils.canCreateWorkspaces(subject, project))
			throw new UnauthorizedException();

		if (project.getHierarchyWorkspaceSpecs().stream()
				.noneMatch(it -> it.getName().equals(data.getSpecName()))) {
			throw new NotAcceptableException("Workspace spec not found: " + data.getSpecName());
		}

		ObjectId commitId = ObjectId.fromString(data.getCommitHash());
		var commit = project.getRevCommit(commitId, false);
		if (commit == null) 
			throw new NotAcceptableException("Commit not found: " + data.getCommitHash());

		Issue issue = null;
		if (data.getIssueId() != null) {
			issue = issueService.get(data.getIssueId());
			if (issue == null)
				throw new NotAcceptableException("Issue not found by id: " + data.getIssueId());
			if (!issue.getProject().equals(project))
				throw new NotAcceptableException("Issue does not belong to specified project");
		}

		PullRequest request = null;
		if (data.getPullRequestId() != null) {
			request = pullRequestService.get(data.getPullRequestId());
			if (request == null)
				throw new NotAcceptableException("Pull request not found by id: " + data.getPullRequestId());
			if (!request.getProject().equals(project))
				throw new NotAcceptableException("Pull request does not belong to specified project");
		}

View on GitHub (pinned to d44925c47c)

Solutions

  1. Verify the commit exists in the target project: run 'git cat-file -t <hash>' inside the project's repository or check the commit page in the OneDev UI.
  2. Use the full 40-character SHA-1 of a commit that is reachable from some ref in the specified project.
  3. If the hash comes from another repository, either point the workspace at the correct project or use the equivalent commit in this project.
  4. If the commit was on a rewritten branch, locate the new hash (e.g. via reflog or the PR's current head) and resend the request.

Example fix

// before
data.setCommitHash("e83c5163316f89bfbde7d9ab23ca2e25604af290-from-fork");
// after
String fullHash = project.getRepository().resolve("refs/heads/main").getName();
data.setCommitHash(fullHash);
Defensive patterns

Strategy: validation

Validate before calling

ObjectId commitId = ObjectId.fromString(data.getCommitHash());
if (project.getRevCommit(commitId, false) == null)
    throw new IllegalArgumentException("Commit " + data.getCommitHash() + " not in project " + project.getPath());

Type guard

boolean commitExists(Project project, String hash) {
    try {
        return project.getRevCommit(ObjectId.fromString(hash), false) != null;
    } catch (IllegalArgumentException e) { return false; }
}

Prevention

When it happens

Trigger: POSTing to the workspace REST resource with a CommitHash that is not present in the specified project's repository (e.g. a hash from a different repo, a pruned/rewritten commit, or a typo).

Common situations: Copy-pasting a commit hash from a fork or another OneDev project; referencing a commit on a branch that was force-pushed away; using an abbreviated hash where the full 40-char hash is expected; CI automations caching hashes that were later garbage-collected.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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