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

src/create_hooks.rs: update .git/config to create a new alias if hooks are used

parent 20330ff1
No related branches found
No related tags found
No related merge requests found
......@@ -43,6 +43,7 @@ fn get_hooks_folder() -> PathBuf {
p
}
/// Function used to create a file
///
/// # Arguments:
......@@ -83,6 +84,25 @@ fn create_file(folder: &PathBuf, file_name: &str, content: &str) {
});
}
/// Add a gblkco alias in `.git/config` file at the end to ensure a quiet
/// Checkout and a quiet cancel of this checkout
fn update_config_file() {
let git_hooks = get_hooks_folder();
let mut git_config = git_hooks.parent().unwrap().to_path_buf();
git_config.push("config");
if !git_config.is_file() {
eprintln!("Error: The file .git/config wasn't found");
exit(19);
}
let mut file = OpenOptions::new()
.write(true)
.append(true)
.open(&git_config)
.unwrap();
writeln!(file, "[alias]\n\tgblkco = checkout -q").unwrap();
}
/// Create 2 files in `.git/hooks` folder
///
/// 1. Create post-commit hook
......@@ -92,6 +112,7 @@ fn create_file(folder: &PathBuf, file_name: &str, content: &str) {
/// * `compression`: The compression that will automatically be used to save the results folder (no, lz4, zstd, zlib or lzma) after a git commit
/// * `mode`: `mode`: The checkout mode used by gblk automatically after a git checkout: soft or hard.
pub fn create_hooks(compression: &str, mode: &str) {
update_config_file();
let git_folder = get_hooks_folder();
let post_commit_cmd = format!("gblk commit --compression {}", &compression);
let post_commit_cmd = post_commit_cmd.as_str();
......@@ -100,7 +121,7 @@ pub fn create_hooks(compression: &str, mode: &str) {
original_commit=${{arr[5]}} \n\
target_commit=${{arr[7]}} \n\
\n
git -c core.hooksPath=/dev/null checkout ${{original_commit}} && gblk pre-co && git -c core.hooksPath=/dev/null checkout ${{target_commit}} && gblk co --mode {}
git -c core.hooksPath=/dev/null gblkco ${{original_commit}} && gblk pre-co && git -c core.hooksPath=/dev/null checkout ${{target_commit}} && gblk co --mode {}
", mode);
let post_co_cmd = post_co_cmd.as_str();
let v = vec![post_commit_cmd, post_co_cmd];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment