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

src/checkout.rs: fix checkout problem

parent 455ada31
No related branches found
No related tags found
No related merge requests found
use crate::commit; use crate::commit;
use std::env;
use std::{ use std::{
path::PathBuf, path::PathBuf,
process::{exit, Command, Stdio}, process::{exit, Command, Stdio},
...@@ -139,7 +140,6 @@ pub fn remove_results(borg_path: &PathBuf, results: &PathBuf) { ...@@ -139,7 +140,6 @@ pub fn remove_results(borg_path: &PathBuf, results: &PathBuf) {
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()) 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());
match output.status.code().unwrap() { match output.status.code().unwrap() {
0 => (), 0 => (),
123 => (), 123 => (),
...@@ -154,7 +154,6 @@ pub fn remove_results(borg_path: &PathBuf, results: &PathBuf) { ...@@ -154,7 +154,6 @@ pub fn remove_results(borg_path: &PathBuf, results: &PathBuf) {
/// Function that perform a checkout on your results /// Function that perform a checkout on your results
pub fn checkout(mode: &str) { pub fn checkout(mode: &str) {
let (borg_path, results) = commit::check_path(); let (borg_path, results) = commit::check_path();
let (has_ignore, borgignore) = commit::check_if_borgignore_exists(&borg_path);
if mode == "hard" { if mode == "hard" {
remove_results(&borg_path, &results) remove_results(&borg_path, &results)
} }
...@@ -165,6 +164,9 @@ pub fn checkout(mode: &str) { ...@@ -165,6 +164,9 @@ pub fn checkout(mode: &str) {
.parent() .parent()
.unwrap() .unwrap()
.to_owned(); .to_owned();
env::set_current_dir(&project_dir).unwrap();
let (borg_path, _) = commit::check_path();
let (has_ignore, borgignore) = commit::check_if_borgignore_exists(&borg_path);
let temp = Command::new("pwd").output().unwrap(); let temp = Command::new("pwd").output().unwrap();
match temp.status.code().unwrap() { match temp.status.code().unwrap() {
0 => (), 0 => (),
...@@ -173,14 +175,6 @@ pub fn checkout(mode: &str) { ...@@ -173,14 +175,6 @@ pub fn checkout(mode: &str) {
exit(23); exit(23);
} }
}; };
let mut current_dir = String::from_utf8(temp.stdout.clone()).unwrap();
if current_dir.ends_with("\n") {
current_dir.pop();
}
if current_dir != project_dir.to_str().unwrap() {
eprintln!("Extraction can only happen if you are at the root of your project folder");
exit(47);
}
let progress_part = match has_ignore { let progress_part = match has_ignore {
false => String::from("--progress"), false => String::from("--progress"),
true => format!("--progress --exclude-from {}", borgignore.to_str().unwrap()), true => format!("--progress --exclude-from {}", borgignore.to_str().unwrap()),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment