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

src/commit.rs: add a commit functionality

parent 46a8b417
Branches
No related tags found
No related merge requests found
use crate::init;
use std::process::{exit, Command};
/// Get the current commit name of a git repository
///
/// # Return:
/// * A string corresponding to the current commit id
pub fn get_current_commit() -> String {
let output = Command::new("git")
.arg("rev-parse")
.arg("--verify")
.arg("HEAD")
.output()
.unwrap();
match output.status.code().unwrap() {
0 => (),
num => {
eprintln!("{}", String::from_utf8(output.stderr).unwrap());
exit(num);
}
}
let mut commit = String::from_utf8(output.stdout).unwrap();
commit.pop();
commit
}
/// 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 commit = get_current_commit();
let output = Command::new("borg")
.arg("create")
.arg("--stats")
.arg("--progress")
.arg("--compression")
.arg(compression)
.arg(format!("{}::{}", borg_folder.to_str().unwrap(), commit))
.arg(results_folder.to_str().unwrap())
.output()
.unwrap();
match output.status.code().unwrap() {
0 => (),
num => {
eprintln!("{}", String::from_utf8(output.stderr).unwrap());
exit(num);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment