2019-01-27 02:03:52 +03:00
|
|
|
use std::process::Command;
|
2018-12-09 12:27:13 +00:00
|
|
|
|
|
|
|
|
use failure::bail;
|
|
|
|
|
|
2019-01-27 02:03:52 +03:00
|
|
|
use tools::{Result, run_rustfmt, run, project_root};
|
|
|
|
|
|
2018-12-09 12:27:13 +00:00
|
|
|
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")
|
2018-12-20 16:45:54 +00:00
|
|
|
.arg("--diff-filter=MAR")
|
2018-12-09 12:27:13 +00:00
|
|
|
.arg("--name-only")
|
|
|
|
|
.arg("--cached")
|
|
|
|
|
.current_dir(&root)
|
|
|
|
|
.output()?;
|
|
|
|
|
if !output.status.success() {
|
2019-02-08 14:49:43 +03:00
|
|
|
bail!("`git diff --diff-filter=MAR --name-only --cached` exited with {}", output.status);
|
2018-12-09 12:27:13 +00:00
|
|
|
}
|
|
|
|
|
for line in String::from_utf8(output.stdout)?.lines() {
|
2019-02-08 14:49:43 +03:00
|
|
|
run(&format!("git update-index --add {}", root.join(line).to_string_lossy()), ".")?;
|
2018-12-09 12:27:13 +00:00
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|