diff --git a/libimagstorestdhook/src/vcs/git/delete.rs b/libimagstorestdhook/src/vcs/git/delete.rs index 51528067..6f89cba8 100644 --- a/libimagstorestdhook/src/vcs/git/delete.rs +++ b/libimagstorestdhook/src/vcs/git/delete.rs @@ -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; + 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));