golangci/golangci-lint · error
can't prepare diff by revgrep: %w
Error message
can't prepare diff by revgrep: %w
What it means
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.
Source
Thrown at pkg/result/processors/diff.go:79
return nil, fmt.Errorf("can't read from patch file %s: %w", p.patchFilePath, err)
}
patchReader = bytes.NewReader(patch)
case p.patch != "":
patchReader = strings.NewReader(p.patch)
}
checker := revgrep.Checker{
Patch: patchReader,
RevisionFrom: p.fromRev,
MergeBase: p.fromMergeBase,
WholeFiles: p.wholeFiles,
}
err := checker.Prepare(context.Background())
if err != nil {
return nil, fmt.Errorf("can't prepare diff by revgrep: %w", err)
}
return transformIssues(issues, func(issue *result.Issue) *result.Issue {
if issue.FromLinter == typeCheckName {
// Never hide typechecking errors.
return issue
}
hunkPos, isNew := checker.IsNew(issue.WorkingDirectoryRelativePath, issue.Line())
if !isNew {
return nil
}
newIssue := *issue
newIssue.HunkPos = hunkPos
return &newIssue
}), nilView on GitHub (pinned to ed7a235d2d)
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>
Example fix
# before (GitHub Actions)
- uses: actions/checkout@v4
- run: golangci-lint run --new-from-rev=main
# after
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: golangci-lint run --new-from-rev=origin/main Defensive patterns
Strategy: validation
Validate before calling
# shell: verify base revision exists before running
if ! git cat-file -e "$BASE_REV^{commit}" 2>/dev/null; then
echo "base revision $BASE_REV not found"; exit 1
fi Try / catch
if err != nil {
if strings.Contains(err.Error(), "can't prepare diff by revgrep") {
log.Fatalf("git/diff setup problem: %v — is the repo a full clone?", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: --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.
Related errors
- clone golangci-lint: %w
- failed to build packages cache: %w
- context loading failed: %w
- failed to get goenv: %w
- get git root: %w
AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02).
Data as JSON: /api/errors/ce4be9c65500fcc6.
Report an issue: GitHub.