{"record":{"id":"2242b4bf8392d608","repo":"theonedev/onedev","slug":"specified-commit-is-not-reachable-from-specified-r","errorCode":null,"errorMessage":"Specified commit is not reachable from specified ref","messagePattern":"Specified commit is not reachable from specified ref","errorType":"http","errorClass":"ValidationException","httpStatus":400,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/JobRunResource.java","lineNumber":85,"sourceCode":"\t\t\n\t\tvar subject = SecurityUtils.getSubject();\n\t\tvar user = SecurityUtils.getUser(subject);\n\t\tif (jobRun instanceof JobRunOnCommit) {\n\t\t\tJobRunOnCommit jobRunOnCommit = (JobRunOnCommit) jobRun;\n\t\t\t\n\t    \tproject = projectService.load(jobRunOnCommit.getProjectId());\n\t\t\tif (!SecurityUtils.canRunJob(subject, project, jobRun.getJobName()))\t\t\n\t\t\t\tthrow new UnauthorizedException();\n\n\t\t\tif (!jobRunOnCommit.getRefName().startsWith(Constants.R_REFS)) \n\t\t\t\tthrow new ValidationException(\"Ref name should start with \" + Constants.R_REFS);\n\t\t\t\n\t\t\tRevCommit refCommit = project.getRevCommit(jobRunOnCommit.getRefName(), true);\n\t\t\t\n\t\t\tcommitId = ObjectId.fromString(jobRunOnCommit.getCommitHash());\n\t\t\t\n\t\t\tif (!gitService.isMergedInto(project, null, commitId, refCommit)) \n\t\t\t\tthrow new ValidationException(\"Specified commit is not reachable from specified ref\");\n\t\t\t\n\t\t\trefName = jobRunOnCommit.getRefName();\n\t\t\trequest = null;\n\t\t} else {\n\t\t\tJobRunOnPullRequest jobRunOnPullRequest = (JobRunOnPullRequest) jobRun;\n\t\t\trequest = pullRequestService.load(jobRunOnPullRequest.getPullRequestId());\n\t\t\trefName = request.getMergeRef();\n\t\t\tproject = request.getProject();\n\t\t\t\n\t\t\tif (!SecurityUtils.canRunJob(subject, request.getProject(), jobRun.getJobName()))\t\t\n\t\t\t\tthrow new UnauthorizedException();\n\n\t\t\tMergePreview preview = request.checkMergePreview();\n\t\t\tif (preview == null)\n\t\t\t\tthrow new ValidationException(\"Pull request merge preview not calculated yet\");\n\t\t\tif (preview.getMergeCommitHash() == null)\n\t\t\t\tthrow new ValidationException(\"Pull request has merge conflicts\");\n\t\t\t","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/JobRunResource.java#L67-L103","documentation":"runBuild checks with gitService.isMergedInto() that the supplied commitHash is an ancestor of (reachable from) the supplied ref. If the commit is not contained in the ref's history, a ValidationException is thrown (HTTP 400), because a build on that ref would not actually contain the requested commit.","triggerScenarios":"POSTing a JobRunOnCommit where commitHash points to a commit on another branch, an orphaned commit, or a commit pushed after the ref advanced past it.","commonSituations":"Passing HEAD of a feature branch while naming the main branch as ref; commit garbage-collected or force-pushed away; copying commit hash from a different repository.","solutions":["Verify the commit is an ancestor: git merge-base --is-ancestor <commit> <ref>","Use the ref that actually contains the commit (e.g. the feature branch ref)","Re-resolve the commit hash from the current ref tip before submitting"],"exampleFix":"// before\n{\"refName\":\"refs/heads/main\",\"commitHash\":\"abc123...\"} // commit lives on feature/x\n// after\n{\"refName\":\"refs/heads/feature/x\",\"commitHash\":\"abc123...\"}","handlingStrategy":"validation","validationCode":"// locally verify ancestry before submitting\ngit merge-base --is-ancestor <commitHash> <refName> || fail('commit not reachable from ref');","typeGuard":null,"tryCatchPattern":"try { runBuild(req); } catch (WebApplicationException e) { if (msg contains 'not reachable') reResolveCommitAndRef(); else throw e; }","preventionTips":["Derive commit hash and ref from the same source (e.g. git rev-parse refs/heads/x)","Avoid hardcoding commit hashes across branches","Handle force-push invalidation by re-resolving refs"],"tags":["rest","git","validation","commit-history"],"backgroundTag":"invalid-argument-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"}