Skip to main content

Config

Struct Config 

Source
pub struct Config {
    pub version: String,
    pub include: Vec<IncludeEntry>,
    pub definitions: BTreeMap<String, DefinitionEntry>,
    pub hooks: Hooks,
    pub cache: GlobalCache,
}

Fields§

§version: String

Schema version

§include: Vec<IncludeEntry>

External file includes. Import scripts from package.json, Cargo.toml, etc.

Defines named references to external files. Use $include: in hook commands to reference them.

Example:

include:
  - local:
      path: package.json
      type: json
      ref: packagejson

hooks:
  pre-commit:
    commands:
      - $include: packagejson
        args: scripts.lint
§definitions: BTreeMap<String, DefinitionEntry>

Reusable command definitions for YAML anchors.

Define command templates here using YAML anchors (&name), then reference them with YAML aliases (*name) inside hook command lists. A list alias is automatically flattened into the parent sequence.

Single command anchor:

definitions:
  lint: &lint
    name: lint
    run: cargo clippy -- -D warnings

List-of-commands anchor:

definitions:
  quality: &quality
    - name: lint
      run: cargo clippy
    - name: audit
      run: cargo audit

Usage in hooks (list aliases are inlined automatically):

hooks:
  pre-commit:
    commands:
      - name: fmt
        run: cargo fmt --check
      - *lint        # single command
      - *quality     # expands to two commands inline
§hooks: Hooks

Hook definitions. Keys are git hook names (e.g. pre-commit, commit-msg).

§cache: GlobalCache

Smart caching — skip commands whose inputs haven’t changed.

Set enabled: true here, then add a cache.inputs list to each command you want to cache. The cache key is a SHA-256 of the command script, any extra cache.key strings, and the content of every input file. A cache hit causes the command to be skipped with a “cached” message. Cache entries are stored in .githops/cache/ (or cache.dir).

Example:

cache:
  enabled: true

hooks:
  pre-commit:
    commands:
      - name: lint
        run: cargo clippy -- -D warnings
        cache:
          inputs: ["src/**/*.rs", "Cargo.toml"]
      - name: test
        run: cargo test
        cache:
          inputs: ["src/**/*.rs", "tests/**/*.rs"]
          key: ["$RUST_TOOLCHAIN"]

Implementations§

Source§

impl Config

Source

pub fn load(path: &Path) -> Result<Self>

Source

pub fn find() -> Result<(Self, PathBuf)>

Find and load config from the current directory.

Source

pub fn save(&self, path: &Path) -> Result<()>

Trait Implementations§

Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Config

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Config

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for Config

Source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
Source§

impl Serialize for Config

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,