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 (cur_key, value) = line.split_once('=')?;
22 if cur_key == key {
23 Some(value.to_string())
24 } else {
25 None
26 }
27 })
28}
29
30pub fn git(dir: &Path, args: &[&str]) -> Result<(), Box<dyn Error>> {
32 let status = Command::new("git").current_dir(dir).args(args).status()?;
33
34 if !status.success() {
35 return Err(format!("git {:?} failed", args).into());
36 }
37 Ok(())
38}