|
| 1 | +pub(super) mod function { |
| 2 | + use anyhow::{bail, Context}; |
| 3 | + use gix::bstr::ByteSlice; |
| 4 | + use std::ffi::OsString; |
| 5 | + use std::io::{BufRead, BufReader}; |
| 6 | + use std::process::{Command, Stdio}; |
| 7 | + |
| 8 | + pub fn check_mode() -> anyhow::Result<()> { |
| 9 | + let root = find_root()?; |
| 10 | + let mut mismatch = false; |
| 11 | + |
| 12 | + let cmd = Command::new("git") |
| 13 | + .arg("-C") |
| 14 | + .arg(root) |
| 15 | + .args(["ls-files", "-sz", "--", "*.sh"]) |
| 16 | + .stdout(Stdio::piped()) |
| 17 | + .spawn() |
| 18 | + .context("Can't run `git` to list index")?; |
| 19 | + |
| 20 | + let stdout = cmd.stdout.expect("should have captured stdout"); |
| 21 | + let reader = BufReader::new(stdout); |
| 22 | + for record in reader.split(b'\0') { |
| 23 | + // FIXME: Use the record, displaying messages and updating `mismatch`. |
| 24 | + } |
| 25 | + |
| 26 | + // FIXME: If `cmd` did not report successful completion, bail. |
| 27 | + // FIXME: If `mismatch` (any mismatches), bail. |
| 28 | + bail!("not yet implemented"); |
| 29 | + } |
| 30 | + |
| 31 | + fn find_root() -> anyhow::Result<OsString> { |
| 32 | + let output = Command::new("git") |
| 33 | + .args(["rev-parse", "--show-toplevel"]) |
| 34 | + .output() |
| 35 | + .context("Can't run `git` to find worktree root")?; |
| 36 | + |
| 37 | + if !output.status.success() { |
| 38 | + bail!("`git` failed to find worktree root"); |
| 39 | + } |
| 40 | + |
| 41 | + let root = output |
| 42 | + .stdout |
| 43 | + .strip_suffix(b"\n") |
| 44 | + .context("Can't parse worktree root")? |
| 45 | + .to_os_str()? |
| 46 | + .to_owned(); |
| 47 | + |
| 48 | + Ok(root) |
| 49 | + } |
| 50 | +} |
0 commit comments