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