diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-07-16 17:58:00 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-09-07 22:05:28 +0200 |
commit | c972b5706d65a3a16b8d22fb154b42a1ff908496 (patch) | |
tree | 5d2eb88074b8965690d08713d41e0a0508a180c6 /libimagstorestdhook/src/vcs/git/config.rs | |
parent | c09f0b302f851aa49a3b5d70ddf78ad5c55fa625 (diff) |
Add helper to get the branch which must be checked out before any action takes place
Diffstat (limited to 'libimagstorestdhook/src/vcs/git/config.rs')
-rw-r--r-- | libimagstorestdhook/src/vcs/git/config.rs | 26 |
1 files changed, 26 insertions, 0 deletions
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<Option<String>> { + 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), + } +} + |