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. |
| 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

View File

@ -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)?);
}

View File

@ -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<String>,
/// Display name for this hook.
pub name: Option<String>,
@ -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<String>,
/// Task to perform when this hook is called.
#[serde(flatten)]
pub task: Task,

View File

@ -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]]

View File

@ -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()),

View File

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

View File

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

View File

@ -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'