config

package
v1.8.5 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SubFiles       string = "{files}"
	SubAllFiles    string = "{all_files}"
	SubStagedFiles string = "{staged_files}"
	SubPushFiles   string = "{push_files}"
)
View Source
const (
	DefaultConfigName     = "lefthook.yml"
	DefaultSourceDir      = ".lefthook"
	DefaultSourceDirLocal = ".lefthook-local"
)
View Source
const CMD = "{cmd}"
View Source
const ChecksumFileName = "lefthook.checksum"

ChecksumFileName - the file, which is used just to store the current config checksum version.

View Source
const GhostHookName = "prepare-commit-msg"

GhostHookName - the hook which logs are not shown and which is used for synchronizing hooks.

Variables

View Source
var AvailableHooks = map[string]struct{}{
	"pre-commit":            {},
	"pre-push":              {},
	"commit-msg":            {},
	"applypatch-msg":        {},
	"fsmonitor-watchman":    {},
	"p4-changelist":         {},
	"p4-post-changelist":    {},
	"p4-pre-submit":         {},
	"p4-prepare-changelist": {},
	"post-applypatch":       {},
	"post-checkout":         {},
	"post-commit":           {},
	"post-index-change":     {},
	"post-merge":            {},
	"post-receive":          {},
	"post-rewrite":          {},
	"post-update":           {},
	"pre-applypatch":        {},
	"pre-auto-gc":           {},
	"pre-merge-commit":      {},
	"pre-rebase":            {},
	"pre-receive":           {},
	"prepare-commit-msg":    {},
	"proc-receive":          {},
	"push-to-checkout":      {},
	"rebase":                {},
	"reference-transaction": {},
	"sendemail-validate":    {},
	"update":                {},
}

AvailableHooks - list of hooks taken from https://git-scm.com/docs/githooks.

Functions

func HookUsesPushFiles added in v1.3.6

func HookUsesPushFiles(hook string) bool

func HookUsesStagedFiles added in v1.3.0

func HookUsesStagedFiles(hook string) bool

func KnownHook added in v1.8.1

func KnownHook(hook string) bool

func NewSkipChecker added in v1.6.6

func NewSkipChecker(cmd system.Command) *skipChecker

Types

type Command

type Command struct {
	Run   string `json:"run"             mapstructure:"run"   toml:"run"             yaml:"run"`
	Files string `json:"files,omitempty" mapstructure:"files" toml:"files,omitempty" yaml:",omitempty"`

	Skip interface{}       `json:"skip,omitempty" mapstructure:"skip" toml:"skip,omitempty,inline" yaml:",omitempty"`
	Only interface{}       `json:"only,omitempty" mapstructure:"only" toml:"only,omitempty,inline" yaml:",omitempty"`
	Tags []string          `json:"tags,omitempty" mapstructure:"tags" toml:"tags,omitempty"        yaml:",omitempty"`
	Env  map[string]string `json:"env,omitempty"  mapstructure:"env"  toml:"env,omitempty"         yaml:",omitempty"`

	FileTypes []string `json:"file_types,omitempty" mapstructure:"file_types" toml:"file_types,omitempty" yaml:"file_types,omitempty"`

	Glob    string      `json:"glob,omitempty"    mapstructure:"glob"    toml:"glob,omitempty"    yaml:",omitempty"`
	Root    string      `json:"root,omitempty"    mapstructure:"root"    toml:"root,omitempty"    yaml:",omitempty"`
	Exclude interface{} `json:"exclude,omitempty" mapstructure:"exclude" toml:"exclude,omitempty" yaml:",omitempty"`

	Priority    int    `json:"priority,omitempty"    mapstructure:"priority"    toml:"priority,omitempty"    yaml:",omitempty"`
	FailText    string `json:"fail_text,omitempty"   mapstructure:"fail_text"   toml:"fail_text,omitempty"   yaml:"fail_text,omitempty"`
	Interactive bool   `json:"interactive,omitempty" mapstructure:"interactive" toml:"interactive,omitempty" yaml:",omitempty"`
	UseStdin    bool   `json:"use_stdin,omitempty"   mapstructure:"use_stdin"   toml:"use_stdin,omitempty"   yaml:",omitempty"`
	StageFixed  bool   `json:"stage_fixed,omitempty" mapstructure:"stage_fixed" toml:"stage_fixed,omitempty" yaml:"stage_fixed,omitempty"`
}

func (Command) DoSkip

func (c Command) DoSkip(state func() git.State) bool

func (Command) ExecutionPriority added in v1.6.8

func (c Command) ExecutionPriority() int

func (Command) Validate

func (c Command) Validate() error

type Config

type Config struct {
	MinVersion              string      `mapstructure:"min_version,omitempty"`
	SourceDir               string      `mapstructure:"source_dir"`
	SourceDirLocal          string      `mapstructure:"source_dir_local"`
	Rc                      string      `mapstructure:"rc,omitempty"`
	SkipOutput              interface{} `mapstructure:"skip_output,omitempty"`
	Output                  interface{} `mapstructure:"output,omitempty"`
	Extends                 []string    `mapstructure:"extends,omitempty"`
	NoTTY                   bool        `mapstructure:"no_tty,omitempty"`
	AssertLefthookInstalled bool        `mapstructure:"assert_lefthook_installed,omitempty"`
	Colors                  interface{} `mapstructure:"colors,omitempty"`
	SkipLFS                 bool        `mapstructure:"skip_lfs,omitempty"`

	// Deprecated: use Remotes
	Remote  *Remote   `mapstructure:"remote,omitempty"`
	Remotes []*Remote `mapstructure:"remotes,omitempty"`

	Hooks map[string]*Hook `mapstructure:"-"`
}

