add git::restore_file()

This restores a file from the index to the worktree.
This commit is contained in:
Sebastian Kuzminsky 2025-07-09 22:23:02 -06:00
parent 1509c42734
commit ac72251e0e

View file

@ -117,6 +117,19 @@ pub fn worktree_is_dirty(dir: &str) -> Result<bool, GitError> {
return Ok(result.stdout.len() > 0);
}
pub fn restore_file(file: &std::path::Path) -> Result<(), GitError> {
let result = std::process::Command::new("git")
.args(["restore", &file.to_string_lossy()])
.current_dir(file.parent().unwrap())
.output()?;
if !result.status.success() {
println!("stdout: {}", std::str::from_utf8(&result.stdout).unwrap());
println!("stderr: {}", std::str::from_utf8(&result.stderr).unwrap());
return Err(GitError::Oops);
}
return Ok(());
}
pub fn git_commit_file(file: &std::path::Path) -> Result<(), GitError> {
let mut git_dir = std::path::PathBuf::from(file);
git_dir.pop();