{"record":{"id":"524a6041329282c8","repo":"theonedev/onedev","slug":"unable-to-find-revision","errorCode":null,"errorMessage":"Unable to find revision ''","messagePattern":"Unable to find revision ''","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/model/Project.java","lineNumber":863,"sourceCode":"\t * @param mustExist\n\t * \t\t\ttrue to have the method throwing exception instead \n\t * \t\t\tof returning null if the revision does not exist\n\t * @return\n\t * \t\t\tobject id of specified revision, or <tt>null</tt> if revision \n\t * \t\t\tdoes not exist and mustExist is specified as false\n\t */\n\t@Nullable\n\tpublic ObjectId getObjectId(String revision, boolean mustExist) {\n\t\tif (objectIdCache == null)\n\t\t\tobjectIdCache = new HashMap<>();\n\t\t\n\t\tOptional<ObjectId> optional = objectIdCache.get(revision);\n\t\tif (optional == null) {\n\t\t\toptional = Optional.fromNullable(getGitService().resolve(this, revision, false));\n\t\t\tobjectIdCache.put(revision, optional);\n\t\t}\n\t\tif (mustExist && !optional.isPresent())\n\t\t\tthrow new NotFoundException(\"Unable to find revision '\" + revision + \"'\");\n\t\treturn optional.orNull();\n\t}\n\t\n\tpublic void cacheObjectId(String revision, @Nullable ObjectId objectId) {\n\t\tif (objectIdCache == null)\n\t\t\tobjectIdCache = new HashMap<>();\n\t\t\n\t\tobjectIdCache.put(revision, Optional.fromNullable(objectId));\n\t}\n\n\tpublic Map<String, Status> getCommitStatuses(ObjectId commitId, @Nullable PullRequest request, \n\t\t\t\t\t\t\t\t\t\t\t\t @Nullable String refName) {\n\t\tMap<String, Collection<StatusInfo>> commitStatusInfos = getCommitStatusCache().get(commitId);\n\t\tif (commitStatusInfos == null) {\n\t\t\tBuildService buildService = OneDev.getInstance(BuildService.class);\n\t\t\tcommitStatusInfos = buildService.queryStatus(this, Sets.newHashSet(commitId)).get(commitId);\n\t\t\tgetCommitStatusCache().put(commitId, Preconditions.checkNotNull(commitStatusInfos));\n\t\t}","sourceCodeStart":845,"sourceCodeEnd":881,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/model/Project.java#L845-L881","documentation":"Project.getCommitId(revision, mustExist) resolves a revision string (branch, tag, sha, 'HEAD~1', etc.) to a git ObjectId, caching results. When mustExist is true and git cannot resolve the revision, a NotFoundException \"Unable to find revision '<revision>'\" is thrown.","triggerScenarios":"project.getCommitId(rev, true) where rev is a nonexistent branch/tag/commit hash, a typo, or a ref deleted (e.g. branch removed or history rewritten) after the caller captured the name.","commonSituations":"API clients referencing a branch that was deleted; commit SHA abbreviated incorrectly or from another repository; default branch renamed so 'master' no longer resolves; using a tag that hasn't been pushed to the repo; typo like 'heads/main' vs 'refs/heads/main'.","solutions":["Print/list the available branches and tags (git branch -a / project.getBranches()) and use an exact existing ref name.","Verify commit SHAs belong to this repository; use the full 40-char hash when uncertain.","Handle NotFoundException: catch it and fall back to the project's default branch.","If a ref was recently deleted/renamed, switch callers to the new ref or HEAD."],"exampleFix":"// before\nObjectId id = project.getCommitId(\"feature-x\", true);\n// after\nObjectId id;\ntry { id = project.getCommitId(\"feature-x\", true); }\ncatch (NotFoundException e) { id = project.getCommitId(project.getDefaultBranch(), true); }","handlingStrategy":"validation","validationCode":"ObjectId id = project.getCommitId(revision, false);\nif (id == null) { /* fall back to default branch or report unknown revision */ }","typeGuard":"ObjectId id = project.getCommitId(rev, false); if (id != null) { /* safe to use */ }","tryCatchPattern":"try { ObjectId id = project.getCommitId(revision, true); } catch (NotFoundException e) { // resolve default branch or re-list refs }","preventionTips":["Use mustExist=false for explorative resolution and null-check","Never cache revision strings across branch deletions/renames","List branches/tags to confirm exact ref names before use"],"tags":["git","revision","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-14T05:17:10.506Z"}