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() {
|
|
|
|
|
bail!(
|
2018-12-20 16:45:54 +00:00
|
|
|
"`git diff --diff-filter=MAR --name-only --cached` exited with {}",
|
2018-12-09 12:27:13 +00:00
|
|
|
output.status
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
for line in String::from_utf8(output.stdout)?.lines() {
|
|
|
|
|
run(
|
|
|
|
|
&format!(
|
|
|
|
|
"git update-index --add {}",
|
|
|
|
|
root.join(line).to_string_lossy()
|
|
|
|
|
),
|
|
|
|
|
".",
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|