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

src/create_hooks.rs: add a delete hooks option and create 2 new aliases

parent ba3eaec3
No related branches found
No related tags found
No related merge requests found
use std::fs;
use std::fs::File; use std::fs::File;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::Write; use std::io::Write;
...@@ -93,18 +94,27 @@ fn update_config_file() { ...@@ -93,18 +94,27 @@ fn update_config_file() {
eprintln!("Error: The file .git/config wasn't found"); eprintln!("Error: The file .git/config wasn't found");
exit(19); exit(19);
} }
let content = fs::read_to_string(&git_config).unwrap();
let alias = format!(
"{}\n\t{}\n\t{}",
"co = checkout -q",
"conh = -c core.hooksPath=/dev/null checkout",
"cnh = -c core.hooksPath=/dev/null commit"
);
if !content.contains(&alias) {
let mut file = OpenOptions::new() let mut file = OpenOptions::new()
.write(true) .write(true)
.append(true) .append(true)
.open(&git_config) .open(&git_config)
.unwrap(); .unwrap();
writeln!(file, "[alias]\n\tco = checkout -q").unwrap(); writeln!(file, "[alias]\n\t{}", alias).unwrap();
}
} }
/// Create 2 files in `.git/hooks` folder /// Create 2 files in `.git/hooks` folder
/// ///
/// 1. Create post-commit hook /// 1. Create post-commit hook
/// 3. Create post-checkout hook /// 2. Create post-checkout hook
/// ///
/// # Arguments /// # Arguments
/// * `compression`: The compression that will automatically be used to save the results folder (no, lz4, zstd, zlib or lzma) after a git commit /// * `compression`: The compression that will automatically be used to save the results folder (no, lz4, zstd, zlib or lzma) after a git commit
...@@ -138,3 +148,25 @@ pub fn create_hooks(compression: &str, mode: &str) { ...@@ -138,3 +148,25 @@ pub fn create_hooks(compression: &str, mode: &str) {
create_file(&git_folder, fname, &content); create_file(&git_folder, fname, &content);
} }
} }
/// Delete 2 hooks files in `.git/hooks` folder
///
/// 1. Create post-commit hook
/// 2. Create post-checkout hook
pub fn delete_hooks() {
let git_folder = get_hooks_folder();
let file_name = vec!["post-commit", "post-checkout"];
for cfile in file_name {
let mut hfile = git_folder.to_owned();
hfile.push(cfile);
let cmd = format!("rm {}", hfile.to_str().unwrap());
let output = Command::new("sh").arg("-c").arg(cmd).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