func Load

func Load(fs afero.Fs, repo *git.Repository) (*Config, error)

Loads configs from the given directory with extensions.

func (*Config) Dump added in v1.4.0

func (c *Config) Dump(format DumpFormat, out io.Writer) error

func (*Config) Md5 added in v1.8.0

func (c *Config) Md5() (checksum string, err error)

func (*Config) Validate

func (c *Config) Validate() error

type DumpFormat added in v1.7.16

type DumpFormat int
const (
	YAMLFormat DumpFormat = iota
	TOMLFormat
	JSONFormat
	JSONCompactFormat
)

type Hook

type Hook struct {
	// Should be unmarshalled with `mapstructure:"commands"`
	// But replacing '{cmd}' is still an issue
	// Unmarshalling it manually, so omit auto unmarshalling
	Commands map[string]*Command `json:"commands,omitempty" mapstructure:"-" toml:"commands,omitempty" yaml:",omitempty"`

	// Should be unmarshalled with `mapstructure:"scripts"`
	// But parsing keys with dots in it is still an issue: https://github.com/spf13/viper/issues/324
	// Unmarshalling it manually, so omit auto unmarshalling
	Scripts map[string]*Script `json:"scripts,omitempty" mapstructure:"-" toml:"scripts,omitempty" yaml:",omitempty"`

	Files       string      `json:"files,omitempty"        mapstructure:"files"        toml:"files,omitempty"        yaml:",omitempty"`
	Parallel    bool        `json:"parallel,omitempty"     mapstructure:"parallel"     toml:"parallel,omitempty"     yaml:",omitempty"`
	Piped       bool        `json:"piped,omitempty"        mapstructure:"piped"        toml:"piped,omitempty"        yaml:",omitempty"`
	Follow      bool        `json:"follow,omitempty"       mapstructure:"follow"       toml:"follow,omitempty"       yaml:",omitempty"`
	ExcludeTags []string    `json:"exclude_tags,omitempty" mapstructure:"exclude_tags" toml:"exclude_tags,omitempty" yaml:"exclude_tags,omitempty"`
	Skip        interface{} `json:"skip,omitempty"         mapstructure:"skip"         toml:"skip,omitempty,inline"  yaml:",omitempty"`
	Only        interface{} `json:"only,omitempty"         mapstructure:"only"         toml:"only,omitempty,inline"  yaml:",omitempty"`
}

func (*Hook) DoSkip added in v1.2.2

func (h *Hook) DoSkip(state func() git.State) bool

func (*Hook) Validate

func (h *Hook) Validate() error

type NotFoundError added in v1.3.7

type NotFoundError struct {
	// contains filtered or unexported fields
}

NotFoundError wraps viper.ConfigFileNotFoundError for lefthook.

func (NotFoundError) Error added in v1.3.7

func (err NotFoundError) Error() string

Error returns message of viper.ConfigFileNotFoundError.

type Remote added in v1.2.0

type Remote struct {
	GitURL string `json:"git_url,omitempty" mapstructure:"git_url"       toml:"git_url"       yaml:"git_url"`
	Ref    string `json:"ref,omitempty"     mapstructure:"ref,omitempty" toml:"ref,omitempty" yaml:",omitempty"`
	// Deprecated
	Config           string   `` /* 130-byte string literal not displayed */
	Configs          []string `` /* 130-byte string literal not displayed */
	Refetch          bool     `` /* 130-byte string literal not displayed */
	RefetchFrequency string   `` /* 130-byte string literal not displayed */
}

func (*Remote) Configured added in v1.2.0

func (r *Remote) Configured() bool

type Script

type Script struct {
	Runner string `json:"runner" mapstructure:"runner" toml:"runner" yaml:"runner"`

	Skip     interface{}       `json:"skip,omitempty"     mapstructure:"skip"     toml:"skip,omitempty,inline" yaml:",omitempty"`
	Only     interface{}       `json:"only,omitempty"     mapstructure:"only"     toml:"only,omitempty,inline" yaml:",omitempty"`
	Tags     []string          `json:"tags,omitempty"     mapstructure:"tags"     toml:"tags,omitempty"        yaml:",omitempty"`
	Env      map[string]string `json:"env,omitempty"      mapstructure:"env"      toml:"env,omitempty"         yaml:",omitempty"`
	Priority int               `json:"priority,omitempty" mapstructure:"priority" toml:"priority,omitempty"    yaml:",omitempty"`

	FailText    string `json:"fail_text,omitempty"   mapstructure:"fail_text"   toml:"fail_text,omitempty"   yaml:"fail_text,omitempty"`
	Interactive bool   `json:"interactive,omitempty" mapstructure:"interactive" toml:"interactive,omitempty" yaml:",omitempty"`
	UseStdin    bool   `json:"use_stdin,omitempty"   mapstructure:"use_stdin"   toml:"use_stdin,omitempty"   yaml:",omitempty"`
	StageFixed  bool   `json:"stage_fixed,omitempty" mapstructure:"stage_fixed" toml:"stage_fixed,omitempty" yaml:"stage_fixed,omitempty"`
}

func (Script) DoSkip

func (s Script) DoSkip(state func() git.State) bool

func (Script) ExecutionPriority added in v1.6.8

func (s Script) ExecutionPriority() int

Jump to

Keyboard shortcuts

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