diff options
Diffstat (limited to 'crates/ra_tools/src/bin')
-rw-r--r-- | crates/ra_tools/src/bin/pre-commit.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/crates/ra_tools/src/bin/pre-commit.rs b/crates/ra_tools/src/bin/pre-commit.rs new file mode 100644 index 000000000..c514e992b --- /dev/null +++ b/crates/ra_tools/src/bin/pre-commit.rs | |||
@@ -0,0 +1,28 @@ | |||
1 | use std::process::Command; | ||
2 | |||
3 | use failure::bail; | ||
4 | |||
5 | use ra_tools::{Result, run_rustfmt, run, project_root, Overwrite}; | ||
6 | |||
7 | fn main() -> Result<()> { | ||
8 | run_rustfmt(Overwrite)?; | ||
9 | update_staged() | ||
10 | } | ||
11 | |||
12 | fn update_staged() -> Result<()> { | ||
13 | let root = project_root(); | ||
14 | let output = Command::new("git") | ||
15 | .arg("diff") | ||
16 | .arg("--diff-filter=MAR") | ||
17 | .arg("--name-only") | ||
18 | .arg("--cached") | ||
19 | .current_dir(&root) | ||
20 | .output()?; | ||
21 | if !output.status.success() { | ||
22 | bail!("`git diff --diff-filter=MAR --name-only --cached` exited with {}", output.status); | ||
23 | } | ||
24 | for line in String::from_utf8(output.stdout)?.lines() { | ||
25 | run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?; | ||
26 | } | ||
27 | Ok(()) | ||
28 | } | ||