From cbce28a348ebb5db646cfc5cd3305c6bce80e915 Mon Sep 17 00:00:00 2001 From: DJMcNab <36049421+DJMcNab@users.noreply.github.com> Date: Sun, 9 Dec 2018 12:27:13 +0000 Subject: Reimplement format-hook using a rust binary --- crates/tools/src/bin/pre-commit.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 crates/tools/src/bin/pre-commit.rs (limited to 'crates/tools/src/bin/pre-commit.rs') 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 @@ +use std::{ + process::{Command}, +}; + +use tools::{Result, run_rustfmt, run, project_root}; +use failure::bail; + +fn main() -> tools::Result<()> { + run_rustfmt(tools::Overwrite)?; + update_staged() +} + +fn update_staged() -> Result<()> { + let root = project_root(); + let output = Command::new("git") + .arg("diff") + .arg("--name-only") + .arg("--cached") + .current_dir(&root) + .output()?; + if !output.status.success() { + bail!( + "`git diff --name-only --cached` exited with {}", + output.status + ); + } + for line in String::from_utf8(output.stdout)?.lines() { + run( + &format!( + "git update-index --add {}", + root.join(line).to_string_lossy() + ), + ".", + )?; + } + Ok(()) +} -- cgit v1.2.3