From a03c1706d1841457997d9f53811d68d792f0bec2 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Fri, 21 Oct 2022 00:07:44 +0200 Subject: [PATCH] Add git rm cached --- crates/gitignore/src/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/gitignore/src/main.rs b/crates/gitignore/src/main.rs index 9289cc2..46e8363 100644 --- a/crates/gitignore/src/main.rs +++ b/crates/gitignore/src/main.rs @@ -117,7 +117,22 @@ fn add_gitignore_pattern(term: console::Term, pattern: &String) -> eyre::Result< } } - // TODO: Run git rm -r --cached on the .git root + // TODO: Run git rm -r --cached --pathspec on the .git root + let output = std::process::Command::new("git") + .arg("-r") + .arg("--cached") + .arg(pattern) + .output() + .context("could not process git remove from index command")?; + String::from_utf8(output.stdout)? + .lines() + .chain(String::from_utf8(output.stderr)?.lines()) + .try_for_each(|l| term.write_line(l)) + .context("could not print all output to terminal")?; + + if !output.status.success() { + return Err(eyre::anyhow!("failed to run git index command")); + } Ok(()) }