{"record":{"id":"5a3c4cbcc4d5379c","repo":"golang/go","slug":"unexpected-response-from-git-log-q","errorCode":null,"errorMessage":"unexpected response from git log: %q","messagePattern":"unexpected response from git log: %q","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modfetch/codehost/git.go","lineNumber":657,"sourceCode":"\t}\n\treturn nil\n}\n\n// statLocal returns a new RevInfo describing rev in the local git repository.\n// It uses version as info.Version.\nfunc (r *gitRepo) statLocal(ctx context.Context, version, rev string) (*RevInfo, error) {\n\tout, err := r.runGit(ctx, \"git\", \"-c\", \"log.showsignature=false\", \"log\", \"--no-decorate\", \"-n1\", \"--format=format:%H %ct %D\", \"--end-of-options\", rev, \"--\")\n\tif err != nil {\n\t\t// Return info with Origin.RepoSum if possible to allow caching of negative lookup.\n\t\tvar info *RevInfo\n\t\tif refs, err := r.loadRefs(ctx); err == nil {\n\t\t\tinfo = r.unknownRevisionInfo(refs)\n\t\t}\n\t\treturn info, &UnknownRevisionError{Rev: rev}\n\t}\n\tf := strings.Fields(string(out))\n\tif len(f) < 2 {\n\t\treturn nil, fmt.Errorf(\"unexpected response from git log: %q\", out)\n\t}\n\thash := f[0]\n\tif strings.HasPrefix(hash, version) {\n\t\tversion = hash // extend to full hash\n\t}\n\tt, err := strconv.ParseInt(f[1], 10, 64)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid time from git log: %q\", out)\n\t}\n\n\tinfo := &RevInfo{\n\t\tOrigin: &Origin{\n\t\t\tVCS:  \"git\",\n\t\t\tURL:  r.remoteURL,\n\t\t\tHash: hash,\n\t\t},\n\t\tName:    hash,\n\t\tShort:   r.shortenObjectHash(hash),","sourceCodeStart":639,"sourceCodeEnd":675,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modfetch/codehost/git.go#L639-L675","documentation":"Thrown by gitRepo.statLocal when 'git log' succeeds (exit 0) but the output, after splitting on whitespace, has fewer than 2 fields. The expected format is '%H %ct %D' (hash, commit timestamp, refs). Fewer than 2 fields means the output is empty or malformed — a sentinel that git produced unexpected output.","triggerScenarios":"statLocal runs 'git log --format=%H %ct %D' against a revision; git returns success but the stdout is empty or a single token. This can happen with corrupted git objects, a git bug, custom git wrappers, or an object database inconsistency.","commonSituations":"Corrupted local git cache (loose/pack object damage); a git version with a formatting bug; a git alias or wrapper script interfering with output; interrupted clone leaving partial objects.","solutions":["Clear the cached VCS checkout: 'go clean -cache' or 'rm -rf $(go env GOMODCACHE)/cache/vcs'.","Run 'git fsck' on the local cached repo to detect corruption.","Upgrade git to a current stable version.","Check for git wrappers/aliases: 'type git' and 'git config --list'."],"exampleFix":"# before: corrupted cache produces malformed log output\ngo get example.com/mod@v1.0.0\n# unexpected response from git log: \"\"\n# after\ngo clean -cache\ngo get example.com/mod@v1.0.0","handlingStrategy":"fallback","validationCode":"null","typeGuard":"null","tryCatchPattern":"// On malformed git log output, clear the cache and retry once\ninfo, err := repo.Stat(ctx, rev)\nif err != nil && strings.Contains(err.Error(), \"unexpected response from git log\") {\n    os.RemoveAll(filepath.Join(gomodcache, \"cache/vcs\"))\n    info, err = repo.Stat(ctx, rev)\n}\nreturn info, err","preventionTips":["Run 'go clean -cache' when encountering unexplained git errors.","Periodically 'git fsck' cached repos if corruption recurs.","Keep git updated to a stable release.","Don't use git wrappers or aliases in build environments."],"tags":["git","malformed-output","corruption","stat-local","internal"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T11:17:21.771Z"}