diff --git a/libimagstorestdhook/src/vcs/git/config.rs b/libimagstorestdhook/src/vcs/git/config.rs index 726f4ddc..995eb0a6 100644 --- a/libimagstorestdhook/src/vcs/git/config.rs +++ b/libimagstorestdhook/src/vcs/git/config.rs @@ -1,5 +1,11 @@ use toml::Value; +use libimagerror::into::IntoError; + +use vcs::git::error::GitHookErrorKind as GHEK; +use vcs::git::error::MapErrInto; +use vcs::git::result::Result; + use vcs::git::action::StoreAction; pub fn commit_interactive(config: &Value) -> bool { @@ -32,3 +38,23 @@ pub fn abort_on_repo_init_err(cfg: Option<&Value>) -> bool { .unwrap_or(false) } +pub fn ensure_branch(cfg: Option<&Value>) -> Result> { + match cfg { + Some(cfg) => { + match cfg.lookup("ensure_branch") { + Some(&Value::String(ref s)) => Ok(Some(s.clone())), + Some(_) => { + warn!("Configuration error, 'ensure_branch' must be a String."); + Err(GHEK::ConfigTypeError.into_error()) + .map_err_into(GHEK::ConfigTypeError) + }, + None => { + debug!("No key `ensure_branch'"); + Ok(None) + }, + } + }, + None => Ok(None), + } +} +