Reads the current Git revision and dirty state.
(root: &Path)
| 397 | |
| 398 | /// Reads the current Git revision and dirty state. |
| 399 | pub fn git_revision(root: &Path) -> Result<String> { |
| 400 | let output = Command::new("git").args(["rev-parse", "HEAD"]).current_dir(root).output()?; |
| 401 | if !output.status.success() { |
| 402 | bail!("git rev-parse failed"); |
| 403 | } |
| 404 | |
| 405 | let mut sha = String::from_utf8(output.stdout)?.trim().to_owned(); |
| 406 | let dirty = |
| 407 | Command::new("git").args(["status", "--porcelain"]).current_dir(root).output()?; |
| 408 | if !dirty.stdout.is_empty() { |
| 409 | sha.push_str("-dirty"); |
| 410 | } |
| 411 | Ok(sha) |
| 412 | } |
| 413 | |
| 414 | /// Quotes one path for inert reproduction text. |
| 415 | pub fn shell_quote(path: &Path) -> String { |