diff options
author | Aleksey Kladov <[email protected]> | 2019-06-10 23:47:37 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-06-10 23:47:37 +0100 |
commit | 10d34532e3e96ffd92c11e667deb453188c28282 (patch) | |
tree | 095ad479dde329bdbff034af1f3ec587f473b1db /crates/ra_tools/src/bin | |
parent | 75e6c03883c4533b1134c806d166b72200b4837d (diff) |
rename tools -> ra_tools
This should help with caching on CI I hope (see .travis.yml
before_cache)
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 | } | ||