Move error output to Runtime::repository() getter

This commit is contained in:
Matthias Beyer 2016-09-07 21:54:20 +02:00
parent f86b450cfa
commit b50aacbf55
4 changed files with 13 additions and 18 deletions

View file

@ -92,7 +92,7 @@ impl StoreIdAccessor for CreateHook {
use vcs::git::action::StoreAction; use vcs::git::action::StoreAction;
use vcs::git::config::commit_message; use vcs::git::config::commit_message;
use vcs::git::error::MapIntoHookError; use vcs::git::error::MapIntoHookError;
use vcs::git::util::{fetch_repo, fetch_index}; use vcs::git::util::fetch_index;
debug!("[GIT CREATE HOOK]: {:?}", id); debug!("[GIT CREATE HOOK]: {:?}", id);
@ -109,7 +109,7 @@ impl StoreIdAccessor for CreateHook {
let action = StoreAction::Create; let action = StoreAction::Create;
let cfg = try!(self.runtime.config_value_or_err(&action)); let cfg = try!(self.runtime.config_value_or_err(&action));
let repo = try!(fetch_repo(&self.runtime, &action)); let repo = try!(self.runtime.repository(&action));
let mut index = try!(fetch_index(repo, &action)); let mut index = try!(fetch_index(repo, &action));
let file_status = try!( let file_status = try!(

View file

@ -10,6 +10,7 @@ use libimagstore::hook::error::HookErrorKind as HEK;
use libimagstore::hook::result::HookResult; use libimagstore::hook::result::HookResult;
use libimagutil::debug_result::*; use libimagutil::debug_result::*;
use vcs::git::action::StoreAction;
use vcs::git::result::Result; use vcs::git::result::Result;
use vcs::git::error::{MapErrInto, GitHookErrorKind as GHEK}; use vcs::git::error::{MapErrInto, GitHookErrorKind as GHEK};
@ -60,12 +61,17 @@ impl Runtime {
}) })
} }
pub fn repository(&self) -> HookResult<&Repository> { pub fn repository(&self, action: &StoreAction) -> HookResult<&Repository> {
use vcs::git::error::MapIntoHookError;
debug!("[GIT {} HOOK]: Getting repository", action.uppercase());
self.repository self.repository
.as_ref() .as_ref()
.ok_or(GHEK::MkRepo.into_error()) .ok_or(GHEK::MkRepo.into_error())
.map_err(Box::new) .map_err_into(GHEK::RepositoryError)
.map_err(|e| HEK::HookExecutionError.into_error_with_cause(e)) .map_into_hook_error()
.map_dbg_err(|_| format!("[GIT {} HOOK]: Couldn't fetch Repository", action.uppercase()))
.map_dbg(|_| format!("[GIT {} HOOK]: Repository object fetched", action.uppercase()))
} }
pub fn ensure_cfg_branch_is_checked_out(&self) -> HookResult<()> { pub fn ensure_cfg_branch_is_checked_out(&self) -> HookResult<()> {

View file

@ -87,13 +87,13 @@ impl StoreIdAccessor for UpdateHook {
use vcs::git::action::StoreAction; use vcs::git::action::StoreAction;
use vcs::git::config::commit_message; use vcs::git::config::commit_message;
use vcs::git::error::MapIntoHookError; use vcs::git::error::MapIntoHookError;
use vcs::git::util::{fetch_repo, fetch_index}; use vcs::git::util::fetch_index;
debug!("[GIT UPDATE HOOK]: {:?}", id); debug!("[GIT UPDATE HOOK]: {:?}", id);
let action = StoreAction::Update; let action = StoreAction::Update;
let cfg = try!(self.runtime.config_value_or_err(&action)); let cfg = try!(self.runtime.config_value_or_err(&action));
let repo = try!(fetch_repo(&self.runtime, &action)); let repo = try!(self.runtime.repository(&action));
let mut index = try!(fetch_index(repo, &action)); let mut index = try!(fetch_index(repo, &action));
let tree_id = try!( let tree_id = try!(

View file

@ -13,17 +13,6 @@ use vcs::git::error::MapIntoHookError;
use libimagutil::debug_result::*; use libimagutil::debug_result::*;
use libimagstore::hook::error::HookError; use libimagstore::hook::error::HookError;
pub fn fetch_repo<'a>(runtime: &'a GRuntime, action: &StoreAction) -> Result<&'a Repository, HookError>
{
debug!("[GIT {} HOOK]: Getting repository", action.uppercase());
runtime
.repository()
.map_dbg_err(|_| format!("[GIT {} HOOK]: Couldn't fetch Repository", action.uppercase()))
.map_dbg(|_| format!("[GIT {} HOOK]: Repository object fetched", action.uppercase()))
.map_err_into(GHEK::RepositoryError)
.map_into_hook_error()
}
pub fn fetch_index(repo: &Repository, action: &StoreAction) -> Result<Index, HookError> { pub fn fetch_index(repo: &Repository, action: &StoreAction) -> Result<Index, HookError> {
debug!("[GIT {} HOOK]: Getting Index", action.uppercase()); debug!("[GIT {} HOOK]: Getting Index", action.uppercase());
repo.index() repo.index()