githooksync

package
v0.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package githooksync implements MDS048, the git-hook-sync rule. It reports when the .gitattributes managed block or the pre-merge-commit hook drifts from the canonical content derived from the project's .mdsmith.yml ignore patterns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rule

type Rule struct{}

Rule checks that mdsmith-managed git hooks and .gitattributes are in sync with the canonical content computed from the project's .mdsmith.yml ignore patterns.

The rule is runnable in its zero value: it has no required runtime settings, so users can opt in via the bool form `git-hook-sync: true`. ApplySettings is still implemented to validate unknown keys when the user provides a mapping, but execution does not depend on it being called.

func (*Rule) ApplySettings

func (r *Rule) ApplySettings(settings map[string]any) error

ApplySettings implements rule.Configurable. The rule has no runtime settings, so this only rejects unknown keys when a user supplies a mapping. The rule executes regardless of whether ApplySettings is invoked, so a bool-only enable (`git-hook-sync: true`) also works.

func (*Rule) Category

func (r *Rule) Category() string

Category implements rule.Rule.

func (*Rule) Check

func (r *Rule) Check(f *lint.File) []lint.Diagnostic

Check implements rule.Rule.

func (*Rule) DefaultSettings

func (r *Rule) DefaultSettings() map[string]any

DefaultSettings implements rule.Configurable.

func (*Rule) EnabledByDefault

func (r *Rule) EnabledByDefault() bool

EnabledByDefault implements rule.Defaultable.

func (*Rule) Fix added in v0.9.0

func (r *Rule) Fix(f *lint.File) []byte

Fix implements rule.FixableRule. It regenerates the .gitattributes managed block from the canonical glob set when the merge driver is registered. The pre-merge-commit hook is not auto-fixed because it is an executable script and modifying executable files during automated fixes could be surprising or unsafe. Users must run `mdsmith pre-merge-commit install` manually to update the hook.

The fix only runs when f.FS != nil (a real file, not stdin) and when the repository has opted into the merge driver via `git config merge.mdsmith.driver`. If neither condition holds, the original file content is returned unchanged.

Fix short-circuits via a GlobsEqual check when .gitattributes is already in sync, so linting many files in the same repo does not trigger redundant rewrites. Subsequent calls may still do real work in two cases: drift has reappeared (e.g. an external tool changed the managed block), or a previous staging attempt failed and needs retrying.

func (*Rule) ID

func (r *Rule) ID() string

ID implements rule.Rule.

func (*Rule) Name

func (r *Rule) Name() string

Name implements rule.Rule.

func (*Rule) RepoScopedDiagnostics added in v0.20.0

func (r *Rule) RepoScopedDiagnostics() bool

RepoScopedDiagnostics implements rule.RepoScoped. git-hook-sync anchors every diagnostic to the repository .gitattributes path, independent of the host file being linted, so the same (File, Line, Column, RuleID, Message) tuple recurs for every markdown file in the repo. DedupeDiagnostics collapses these duplicates; this marker lets the engine skip that allocation when git-hook-sync is disabled.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL