Rename git_staged to staged.

This commit is contained in:
Bauke 2022-11-27 17:29:44 +01:00
parent 4a4974fa35
commit 5d26a72c8b
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
8 changed files with 18 additions and 18 deletions

View File

@ -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. | | 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. | | 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". | | 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 ```toml
[[pre_commit]] [[pre_commit]]
@ -40,7 +40,7 @@ command = "echo \"Hey, $USER!\""
name = "Script Example" name = "Script Example"
script = "example.sh" script = "example.sh"
on_failure = "continue" on_failure = "continue"
git_staged = ["*.txt"] staged = ["*.txt"]
``` ```
## Footnotes ## Footnotes

View File

@ -39,10 +39,10 @@ pub fn hooked_run(config: Config, hook_type: String) -> Result<()> {
'hook_loop: for hook in config.pre_commit { 'hook_loop: for hook in config.pre_commit {
let hook_name = hook.name.unwrap_or_else(|| "Unnamed Hook".to_string()); 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 globs = {
let mut builder = GlobSetBuilder::new(); let mut builder = GlobSetBuilder::new();
for glob in hook.git_staged { for glob in hook.staged {
builder.add(Glob::new(&glob)?); builder.add(Glob::new(&glob)?);
} }

View File

@ -8,10 +8,6 @@ use crate::{ExitAction, Task};
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)] #[serde(deny_unknown_fields)]
pub struct PreCommit { pub struct PreCommit {
/// List of globs to check against staged files.
#[serde(default)]
pub git_staged: Vec<String>,
/// Display name for this hook. /// Display name for this hook.
pub name: Option<String>, pub name: Option<String>,
@ -19,6 +15,10 @@ pub struct PreCommit {
#[serde(default)] #[serde(default)]
pub on_failure: ExitAction, pub on_failure: ExitAction,
/// List of globs to check against staged files.
#[serde(default)]
pub staged: Vec<String>,
/// Task to perform when this hook is called. /// Task to perform when this hook is called.
#[serde(flatten)] #[serde(flatten)]
pub task: Task, pub task: Task,

View File

@ -5,7 +5,7 @@ template = "test.sh"
[[pre_commit]] [[pre_commit]]
name = "Pre Commit 1" name = "Pre Commit 1"
command = "exit 0" command = "exit 0"
git_staged = ["*.txt"] staged = ["*.txt"]
on_failure = "continue" on_failure = "continue"
[[pre_commit]] [[pre_commit]]

View File

@ -8,9 +8,9 @@ use insta::assert_snapshot;
#[test] #[test]
fn test_serialize() { fn test_serialize() {
let pre_commit_command = PreCommit { let pre_commit_command = PreCommit {
git_staged: vec!["*.txt".to_string()],
name: Some("Command Test".to_string()), name: Some("Command Test".to_string()),
on_failure: ExitAction::Continue, on_failure: ExitAction::Continue,
staged: vec!["*.txt".to_string()],
task: Task { task: Task {
command: Some("exit 0".to_string()), command: Some("exit 0".to_string()),
script: None, script: None,
@ -18,9 +18,9 @@ fn test_serialize() {
}; };
let pre_commit_script = PreCommit { let pre_commit_script = PreCommit {
git_staged: vec![],
name: Some("Script Test".to_string()), name: Some("Script Test".to_string()),
on_failure: ExitAction::Stop, on_failure: ExitAction::Stop,
staged: vec![],
task: Task { task: Task {
command: None, command: None,
script: Some("test.sh".into()), script: Some("test.sh".into()),

View File

@ -10,9 +10,9 @@ Config {
}, },
pre_commit: [ pre_commit: [
PreCommit { PreCommit {
git_staged: [],
name: None, name: None,
on_failure: Stop, on_failure: Stop,
staged: [],
task: Task { task: Task {
command: None, command: None,
script: None, script: None,

View File

@ -12,13 +12,13 @@ Config {
}, },
pre_commit: [ pre_commit: [
PreCommit { PreCommit {
git_staged: [
"*.txt",
],
name: Some( name: Some(
"Pre Commit 1", "Pre Commit 1",
), ),
on_failure: Continue, on_failure: Continue,
staged: [
"*.txt",
],
task: Task { task: Task {
command: Some( command: Some(
"exit 0", "exit 0",
@ -27,11 +27,11 @@ Config {
}, },
}, },
PreCommit { PreCommit {
git_staged: [],
name: Some( name: Some(
"Pre Commit 2", "Pre Commit 2",
), ),
on_failure: Stop, on_failure: Stop,
staged: [],
task: Task { task: Task {
command: None, command: None,
script: Some( script: Some(

View File

@ -7,14 +7,14 @@ config = 'Hooked.toml'
directory = 'hooks' directory = 'hooks'
[[pre_commit]] [[pre_commit]]
git_staged = ['*.txt']
name = 'Command Test' name = 'Command Test'
on_failure = 'continue' on_failure = 'continue'
staged = ['*.txt']
command = 'exit 0' command = 'exit 0'
[[pre_commit]] [[pre_commit]]
git_staged = []
name = 'Script Test' name = 'Script Test'
on_failure = 'stop' on_failure = 'stop'
staged = []
script = 'test.sh' script = 'test.sh'