diff --git a/src/commit.rs b/src/commit.rs index 9e2f08d20a3908bbc53b469a9e78440b76ca41da..2ca56a467c6d3d82c57490bf90dbee3e2543a549 100644 --- a/src/commit.rs +++ b/src/commit.rs @@ -1,5 +1,17 @@ use crate::init; -use std::process::{exit, Command}; +use std::{process::{exit, Command}, path::PathBuf}; + + +/// Check if .borg repository and results folder exists +pub fn check_path() -> (PathBuf, PathBuf) { + let (borg_folder, results_folder) = init::get_borg_folder(); + if !borg_folder.is_dir() { + eprintln!("{} folder not found !", borg_folder.to_str().unwrap()); + exit(2) + } + (borg_folder, results_folder) +} + /// Get the current commit name of a git repository /// @@ -26,7 +38,7 @@ pub fn get_current_commit() -> String { /// Create a commit of the results folder named as the current git commit id pub fn commit(compression: String) { - let (borg_folder, results_folder) = init::get_borg_folder(); + let (borg_folder, results_folder) = check_path(); let commit = get_current_commit(); let output = Command::new("borg") .arg("create")