aboutsummaryrefslogtreecommitdiff
path: root/crates/tools/src/bin
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2018-12-09 12:44:58 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2018-12-09 12:44:58 +0000
commit3725276554fe63fdd9b63a10b86e794b3eb73158 (patch)
tree01de23f215e51459c67d2eb7f4bfb77d65afd1b7 /crates/tools/src/bin
parentb9c17a6001aaf79e181a86218883fe96d9c95c09 (diff)
parentcbce28a348ebb5db646cfc5cd3305c6bce80e915 (diff)
Merge #271
271: Implement format hook r=matklad a=DJMcNab Tentatively: fixes #155. However, this does add all changes in staged files, which might not be desirable. However, I think we can't solve that without explicit support in rustfmt for it, so it should be fine. Co-authored-by: DJMcNab <[email protected]>
Diffstat (limited to 'crates/tools/src/bin')
-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}