{"record":{"id":"0a80870810311c19","repo":"theonedev/onedev","slug":"commit-not-found-commithash","errorCode":null,"errorMessage":"Commit not found: ${commitHash}","messagePattern":"Commit not found: (.+?)","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/WorkspaceResource.java","lineNumber":118,"sourceCode":"\tpublic Long createWorkspace(@NotNull @Valid WorkspaceCreateData data) {\n\t\tvar subject = SecurityUtils.getSubject();\n\t\tvar user = SecurityUtils.getUser(subject);\n\t\tif (user == null)\n\t\t\tthrow new UnauthorizedException();\n\n\t\tProject project = projectService.load(data.getProjectId());\n\t\tif (!SecurityUtils.canCreateWorkspaces(subject, project))\n\t\t\tthrow new UnauthorizedException();\n\n\t\tif (project.getHierarchyWorkspaceSpecs().stream()\n\t\t\t\t.noneMatch(it -> it.getName().equals(data.getSpecName()))) {\n\t\t\tthrow new NotAcceptableException(\"Workspace spec not found: \" + data.getSpecName());\n\t\t}\n\n\t\tObjectId commitId = ObjectId.fromString(data.getCommitHash());\n\t\tvar commit = project.getRevCommit(commitId, false);\n\t\tif (commit == null) \n\t\t\tthrow new NotAcceptableException(\"Commit not found: \" + data.getCommitHash());\n\n\t\tIssue issue = null;\n\t\tif (data.getIssueId() != null) {\n\t\t\tissue = issueService.get(data.getIssueId());\n\t\t\tif (issue == null)\n\t\t\t\tthrow new NotAcceptableException(\"Issue not found by id: \" + data.getIssueId());\n\t\t\tif (!issue.getProject().equals(project))\n\t\t\t\tthrow new NotAcceptableException(\"Issue does not belong to specified project\");\n\t\t}\n\n\t\tPullRequest request = null;\n\t\tif (data.getPullRequestId() != null) {\n\t\t\trequest = pullRequestService.get(data.getPullRequestId());\n\t\t\tif (request == null)\n\t\t\t\tthrow new NotAcceptableException(\"Pull request not found by id: \" + data.getPullRequestId());\n\t\t\tif (!request.getProject().equals(project))\n\t\t\t\tthrow new NotAcceptableException(\"Pull request does not belong to specified project\");\n\t\t}","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/WorkspaceResource.java#L100-L136","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["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.","Use the full 40-character SHA-1 of a commit that is reachable from some ref in the specified project.","If the hash comes from another repository, either point the workspace at the correct project or use the equivalent commit in this project.","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."],"exampleFix":"// before\ndata.setCommitHash(\"e83c5163316f89bfbde7d9ab23ca2e25604af290-from-fork\");\n// after\nString fullHash = project.getRepository().resolve(\"refs/heads/main\").getName();\ndata.setCommitHash(fullHash);","handlingStrategy":"validation","validationCode":"ObjectId commitId = ObjectId.fromString(data.getCommitHash());\nif (project.getRevCommit(commitId, false) == null)\n    throw new IllegalArgumentException(\"Commit \" + data.getCommitHash() + \" not in project \" + project.getPath());","typeGuard":"boolean commitExists(Project project, String hash) {\n    try {\n        return project.getRevCommit(ObjectId.fromString(hash), false) != null;\n    } catch (IllegalArgumentException e) { return false; }\n}","tryCatchPattern":null,"preventionTips":["Always resolve and verify commit hashes against the target project before workspace creation","Use full 40-char SHAs taken from the same project's refs","Avoid caching commit hashes across force-pushes; re-resolve branch heads at call time"],"tags":["rest-api","git","workspace","resource-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}