{"record":{"id":"ce4be9c65500fcc6","repo":"golangci/golangci-lint","slug":"can-t-prepare-diff-by-revgrep-w","errorCode":null,"errorMessage":"can't prepare diff by revgrep: %w","messagePattern":"can't prepare diff by revgrep: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/result/processors/diff.go","lineNumber":79,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"can't read from patch file %s: %w\", p.patchFilePath, err)\n\t\t}\n\n\t\tpatchReader = bytes.NewReader(patch)\n\n\tcase p.patch != \"\":\n\t\tpatchReader = strings.NewReader(p.patch)\n\t}\n\n\tchecker := revgrep.Checker{\n\t\tPatch:        patchReader,\n\t\tRevisionFrom: p.fromRev,\n\t\tMergeBase:    p.fromMergeBase,\n\t\tWholeFiles:   p.wholeFiles,\n\t}\n\n\terr := checker.Prepare(context.Background())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"can't prepare diff by revgrep: %w\", err)\n\t}\n\n\treturn transformIssues(issues, func(issue *result.Issue) *result.Issue {\n\t\tif issue.FromLinter == typeCheckName {\n\t\t\t// Never hide typechecking errors.\n\t\t\treturn issue\n\t\t}\n\n\t\thunkPos, isNew := checker.IsNew(issue.WorkingDirectoryRelativePath, issue.Line())\n\t\tif !isNew {\n\t\t\treturn nil\n\t\t}\n\n\t\tnewIssue := *issue\n\t\tnewIssue.HunkPos = hunkPos\n\n\t\treturn &newIssue\n\t}), nil","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/result/processors/diff.go#L61-L97","documentation":"The diff processor asked the revgrep checker to prepare the diff (against the base revision or merge base) and revgrep failed. This wraps the underlying git/diff error so the developer sees why the changed-lines computation could not be produced. Without a prepared diff, patch-based filtering of issues cannot proceed.","triggerScenarios":"Process is called with a from-revision (e.g. --new-from-rev) or fromMergeBase and the revgrep checker's Prepare fails — typically because the revision does not exist in the repository or git operations fail.","commonSituations":"--new-from-rev references a commit not present in a shallow CI clone; running outside a git repository; merge-base computation fails on detached HEAD or unrelated histories; wrong branch name in CI configuration.","solutions":["Ensure the base revision exists: run in a full (non-shallow) clone or add a fetch-depth/fetch of the target branch","Verify you are running inside a git repository","Check the --new-from-rev value matches a real commit/branch (e.g. origin/main)","Test the diff manually: git diff <rev>"],"exampleFix":"# before (GitHub Actions)\n- uses: actions/checkout@v4\n- run: golangci-lint run --new-from-rev=main\n# after\n- uses: actions/checkout@v4\n  with:\n    fetch-depth: 0\n- run: golangci-lint run --new-from-rev=origin/main","handlingStrategy":"validation","validationCode":"# shell: verify base revision exists before running\nif ! git cat-file -e \"$BASE_REV^{commit}\" 2>/dev/null; then\n  echo \"base revision $BASE_REV not found\"; exit 1\nfi","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"can't prepare diff by revgrep\") {\n        log.Fatalf(\"git/diff setup problem: %v — is the repo a full clone?\", err)\n    }\n    return err\n}","preventionTips":["Use fetch-depth: 0 (or fetch the target branch) in shallow CI clones","Always run from a repository workdir","Reference remote-tracking revisions like origin/main, and test `git diff <rev>` in CI first"],"tags":["git","diff","ci"],"backgroundTag":"git-revision-not-found","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}