theonedev/onedev · error · ValidationException

Invalid commit id

Error message

Invalid commit id

What it means

CommitInput converts input strings into commit ids for commit-type input parameters. A value is valid only if JGit's ObjectId.isId accepts it (40-char hex SHA-1). Any other single value is rejected with ValidationException('Invalid commit id').

Source

Thrown at server-core/src/main/java/io/onedev/server/buildspecmodel/inputspec/CommitInput.java:36

		inputSpec.appendField(buffer, index, "String");
		inputSpec.appendCommonAnnotations(buffer, index);
		buffer.append("    @CommitHash\n");
		if (!inputSpec.isAllowEmpty())
			buffer.append("    @NotEmpty\n");
		inputSpec.appendMethods(buffer, index, "String", null, null);
		
		return buffer.toString();
	}

	public static Object convertToObject(List<String> strings) {
		if (strings.size() == 0) {
			return null;
		} else if (strings.size() == 1) {
			String value = strings.iterator().next();
			if (ObjectId.isId(value))
				return value;
			else
				throw new ValidationException("Invalid commit id");
		} else {
			throw new ValidationException("Not eligible for multi-value");
		}
	}

	public static List<String> convertToStrings(Object value) {
		if (value instanceof String)
			return Lists.newArrayList((String) value);
		else
			return new ArrayList<>();
	}
	
}

View on GitHub (pinned to d44925c47c)

Solutions

  1. Provide the full 40-character hexadecimal commit SHA.
  2. Resolve the branch/tag to its full SHA first (git rev-parse <ref>) and use that value.
  3. Fix parameter expressions so they resolve to a full SHA rather than a ref name.
  4. Extend the abbreviated SHA before entering it.

Example fix

// before
value: "main"
// after
value: "3f2a9c8d1e0b7a6f5c4d3e2f1a0b9c8d7e6f5a4b"
Defensive patterns

Strategy: validation

Validate before calling

// Validate a full 40-char hex SHA before submitting
if (!/^[0-9a-fA-F]{40}$/.test(commitValue)) {
  throw new Error("Provide a full commit SHA (git rev-parse <ref>)");
}

Type guard

boolean isCommitId(String v) {
  return v != null && org.eclipse.jgit.lib.ObjectId.isId(v.trim());
}

Try / catch

try {
    Object commit = CommitInput.convertToObject(strings);
} catch (ValidationException e) {
    // prompt user for full 40-char SHA
}

Prevention

When it happens

Trigger: convertToObject receives a single string that is not a valid git object id — e.g. a branch name, short SHA, 'HEAD', or a SHA with invalid characters/length.

Common situations: Typing a branch name or tag instead of the full commit hash; pasting an abbreviated SHA (7-8 chars); parameter substitution producing an empty or malformed value.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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