From da0e38e3bb4447871bf1cce819e57278c43cd411 Mon Sep 17 00:00:00 2001 From: Bauke Date: Sun, 20 Nov 2022 12:20:59 +0100 Subject: [PATCH] Add git_staged as a config option. --- hooked-config/source/config/pre_commit.rs | 4 ++++ hooked-config/tests/parsing/with-hooks.toml | 1 + hooked-config/tests/serialize.rs | 2 ++ hooked-config/tests/snapshots/parsing__defaults.snap | 1 + hooked-config/tests/snapshots/parsing__with-hooks.snap | 4 ++++ hooked-config/tests/snapshots/serialize__serialize.snap | 2 ++ 6 files changed, 14 insertions(+) diff --git a/hooked-config/source/config/pre_commit.rs b/hooked-config/source/config/pre_commit.rs index 40689a2..31adae8 100644 --- a/hooked-config/source/config/pre_commit.rs +++ b/hooked-config/source/config/pre_commit.rs @@ -8,6 +8,10 @@ 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, diff --git a/hooked-config/tests/parsing/with-hooks.toml b/hooked-config/tests/parsing/with-hooks.toml index d166d7a..96abfbc 100644 --- a/hooked-config/tests/parsing/with-hooks.toml +++ b/hooked-config/tests/parsing/with-hooks.toml @@ -5,6 +5,7 @@ template = "test.sh" [[pre_commit]] name = "Pre Commit 1" command = "exit 0" +git_staged = ["*.txt"] on_failure = "continue" [[pre_commit]] diff --git a/hooked-config/tests/serialize.rs b/hooked-config/tests/serialize.rs index 51a4a38..448f45b 100644 --- a/hooked-config/tests/serialize.rs +++ b/hooked-config/tests/serialize.rs @@ -8,6 +8,7 @@ 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, task: Task { @@ -17,6 +18,7 @@ fn test_serialize() { }; let pre_commit_script = PreCommit { + git_staged: vec![], name: Some("Script Test".to_string()), on_failure: ExitAction::Stop, task: Task { diff --git a/hooked-config/tests/snapshots/parsing__defaults.snap b/hooked-config/tests/snapshots/parsing__defaults.snap index 32fec24..c7e7d38 100644 --- a/hooked-config/tests/snapshots/parsing__defaults.snap +++ b/hooked-config/tests/snapshots/parsing__defaults.snap @@ -10,6 +10,7 @@ Config { }, pre_commit: [ PreCommit { + git_staged: [], name: None, on_failure: Stop, task: Task { diff --git a/hooked-config/tests/snapshots/parsing__with-hooks.snap b/hooked-config/tests/snapshots/parsing__with-hooks.snap index 8150b40..9e528e1 100644 --- a/hooked-config/tests/snapshots/parsing__with-hooks.snap +++ b/hooked-config/tests/snapshots/parsing__with-hooks.snap @@ -12,6 +12,9 @@ Config { }, pre_commit: [ PreCommit { + git_staged: [ + "*.txt", + ], name: Some( "Pre Commit 1", ), @@ -24,6 +27,7 @@ Config { }, }, PreCommit { + git_staged: [], name: Some( "Pre Commit 2", ), diff --git a/hooked-config/tests/snapshots/serialize__serialize.snap b/hooked-config/tests/snapshots/serialize__serialize.snap index 39367c6..402b3dc 100644 --- a/hooked-config/tests/snapshots/serialize__serialize.snap +++ b/hooked-config/tests/snapshots/serialize__serialize.snap @@ -7,11 +7,13 @@ config = 'Hooked.toml' directory = 'hooks' [[pre_commit]] +git_staged = ['*.txt'] name = 'Command Test' on_failure = 'continue' command = 'exit 0' [[pre_commit]] +git_staged = [] name = 'Script Test' on_failure = 'stop' script = 'test.sh'