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

Add silent commit function

parent d90615a3
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,34 @@ use std::{
process::{exit, Command},
};
/// Create a commit of the results folder named as the current git commit id
fn silent_commit(compression: String, mut commit_id: String, update: bool) {
let (borg_folder, results_folder) = commit::check_path();
if commit_id == String::from("") {
commit_id = commit::get_current_commit();
}
if update {
commit::delete_commit(&commit_id, &borg_folder);
}
let output = Command::new("borg")
.arg("create")
.arg("--stats")
.arg("--progress")
.arg("--compression")
.arg(compression)
.arg(format!("{}::{}", borg_folder.to_str().unwrap(), commit_id))
.arg(results_folder.to_str().unwrap())
.output()
.unwrap();
match output.status.code().unwrap() {
0 => (),
num => {
eprintln!("{}", String::from_utf8(output.stderr).unwrap());
exit(num);
}
}
}
/// Check if two commits are differents
pub fn is_diff(commit1: &str, commit2: &str, borg_folder: &PathBuf) -> bool {
let archive1 = format!("{}::{}", borg_folder.to_str().unwrap(), commit1);
......@@ -70,7 +98,7 @@ pub fn prepare_checkout() {
check_if_current_commit_exits(&borg_path, &commit_id);
// Create an archive with the content of the current commit
let tmp_name = format!("{}-tmp", commit_id);
commit::commit(String::from("none"), tmp_name.clone(), false);
silent_commit(String::from("none"), tmp_name.clone(), false);
let res = is_diff(&commit_id, &tmp_name, &borg_path);
commit::delete_commit(&tmp_name, &borg_path);
if res {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment