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

src/commit.rs: add a revert option

parent 0862a1bd
Branches
No related tags found
No related merge requests found
use crate::init; use crate::{init, checkout};
use std::{ use std::{
path::PathBuf, path::PathBuf,
process::{exit, Command, Stdio}, process::{exit, Command, Stdio},
...@@ -68,6 +68,35 @@ pub fn check_if_borgignore_exists(borg_folder: &PathBuf) -> (bool, PathBuf) { ...@@ -68,6 +68,35 @@ pub fn check_if_borgignore_exists(borg_folder: &PathBuf) -> (bool, PathBuf) {
(project_folder.is_file(), project_folder) (project_folder.is_file(), project_folder)
} }
/// Function that checks if the archive with the name of the current commit id
/// exits in borg repository
pub fn is_a_commit(borg_path: &PathBuf, commit_id: &str) -> bool{
// Trying to create an archive with the current git commit id
let output = Command::new("borg")
.arg("list")
.arg(format!("{}::{}", borg_path.to_str().unwrap(), commit_id))
.output()
.unwrap();
match output.status.code().unwrap() {
0 => true,
_ => false
}
}
/// Revert the result folder back to the current commit archive
pub fn revert_commit() {
let commit_id = get_current_commit();
let (borg_path, _) = check_path();
if is_a_commit(&borg_path, &commit_id) {
checkout::checkout("hard");
} else {
eprintln!("Cannot revert the content of the results folder previously saved for that commit: No archive found for this commit !");
exit(17);
}
}
/// Create a commit of the results folder named as the current git commit id /// Create a commit of the results folder named as the current git commit id
pub fn commit(compression: String, mut commit_id: String, update: bool) { pub fn commit(compression: String, mut commit_id: String, update: bool) {
let (borg_folder, results_folder) = check_path(); let (borg_folder, results_folder) = check_path();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment