config

package
v1.6.10 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 18 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 = [...]string{
	"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 HookAvailable

func HookAvailable(hook string) bool

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 NewSkipChecker added in v1.6.6

func NewSkipChecker(executor Executor) *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 string `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(gitState 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"`

	// 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(asJSON bool, asTOML bool) error

func (*Config) Validate

func (c *Config) Validate() error

type Executor added in v1.6.9

type Executor interface {
	Execute(args []string, root string) (string, error)
}

Executor is a general execution interface for implicit commands.

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(gitState 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   `json:"config,omitempty"  mapstructure:"config,omitempty"  toml:"config,omitempty"  yaml:",omitempty"`
	Configs []string `json:"configs,omitempty" mapstructure:"configs,omitempty" toml:"configs,omitempty" yaml:",omitempty"`
}

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(gitState 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