Skip to content
Snippets Groups Projects
Commit a6725148 authored by nfontrod's avatar nfontrod
Browse files

src/checkout.rs: change in checkout to not remove ignored files in hard mode

parent e4d041ab
No related branches found
No related tags found
No related merge requests found
...@@ -118,11 +118,17 @@ pub fn prepare_checkout() { ...@@ -118,11 +118,17 @@ pub fn prepare_checkout() {
pub fn checkout(mode: &str) { pub fn checkout(mode: &str) {
let (borg_path, results) = commit::check_path(); let (borg_path, results) = commit::check_path();
if mode == "hard" { if mode == "hard" {
let cmd = format!("rm -r {}/*", results.to_str().unwrap()); let (has_ignore, borgignore) = commit::check_if_borgignore_exists(&borg_path);
let cmd = if !has_ignore {
format!("rm -r {}/*", results.to_str().unwrap())
} else {
format!("find {} -name '*' -type f | egrep -v -f {} | xargs rm 2>> /dev/null; find results -name '*' -type d | xargs rm -d 2>> /dev/null", results.to_str().unwrap(), borgignore.to_str().unwrap())
};
let output = Command::new("sh").arg("-c").arg(cmd).output().unwrap(); let output = Command::new("sh").arg("-c").arg(cmd).output().unwrap();
println!("{}", String::from_utf8(output.stdout).unwrap()); println!("{}", String::from_utf8(output.stdout).unwrap());
match output.status.code().unwrap() { match output.status.code().unwrap() {
0 => (), 0 => (),
123 => (),
num => { num => {
eprintln!("{}", String::from_utf8(output.stderr).unwrap()); eprintln!("{}", String::from_utf8(output.stderr).unwrap());
exit(num); exit(num);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment