{"record":{"id":"26d2af66936ab8fe","repo":"elastic/elasticsearch","slug":"unable-to-read-the-git-revision","errorCode":null,"errorMessage":"unable to read the git revision","messagePattern":"unable to read the git revision","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/info/GitInfo.java","lineNumber":134,"sourceCode":"                    }\n                } else {\n                    File refsDir = gitDir.resolve(\"refs\").toFile();\n                    if (refsDir.exists()) {\n                        String foundRefs = Arrays.stream(refsDir.listFiles()).map(f -> f.getName()).collect(Collectors.joining(\"\\n\"));\n                        Logging.getLogger(GitInfo.class).error(\"Found git refs\\n\" + foundRefs);\n                    } else {\n                        Logging.getLogger(GitInfo.class).error(\"No git refs dir found\");\n                    }\n                    throw new GradleException(\"Can't find revision for refName \" + refName);\n                }\n            } else {\n                // we are in detached HEAD state\n                revision = ref;\n            }\n            return new GitInfo(revision, findOriginUrl(gitDir.resolve(\"config\")));\n        } catch (final IOException e) {\n            // for now, do not be lenient until we have better understanding of real-world scenarios where this happens\n            throw new GradleException(\"unable to read the git revision\", e);\n        }\n    }\n\n\n    private static String findOriginUrl(final Path configFile) throws IOException {\n        Map<String, String> props = new HashMap<>();\n\n        try (Stream<String> stream = Files.lines(configFile, StandardCharsets.UTF_8)) {\n            Iterator<String> lines = stream.iterator();\n            boolean foundOrigin = false;\n            while (lines.hasNext()) {\n                String line = lines.next().trim();\n                if (line.startsWith(\";\") || line.startsWith(\"#\")) {\n                    // ignore comments\n                    continue;\n                }\n                if (foundOrigin) {\n                    if (line.startsWith(\"[\")) {","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/info/GitInfo.java#L116-L152","documentation":"The outer catch in GitInfo.gitInfo wraps every IOException thrown while walking .git: reading HEAD, following a worktree gitdir pointer, resolving commondir, or reading the config for the origin URL. The comment explicitly notes the authors chose not to be lenient yet, so any read failure aborts the build-info lookup.","triggerScenarios":"Any IOException inside the try of gitInfo(File) that is not already converted to a GradleException — e.g. readFirstLine on HEAD fails, the commondir file is missing, Files.lines on packed-refs throws, or findOriginUrl cannot read config.","commonSituations":"A truncated or permission-denied .git file; a worktree whose gitdir pointer dangles (the linked directory was deleted); an I/O error reading the config file; disk corruption in .git; a submodule pointer whose modules dir was removed.","solutions":["Read the caused-by IOException for the exact path that failed.","Re-clone or `git worktree prune` to remove dangling worktree references.","Verify the user running the build has read access to the entire .git tree.","If building from a source tarball, ensure it preserved the .git directory or accept that git info will be unknown."],"exampleFix":"// before: dangling worktree gitdir pointer causes IOException\n// prune and recreate\ngit worktree prune && git worktree add ../wt main","handlingStrategy":"try-catch","validationCode":"// Verify the minimal .git paths are readable before building\nPath dotGit = rootDir.toPath().resolve(\".git\");\nif (!Files.exists(dotGit)) { /* no git info available */ }\nelse if (!Files.isReadable(dotGit.resolve(\"HEAD\"))) {\n    throw new GradleException(\".git/HEAD is not readable; cannot compute git revision\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    GitInfo info = GitInfo.gitInfo(rootDir);\n} catch (GradleException e) {\n    if (e.getMessage().equals(\"unable to read the git revision\")) {\n        // Inspect e.getCause() for the failing path; fall back to a placeholder if your build tolerates it\n        getLogger().warn(\"Skipping git info: {}\", e.getCause().getMessage());\n    } else { throw e; }\n}","preventionTips":["Ensure the build user has read access across the whole .git tree.","Prune dangling worktrees with `git worktree prune` before building.","Avoid source tarballs that drop .git when the build needs git metadata."],"tags":["gradle","git","metadata","io"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}