simplify reset_workdir (#6)

This commit is contained in:
Stephan Dilly 2020-03-30 19:25:52 +02:00 committed by GitHub
parent 7bfa374ddf
commit 73e9029df4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -45,28 +45,14 @@ pub fn reset_workdir(repo_path: &str, path: &Path) -> bool {
return removed_file_wd;
}
if status != Status::WT_MODIFIED | Status::INDEX_NEW {
let mut checkout_opts = CheckoutBuilder::new();
checkout_opts
.remove_untracked(true)
.force()
.update_index(false)
.path(&path);
//first reset working dir file
repo.checkout_head(Some(&mut checkout_opts)).unwrap();
}
let mut checkout_opts = CheckoutBuilder::new();
checkout_opts
.update_index(true) // windows: needs this to be true WTF?!
.allow_conflicts(true)
.force()
.path(&path);
// now reset staged changes back to working dir
repo.checkout_index(None, Some(&mut checkout_opts)).unwrap();
true
repo.checkout_index(None, Some(&mut checkout_opts)).is_ok()
} else {
false
}