DeleteHook: Add config-based abort if repo init failed

This commit is contained in:
Matthias Beyer 2016-09-18 18:28:45 +02:00
parent 573745b9f3
commit a321ad941c

View file

@ -79,15 +79,34 @@ impl HookDataAccessorProvider for DeleteHook {
impl StoreIdAccessor for DeleteHook {
fn access(&self, id: &StoreId) -> HookResult<()> {
use libimagerror::into::IntoError;
use vcs::git::action::StoreAction;
use vcs::git::config::commit_message;
use vcs::git::error::MapIntoHookError;
use vcs::git::util::fetch_index;
use vcs::git::config::abort_on_repo_init_err;
use git2::{ADD_DEFAULT, STATUS_WT_DELETED, IndexMatchedPath};
debug!("[GIT DELETE HOOK]: {:?}", id);
let action = StoreAction::Delete;
if !self.runtime.has_repository() {
debug!("[GIT DELETE HOOK]: Runtime has no repository...");
if try!(self.runtime.config_value_or_err(&action).map(|c| abort_on_repo_init_err(c))) {
// Abort on repo init failure
debug!("[GIT DELETE HOOK]: Config says we should abort if we have no repository");
debug!("[GIT DELETE HOOK]: Returing Err(_)");
return Err(GHEK::RepositoryInitError.into_error())
.map_err_into(GHEK::RepositoryError)
.map_into_hook_error()
} else {
debug!("[GIT DELETE HOOK]: Config says it is okay to not have a repository");
debug!("[GIT DELETE HOOK]: Returing Ok(())");
return Ok(())
}
}
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));