theonedev/onedev · error · NotFoundException

Unable to find revision ''

Error message

Unable to find revision ''

What it means

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.

Source

Thrown at server-core/src/main/java/io/onedev/server/model/Project.java:863

	 * @param mustExist
	 * 			true to have the method throwing exception instead 
	 * 			of returning null if the revision does not exist
	 * @return
	 * 			object id of specified revision, or <tt>null</tt> if revision 
	 * 			does not exist and mustExist is specified as false
	 */
	@Nullable
	public ObjectId getObjectId(String revision, boolean mustExist) {
		if (objectIdCache == null)
			objectIdCache = new HashMap<>();
		
		Optional<ObjectId> optional = objectIdCache.get(revision);
		if (optional == null) {
			optional = Optional.fromNullable(getGitService().resolve(this, revision, false));
			objectIdCache.put(revision, optional);
		}
		if (mustExist && !optional.isPresent())
			throw new NotFoundException("Unable to find revision '" + revision + "'");
		return optional.orNull();
	}
	
	public void cacheObjectId(String revision, @Nullable ObjectId objectId) {
		if (objectIdCache == null)
			objectIdCache = new HashMap<>();
		
		objectIdCache.put(revision, Optional.fromNullable(objectId));
	}

	public Map<String, Status> getCommitStatuses(ObjectId commitId, @Nullable PullRequest request, 
												 @Nullable String refName) {
		Map<String, Collection<StatusInfo>> commitStatusInfos = getCommitStatusCache().get(commitId);
		if (commitStatusInfos == null) {
			BuildService buildService = OneDev.getInstance(BuildService.class);
			commitStatusInfos = buildService.queryStatus(this, Sets.newHashSet(commitId)).get(commitId);
			getCommitStatusCache().put(commitId, Preconditions.checkNotNull(commitStatusInfos));
		}

View on GitHub (pinned to d44925c47c)

Solutions

  1. Print/list the available branches and tags (git branch -a / project.getBranches()) and use an exact existing ref name.
  2. Verify commit SHAs belong to this repository; use the full 40-char hash when uncertain.
  3. Handle NotFoundException: catch it and fall back to the project's default branch.
  4. If a ref was recently deleted/renamed, switch callers to the new ref or HEAD.

Example fix

// before
ObjectId id = project.getCommitId("feature-x", true);
// after
ObjectId id;
try { id = project.getCommitId("feature-x", true); }
catch (NotFoundException e) { id = project.getCommitId(project.getDefaultBranch(), true); }
Defensive patterns

Strategy: validation

Validate before calling

ObjectId id = project.getCommitId(revision, false);
if (id == null) { /* fall back to default branch or report unknown revision */ }

Type guard

ObjectId id = project.getCommitId(rev, false); if (id != null) { /* safe to use */ }

Try / catch

try { ObjectId id = project.getCommitId(revision, true); } catch (NotFoundException e) { // resolve default branch or re-list refs }

Prevention

When it happens

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

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

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/524a6041329282c8. Report an issue: GitHub.