From 4436a294e2cd5c1dda195d0ea05c31e351a45cf0 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 16 Jul 2016 17:28:49 +0200 Subject: [PATCH] Add helper to check config whether to abort the hook failing This helper can be used to check the configuration of the hook whether it should abort if the repository cannot be opened. --- libimagstorestdhook/src/vcs/git/config.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libimagstorestdhook/src/vcs/git/config.rs b/libimagstorestdhook/src/vcs/git/config.rs index 839a57d6..726f4ddc 100644 --- a/libimagstorestdhook/src/vcs/git/config.rs +++ b/libimagstorestdhook/src/vcs/git/config.rs @@ -13,3 +13,22 @@ pub fn commit_message(config: &Value, action: StoreAction) -> Option { unimplemented!() } } + +pub fn abort_on_repo_init_err(cfg: Option<&Value>) -> bool { + cfg.map(|cfg| { + match cfg.lookup("abort_on_repo_init_failure") { + Some(&Value::Boolean(b)) => b, + Some(_) => { + warn!("Configuration error, 'abort_on_repo_init_failure' must be a Boolean (true|false)."); + warn!("Assuming 'true' now."); + true + }, + None => { + debug!("No key `abort_on_repo_init_failure' - Assuming 'true'"); + true + }, + } + }) + .unwrap_or(false) +} +