add git::restore_file()
This restores a file from the index to the worktree.
This commit is contained in:
parent
1509c42734
commit
ac72251e0e
1 changed files with 13 additions and 0 deletions
13
src/git.rs
13
src/git.rs
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue