Merge pull request #756 from matthiasbeyer/libimagstorestdhook/git-hook-disable

Libimagstorestdhook/git hook disable
This commit is contained in:
Matthias Beyer 2016-09-20 12:07:43 +02:00 committed by GitHub
commit 896f5e2bc4
4 changed files with 29 additions and 32 deletions

View file

@ -38,37 +38,12 @@ mutable_hooks = false
[store.hooks.stdhook_debug]
aspect = "debug"
[store.hooks.stdhook_git_create]
aspect = "vcs"
# Fail if the repository cannot be opened. If this is set to `false`, the error
# will be printed, but will not abort the store operation. `true` will print the
# error and abort the store action.
abort_on_repo_init_failure = true
# Ensure to be on this branche before doing anything.
ensure_branch = "refs/heads/master"
# Try to checkout the ensure_branch if it isn't checked out
try_checkout_ensure_branch = true
[store.hooks.stdhook_git_retrieve]
aspect = "vcs"
# Fail if the repository cannot be opened. If this is set to `false`, the error
# will be printed, but will not abort the store operation. `true` will print the
# error and abort the store action.
abort_on_repo_init_failure = true
# Ensure to be on this branche before doing anything.
ensure_branch = "refs/heads/master"
# Try to checkout the ensure_branch if it isn't checked out
try_checkout_ensure_branch = true
[store.hooks.stdhook_git_update]
aspect = "vcs"
# set to false to disable
enabled = true
# Fail if the repository cannot be opened. If this is set to `false`, the error
# will be printed, but will not abort the store operation. `true` will print the
# error and abort the store action.
@ -97,6 +72,9 @@ message = "Update"
[store.hooks.stdhook_git_delete]
aspect = "vcs"
# set to false to disable
enabled = true
# Fail if the repository cannot be opened. If this is set to `false`, the error
# will be printed, but will not abort the store operation. `true` will print the
# error and abort the store action.

View file

@ -159,11 +159,20 @@ fn get_bool_cfg(cfg: Option<&Value>, name: &str, on_fail: bool, on_unavail: bool
on_fail
},
None => {
debug!("No key '{}' - Assuming '{}'", name, on_unavail);
warn!("No key '{}' - Assuming '{}'", name, on_unavail);
on_unavail
},
}
})
.unwrap_or(on_unavail)
.unwrap_or_else(|| {
warn!("No configuration to fetch {} from, assuming {}", name, on_unavail);
on_unavail
})
}
/// Check whether the hook is enabled or not. If the config is not there, the hook is _enabled_ by
/// default.
pub fn is_enabled(cfg: &Value) -> bool {
get_bool_cfg(Some(cfg), "enabled", true, true)
}

View file

@ -85,11 +85,17 @@ impl StoreIdAccessor for DeleteHook {
use vcs::git::error::MapIntoHookError;
use vcs::git::util::fetch_index;
use vcs::git::config::abort_on_repo_init_err;
use vcs::git::config::is_enabled;
use git2::{ADD_DEFAULT, STATUS_WT_DELETED, IndexMatchedPath};
debug!("[GIT DELETE HOOK]: {:?}", id);
let action = StoreAction::Delete;
let cfg = try!(self.runtime.config_value_or_err(&action));
if !is_enabled(cfg) {
return Ok(())
}
if !self.runtime.has_repository() {
debug!("[GIT DELETE HOOK]: Runtime has no repository...");
@ -108,7 +114,6 @@ impl StoreIdAccessor for DeleteHook {
}
let _ = try!(self.runtime.ensure_cfg_branch_is_checked_out(&action));
let cfg = try!(self.runtime.config_value_or_err(&action));
let repo = try!(self.runtime.repository(&action));
let mut index = try!(fetch_index(repo, &action));

View file

@ -99,11 +99,17 @@ impl StoreIdAccessor for UpdateHook {
use vcs::git::error::MapIntoHookError;
use vcs::git::util::fetch_index;
use vcs::git::config::abort_on_repo_init_err;
use vcs::git::config::is_enabled;
use git2::{ADD_DEFAULT, STATUS_WT_NEW, STATUS_WT_MODIFIED, IndexMatchedPath};
debug!("[GIT UPDATE HOOK]: {:?}", id);
let action = StoreAction::Update;
let cfg = try!(self.runtime.config_value_or_err(&action));
if !is_enabled(cfg) {
return Ok(());
}
if !self.runtime.has_repository() {
debug!("[GIT UPDATE HOOK]: Runtime has no repository...");
@ -122,7 +128,6 @@ impl StoreIdAccessor for UpdateHook {
}
let _ = try!(self.runtime.ensure_cfg_branch_is_checked_out(&action));
let cfg = try!(self.runtime.config_value_or_err(&action));
let repo = try!(self.runtime.repository(&action));
let mut index = try!(fetch_index(repo, &action));