elastic/elasticsearch · error · RuntimeException
git command failed with exit code {} command: {} output: {}
Error message
git command failed with exit code {}
command: {}
output:
{} What it means
RuntimeException from TransportVersionResourcesService when a git invocation (run with -C pointing at the transport-resources dir) exits with a non-zero code. The message includes the exit code, the full command, and git's combined stdout/stderr so the underlying git error is visible.
Source
Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/TransportVersionResourcesService.java:489
}
// run a git command, relative to the transport version resources directory
private String gitCommand(String... args) {
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
List<String> command = new ArrayList<>();
Collections.addAll(command, "git", "-C", getTransportResourcesDir().toString());
Collections.addAll(command, args);
ExecResult result = getExecOperations().exec(spec -> {
spec.setCommandLine(command);
spec.setStandardOutput(stdout);
spec.setErrorOutput(stdout);
spec.setIgnoreExitValue(true);
});
if (result.getExitValue() != 0) {
throw new RuntimeException(
"git command failed with exit code "
+ result.getExitValue()
+ System.lineSeparator()
+ "command: "
+ String.join(" ", command)
+ System.lineSeparator()
+ "output:"
+ System.lineSeparator()
+ stdout.toString(StandardCharsets.UTF_8)
);
}
return stdout.toString(StandardCharsets.UTF_8);
}
/** Read the alternate (non-serverless) upper bound from the working tree. */
public TransportVersionUpperBound getAlternateUpperBound(Path file) throws IOException {
String contents = Files.readString(file, StandardCharsets.UTF_8).strip();View on GitHub (pinned to db6a809a66)
Solutions
- Read the embedded git stderr in the message - it states the precise git-level failure.
- Ensure the transport-resources directory is a valid git repo and git is on PATH for the Gradle JVM.
- If the failure is about a missing object/revision, fetch from the remote and retry.
- For a corrupted index, run git -C <dir> reset/--hard or re-clone the resources dir.
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-flight: ensure the resources dir is a git repo and git is available
File dir = getTransportResourcesDir();
if (!new File(dir, ".git").exists() && !isInsideWorkTree(dir)) {
throw new IllegalStateException(dir + " is not a git repository");
} Try / catch
try {
runGit(args);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("git command failed")) {
// surface exit code + stderr already embedded; optionally retry once after fetch
getLogger().error("git failure:\n{}", e.getMessage());
}
throw e;
} Prevention
- Ensure git is on PATH for the Gradle JVM.
- Keep the transport-resources directory a clean, initialized git repo.
- Fetch from remote before running tasks that read git-base objects.
When it happens
Trigger: Any git command the service runs (log, show, cat-file, checkout of resource files, status) fails - e.g. the resources dir is not a git repo, the requested revision/object is missing, git is not on PATH, or there are unrecoverable index conflicts.
Common situations: The transport-resources directory is not initialized as a git repo; running offline without the objects git would fetch; a corrupted .git; git not installed or not on PATH in the build JVM's environment; referencing a sha that does not exist locally.
Related errors
- Missing upper bound {} for release version {}
- Missing upper bound {} for stack version {}
- Invalid increment {}, must be a positive integer
- Invalid increment {}, must be no larger than 1000
- Could not find base id: {}
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/70838d41da652ded.
Report an issue: GitHub.