summaryrefslogtreecommitdiffstats
path: root/libimagstorestdhook/src
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-09-20 15:33:55 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-10-06 18:41:12 +0200
commit5b7ff231a9767972d1018d4e282f514364a1e119 (patch)
treef5a1e31b0ba835eb71d0614b42fbb38b1b954724 /libimagstorestdhook/src
parent1509e074f8005cd5275319a72a03cdfa7de285fc (diff)
Add helper to check whether committing is enabled
Diffstat (limited to 'libimagstorestdhook/src')
-rw-r--r--libimagstorestdhook/src/vcs/git/config.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/libimagstorestdhook/src/vcs/git/config.rs b/libimagstorestdhook/src/vcs/git/config.rs
index c68743d3..ee5871f3 100644
--- a/libimagstorestdhook/src/vcs/git/config.rs
+++ b/libimagstorestdhook/src/vcs/git/config.rs
@@ -195,3 +195,20 @@ pub fn is_enabled(cfg: &Value) -> bool {
get_bool_cfg(Some(cfg), "enabled", true, true)
}
+/// Check whether committing is enabled for a hook.
+pub fn committing_is_enabled(cfg: &Value) -> Result<bool> {
+ match cfg.lookup("commit.enabled") {
+ Some(&Value::Boolean(b)) => Ok(b),
+ Some(_) => {
+ warn!("Config setting whether committing is enabled or not has wrong type.");
+ warn!("Expected Boolean");
+ Err(GHEK::ConfigTypeError.into_error())
+ },
+ None => {
+ warn!("No config setting whether committing is enabled or not.");
+ Err(GHEK::NoConfigError.into_error())
+ },
+ }
+ .map_err_into(GHEK::ConfigError)
+}
+