Skip to content

Pre-commit: go-mod-tidy hook reports false positive when run outside a commit context #40

@HarryCampion

Description

@HarryCampion

Problem

The go-mod-tidy pre-commit hook runs go mod tidy, then checks if go.mod or go.sum differ from the staged version. On a fresh repo (or any time make fmt is run outside a git commit context), it reports a spurious failure:

go.mod or go.sum differs, please re-add it to your commit

This resolves itself once the files are git added, but is confusing when running make fmt standalone as a quality check — it gives the impression something is broken when it is not.

Suggestion

Document this behaviour clearly, or adjust the hook to only fail when there is actually a staged version to compare against (i.e. only in a true commit context).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions