diff --git a/hooked-book/source/configuration/README.md b/hooked-book/source/configuration/README.md index 3770c54..f6d2432 100644 --- a/hooked-book/source/configuration/README.md +++ b/hooked-book/source/configuration/README.md @@ -29,7 +29,7 @@ Pre-commit hooks are defined using `pre_commit` [arrays of tables][toml-arrays-o | command[^command-and-script] | String | | A command to run when the hook is called. | | script[^command-and-script] | String | | A script to run when the hook is called. This script should be executable and be located inside the configured general directory. | | on_failure | String | stop | What to do when the hook task returns a non-zero status code. Can be either "continue" or "stop". | -| git_staged | Optional list of strings | | A list of [globs][globset-docs] that will be checked against staged files. If none of the globs match the hook will be skipped. With no globs defined at all the hook will always run. | +| staged | Optional list of strings | | A list of [globs][globset-docs] that will be checked against staged files. If none of the globs match the hook will be skipped. With no globs defined at all the hook will always run. | ```toml [[pre_commit]] @@ -40,7 +40,7 @@ command = "echo \"Hey, $USER!\"" name = "Script Example" script = "example.sh" on_failure = "continue" -git_staged = ["*.txt"] +staged = ["*.txt"] ``` ## Footnotes diff --git a/hooked-cli/source/cli/run.rs b/hooked-cli/source/cli/run.rs index 2763312..2c5a4de 100644 --- a/hooked-cli/source/cli/run.rs +++ b/hooked-cli/source/cli/run.rs @@ -39,10 +39,10 @@ pub fn hooked_run(config: Config, hook_type: String) -> Result<()> { 'hook_loop: for hook in config.pre_commit { let hook_name = hook.name.unwrap_or_else(|| "Unnamed Hook".to_string()); - if !hook.git_staged.is_empty() { + if !hook.staged.is_empty() { let globs = { let mut builder = GlobSetBuilder::new(); - for glob in hook.git_staged { + for glob in hook.staged { builder.add(Glob::new(&glob)?); } diff --git a/hooked-config/source/config/pre_commit.rs b/hooked-config/source/config/pre_commit.rs index 31adae8..01b0faf 100644 --- a/hooked-config/source/config/pre_commit.rs +++ b/hooked-config/source/config/pre_commit.rs @@ -8,10 +8,6 @@ use crate::{ExitAction, Task}; #[derive(Debug, Deserialize, Serialize)] #[serde(deny_unknown_fields)] pub struct PreCommit { - /// List of globs to check against staged files. - #[serde(default)] - pub git_staged: Vec, - /// Display name for this hook. pub name: Option, @@ -19,6 +15,10 @@ pub struct PreCommit { #[serde(default)] pub on_failure: ExitAction, + /// List of globs to check against staged files. + #[serde(default)] + pub staged: Vec, + /// Task to perform when this hook is called. #[serde(flatten)] pub task: Task, diff --git a/hooked-config/tests/parsing/with-hooks.toml b/hooked-config/tests/parsing/with-hooks.toml index 96abfbc..9afc804 100644 --- a/hooked-config/tests/parsing/with-hooks.toml +++ b/hooked-config/tests/parsing/with-hooks.toml @@ -5,7 +5,7 @@ template = "test.sh" [[pre_commit]] name = "Pre Commit 1" command = "exit 0" -git_staged = ["*.txt"] +staged = ["*.txt"] on_failure = "continue" [[pre_commit]] diff --git a/hooked-config/tests/serialize.rs b/hooked-config/tests/serialize.rs index 448f45b..77ae6cd 100644 --- a/hooked-config/tests/serialize.rs +++ b/hooked-config/tests/serialize.rs @@ -8,9 +8,9 @@ use insta::assert_snapshot; #[test] fn test_serialize() { let pre_commit_command = PreCommit { - git_staged: vec!["*.txt".to_string()], name: Some("Command Test".to_string()), on_failure: ExitAction::Continue, + staged: vec!["*.txt".to_string()], task: Task { command: Some("exit 0".to_string()), script: None, @@ -18,9 +18,9 @@ fn test_serialize() { }; let pre_commit_script = PreCommit { - git_staged: vec![], name: Some("Script Test".to_string()), on_failure: ExitAction::Stop, + staged: vec![], task: Task { command: None, script: Some("test.sh".into()), diff --git a/hooked-config/tests/snapshots/parsing__defaults.snap b/hooked-config/tests/snapshots/parsing__defaults.snap index c7e7d38..e08526c 100644 --- a/hooked-config/tests/snapshots/parsing__defaults.snap +++ b/hooked-config/tests/snapshots/parsing__defaults.snap @@ -10,9 +10,9 @@ Config { }, pre_commit: [ PreCommit { - git_staged: [], name: None, on_failure: Stop, + staged: [], task: Task { command: None, script: None, diff --git a/hooked-config/tests/snapshots/parsing__with-hooks.snap b/hooked-config/tests/snapshots/parsing__with-hooks.snap index 9e528e1..990759b 100644 --- a/hooked-config/tests/snapshots/parsing__with-hooks.snap +++ b/hooked-config/tests/snapshots/parsing__with-hooks.snap @@ -12,13 +12,13 @@ Config { }, pre_commit: [ PreCommit { - git_staged: [ - "*.txt", - ], name: Some( "Pre Commit 1", ), on_failure: Continue, + staged: [ + "*.txt", + ], task: Task { command: Some( "exit 0", @@ -27,11 +27,11 @@ Config { }, }, PreCommit { - git_staged: [], name: Some( "Pre Commit 2", ), on_failure: Stop, + staged: [], task: Task { command: None, script: Some( diff --git a/hooked-config/tests/snapshots/serialize__serialize.snap b/hooked-config/tests/snapshots/serialize__serialize.snap index 402b3dc..a6fafd1 100644 --- a/hooked-config/tests/snapshots/serialize__serialize.snap +++ b/hooked-config/tests/snapshots/serialize__serialize.snap @@ -7,14 +7,14 @@ config = 'Hooked.toml' directory = 'hooks' [[pre_commit]] -git_staged = ['*.txt'] name = 'Command Test' on_failure = 'continue' +staged = ['*.txt'] command = 'exit 0' [[pre_commit]] -git_staged = [] name = 'Script Test' on_failure = 'stop' +staged = [] script = 'test.sh'