| 59 | } |
| 60 | |
| 61 | pub fn pre_commit_check(pre_commit_command: Option<String>, message: &str) -> Result<()> { |
| 62 | if let Some(command) = pre_commit_command { |
| 63 | println!("Running pre-commit command..."); |
| 64 | let mut process = Command::new(command) |
| 65 | .env("MSG", message) |
| 66 | .stdout(Stdio::piped()) |
| 67 | .stderr(Stdio::piped()) |
| 68 | .spawn()?; |
| 69 | let stdout = process.stdout.take().expect("Unable to get stdout"); |
| 70 | let stderr = process.stderr.take().expect("Unable to get stderr"); |
| 71 | thread::spawn(move || { |
| 72 | let lines = BufReader::new(stdout).lines(); |
| 73 | for line in lines { |
| 74 | println!("{}", line.expect("Unable to get line")); |
| 75 | } |
| 76 | }); |
| 77 | thread::spawn(move || { |
| 78 | let lines = BufReader::new(stderr).lines(); |
| 79 | for line in lines { |
| 80 | eprintln!("{}", line.expect("Unable to get line")); |
| 81 | } |
| 82 | }); |
| 83 | let status = process.wait()?; |
| 84 | if !status.success() { |
| 85 | return Err(anyhow!("Pre-commit command failed with {}", status)); |
| 86 | } |
| 87 | } |
| 88 | Ok(()) |
| 89 | } |
| 90 | |
| 91 | pub fn git_add_all_modified() -> Result<()> { |
| 92 | let output = git_exec(&["add", "-u"])?; |