Run a Git command with stdin bytes and return trimmed stdout (for plumbing like `hash-object --stdin`).
(root: &Path, args: &[&str], stdin: &[u8])
| 73 | /// Run a Git command with stdin bytes and return trimmed stdout (for |
| 74 | /// plumbing like `hash-object --stdin`). |
| 75 | fn git_stdin(root: &Path, args: &[&str], stdin: &[u8]) -> String { |
| 76 | use std::io::Write as _; |
| 77 | use std::process::Stdio; |
| 78 | let mut child = Command::new("git") |
| 79 | .args(args) |
| 80 | .current_dir(root) |
| 81 | .env("GIT_CONFIG_NOSYSTEM", "1") |
| 82 | .stdin(Stdio::piped()) |
| 83 | .stdout(Stdio::piped()) |
| 84 | .stderr(Stdio::piped()) |
| 85 | .spawn() |
| 86 | .expect("run git with stdin"); |
| 87 | child |
| 88 | .stdin |
| 89 | .as_mut() |
| 90 | .unwrap() |
| 91 | .write_all(stdin) |
| 92 | .expect("write git stdin"); |
| 93 | let out = child.wait_with_output().expect("wait for git"); |
| 94 | assert!( |
| 95 | out.status.success(), |
| 96 | "git {args:?} failed: {}", |
| 97 | String::from_utf8_lossy(&out.stderr) |
| 98 | ); |
| 99 | String::from_utf8_lossy(&out.stdout).trim().to_string() |
| 100 | } |
| 101 | |
| 102 | fn open_repo(root: &Path) -> atomic_repository::Repository { |
| 103 | atomic_repository::Repository::open(root).unwrap() |
no test coverage detected