1use std::{error::Error, path::Path, process::Command};
8
9pub fn get_config(key: &str) -> Option<String> {
10 let handle = Command::new("git")
11 .arg("config")
12 .arg("list")
13 .output()
14 .ok()?;
15
16 let conf_out = String::from_utf8(handle.stdout).ok()?;
17
18 conf_out.split("\n").find_map(|line| {
19 let mut parts = line.splitn(2, '=');
21 let cur_key = parts.next()?;
23 let value = parts.next()?;
24 if cur_key == key {
25 Some(value.to_string())
26 } else {
27 None
28 }
29 })
30}
31
32pub fn git(dir: &Path, args: &[&str]) -> Result<(), Box<dyn Error>> {
34 let status = Command::new("git").current_dir(dir).args(args).status()?;
35
36 if !status.success() {
37 return Err(format!("git {:?} failed", args).into());
38 }
39 Ok(())
40}