summaryrefslogtreecommitdiffstats
path: root/libimagstorestdhook/src/vcs/git/config.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-07-16 17:58:00 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-09-07 22:05:28 +0200
commitc972b5706d65a3a16b8d22fb154b42a1ff908496 (patch)
tree5d2eb88074b8965690d08713d41e0a0508a180c6 /libimagstorestdhook/src/vcs/git/config.rs
parentc09f0b302f851aa49a3b5d70ddf78ad5c55fa625 (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.rs26
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),
+ }
+}
+