From f542474af150cff4ae324bd95f3fca41207fdd0d Mon Sep 17 00:00:00 2001 From: Fontrodona Nicolas <nicolas.fontrodona@ens-lyon.fr> Date: Thu, 12 May 2022 10:18:39 +0200 Subject: [PATCH] src/init.rs: creation of init_and_hook function --- src/init.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/init.rs b/src/init.rs index a24a381..cead230 100644 --- a/src/init.rs +++ b/src/init.rs @@ -1,5 +1,6 @@ use std::path::PathBuf; use std::process::{exit, Command}; +use crate::create_hooks; /// Function used to get borg repository folder and results repository only if /// the project is inside a git repository @@ -40,7 +41,7 @@ pub fn get_borg_folder() -> (PathBuf, PathBuf) { } /// Creation of a borg repository in the same directory as the .git repository -pub fn init_repository() { +fn init_repository() { let (borg_path, _) = get_borg_folder(); let output = Command::new("borg") .arg("init") @@ -65,3 +66,16 @@ pub fn init_repository() { } } } + + +/// Creation of a borg repository and creation of hooks if needed inside `.git/hooks` +/// folder +/// # Arguments: +/// * `hooks`: a boolean indicating wether or not to create hooks +/// * `compression`: The compression used automatically after each commit. This parameter is only used if hooks is true. +pub fn init_and_hook(hooks: bool, compression: &str) { + init_repository(); + if hooks { + create_hooks::create_hooks(compression); + } +} \ No newline at end of file -- GitLab