Compare commits
2 Commits
651699c40a
...
4a4974fa35
Author | SHA1 | Date |
---|---|---|
Bauke | 4a4974fa35 | |
Bauke | e4ed623e64 |
|
@ -29,6 +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. |
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[[pre_commit]]
|
[[pre_commit]]
|
||||||
|
@ -39,6 +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"]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Footnotes
|
## Footnotes
|
||||||
|
@ -46,5 +48,6 @@ on_failure = "continue"
|
||||||
[^command-and-script]: When both a command and script are defined in a hook, *only* the command will be run.
|
[^command-and-script]: When both a command and script are defined in a hook, *only* the command will be run.
|
||||||
|
|
||||||
[cli-install]: ../cli/install.md
|
[cli-install]: ../cli/install.md
|
||||||
|
[globset-docs]: https://docs.rs/globset/0.4.9/globset/#syntax
|
||||||
[toml-table]: https://toml.io/en/v1.0.0#table
|
[toml-table]: https://toml.io/en/v1.0.0#table
|
||||||
[toml-arrays-of-tables]: https://toml.io/en/v1.0.0#array-of-tables
|
[toml-arrays-of-tables]: https://toml.io/en/v1.0.0#array-of-tables
|
||||||
|
|
|
@ -53,8 +53,7 @@ pub fn hooked_run(config: Config, hook_type: String) -> Result<()> {
|
||||||
.args(&["diff", "--name-only", "--cached"])
|
.args(&["diff", "--name-only", "--cached"])
|
||||||
.capture()?
|
.capture()?
|
||||||
.stdout_str();
|
.stdout_str();
|
||||||
for line in staged_files.lines() {
|
if !staged_files.lines().any(|line| globs.is_match(line)) {
|
||||||
if globs.is_match(line) {
|
|
||||||
println!(
|
println!(
|
||||||
"\t{} {}",
|
"\t{} {}",
|
||||||
"≫".style(skipped_style),
|
"≫".style(skipped_style),
|
||||||
|
@ -63,7 +62,6 @@ pub fn hooked_run(config: Config, hook_type: String) -> Result<()> {
|
||||||
continue 'hook_loop;
|
continue 'hook_loop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let command = match (hook.task.command, hook.task.script) {
|
let command = match (hook.task.command, hook.task.script) {
|
||||||
(Some(command), _) => Ok(Exec::shell(command)),
|
(Some(command), _) => Ok(Exec::shell(command)),
|
||||||
|
|
Loading…
Reference in New Issue