{"record":{"id":"70838d41da652ded","repo":"elastic/elasticsearch","slug":"git-command-failed-with-exit-code-command-o","errorCode":null,"errorMessage":"git command failed with exit code {}\ncommand: {}\noutput:\n{}","messagePattern":"git command failed with exit code (.+?)\ncommand: (.+?)\noutput:\n(.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/TransportVersionResourcesService.java","lineNumber":489,"sourceCode":"    }\n\n    // run a git command, relative to the transport version resources directory\n    private String gitCommand(String... args) {\n        ByteArrayOutputStream stdout = new ByteArrayOutputStream();\n\n        List<String> command = new ArrayList<>();\n        Collections.addAll(command, \"git\", \"-C\", getTransportResourcesDir().toString());\n        Collections.addAll(command, args);\n\n        ExecResult result = getExecOperations().exec(spec -> {\n            spec.setCommandLine(command);\n            spec.setStandardOutput(stdout);\n            spec.setErrorOutput(stdout);\n            spec.setIgnoreExitValue(true);\n        });\n\n        if (result.getExitValue() != 0) {\n            throw new RuntimeException(\n                \"git command failed with exit code \"\n                    + result.getExitValue()\n                    + System.lineSeparator()\n                    + \"command: \"\n                    + String.join(\" \", command)\n                    + System.lineSeparator()\n                    + \"output:\"\n                    + System.lineSeparator()\n                    + stdout.toString(StandardCharsets.UTF_8)\n            );\n        }\n\n        return stdout.toString(StandardCharsets.UTF_8);\n    }\n\n    /** Read the alternate (non-serverless) upper bound from the working tree. */\n    public TransportVersionUpperBound getAlternateUpperBound(Path file) throws IOException {\n        String contents = Files.readString(file, StandardCharsets.UTF_8).strip();","sourceCodeStart":471,"sourceCodeEnd":507,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/TransportVersionResourcesService.java#L471-L507","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight: ensure the resources dir is a git repo and git is available\nFile dir = getTransportResourcesDir();\nif (!new File(dir, \".git\").exists() && !isInsideWorkTree(dir)) {\n    throw new IllegalStateException(dir + \" is not a git repository\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    runGit(args);\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"git command failed\")) {\n        // surface exit code + stderr already embedded; optionally retry once after fetch\n        getLogger().error(\"git failure:\\n{}\", e.getMessage());\n    }\n    throw e;\n}","preventionTips":["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."],"tags":["transport-version","git","subprocess","build-tooling"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}