From 9c2f4db03d3577243f53ca0da9c5bf6d7d856aec Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 7 Sep 2016 21:26:06 +0200 Subject: [PATCH 1/9] Remove unused fn: hasrepo() --- libimagstorestdhook/src/vcs/git/util.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libimagstorestdhook/src/vcs/git/util.rs b/libimagstorestdhook/src/vcs/git/util.rs index e57e6acc..5a6f0b86 100644 --- a/libimagstorestdhook/src/vcs/git/util.rs +++ b/libimagstorestdhook/src/vcs/git/util.rs @@ -22,7 +22,3 @@ pub fn mkrepo(store: &Store) -> Result<()> { .map_err_into(GHEK::MkRepo) } -pub fn hasrepo(store: &Store) -> bool { - Repository::open(store.path()).is_ok() -} - From fddd6ec4cb8b36a163e955baa7214f48f34a9c25 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 7 Sep 2016 21:26:23 +0200 Subject: [PATCH 2/9] Remove unused fn: mkrepo() --- libimagstorestdhook/src/vcs/git/util.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/libimagstorestdhook/src/vcs/git/util.rs b/libimagstorestdhook/src/vcs/git/util.rs index 5a6f0b86..0a022a9a 100644 --- a/libimagstorestdhook/src/vcs/git/util.rs +++ b/libimagstorestdhook/src/vcs/git/util.rs @@ -11,14 +11,3 @@ use vcs::git::error::GitHookErrorKind as GHEK; use vcs::git::error::MapErrInto; use vcs::git::result::Result; -pub fn mkrepo(store: &Store) -> Result<()> { - let mut opts = RepositoryInitOptions::new(); - opts.bare(false); - opts.no_reinit(true); - opts.mkdir(false); - opts.external_template(false); - Repository::init_opts(store.path(), &opts) - .map(|_| ()) - .map_err_into(GHEK::MkRepo) -} - From 741ebff2da3c115e76ab7e732564628152b72de5 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 7 Sep 2016 21:32:11 +0200 Subject: [PATCH 3/9] Outsource repository fetching into helper fn --- libimagstorestdhook/src/vcs/git/create.rs | 13 +++++-------- libimagstorestdhook/src/vcs/git/update.rs | 13 +++++-------- libimagstorestdhook/src/vcs/git/util.rs | 19 +++++++++++++++---- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/libimagstorestdhook/src/vcs/git/create.rs b/libimagstorestdhook/src/vcs/git/create.rs index 54845cdd..d3df670d 100644 --- a/libimagstorestdhook/src/vcs/git/create.rs +++ b/libimagstorestdhook/src/vcs/git/create.rs @@ -92,6 +92,7 @@ impl StoreIdAccessor for CreateHook { use vcs::git::action::StoreAction; use vcs::git::config::commit_message; use vcs::git::error::MapIntoHookError; + use vcs::git::util::fetch_repo; debug!("[GIT CREATE HOOK]: {:?}", id); @@ -112,15 +113,11 @@ impl StoreIdAccessor for CreateHook { try!(self.runtime.ensure_cfg_branch_is_checked_out()); debug!("[GIT CREATE HOOK]: Branch checked out"); - debug!("[GIT CREATE HOOK]: Getting repository"); - let repo = try!( - self.runtime - .repository() - .map_dbg_err_str("[GIT CREATE HOOK]: Couldn't fetch Repository") - .map_err_into(GHEK::RepositoryError) - .map_into_hook_error() + let repo = try!(fetch_repo(&self.runtime, + "[GIT CREATE HOOK]: Getting repository", + "[GIT CREATE HOOK]: Couldn't fetch Repository", + "[GIT CREATE HOOK]: Repository object fetched") ); - debug!("[GIT CREATE HOOK]: Repository object fetched"); let mut index = try!( repo diff --git a/libimagstorestdhook/src/vcs/git/update.rs b/libimagstorestdhook/src/vcs/git/update.rs index b0d2d05e..e423c0de 100644 --- a/libimagstorestdhook/src/vcs/git/update.rs +++ b/libimagstorestdhook/src/vcs/git/update.rs @@ -87,6 +87,7 @@ impl StoreIdAccessor for UpdateHook { use vcs::git::action::StoreAction; use vcs::git::config::commit_message; use vcs::git::error::MapIntoHookError; + use vcs::git::util::fetch_repo; debug!("[GIT UPDATE HOOK]: {:?}", id); @@ -96,15 +97,11 @@ impl StoreIdAccessor for UpdateHook { .map_dbg_err_str("[GIT UPDATE HOOK]: Couldn't get Value object from config") ); - debug!("[GIT UPDATE HOOK]: Getting repository"); - let repo = try!( - self.runtime - .repository() - .map_dbg_err_str("[GIT UPDATE HOOK]: Couldn't fetch Repository") - .map_err_into(GHEK::RepositoryError) - .map_into_hook_error() + let repo = try!(fetch_repo(&self.runtime, + "[GIT UPDATE HOOK]: Getting repository", + "[GIT UPDATE HOOK]: Couldn't fetch Repository", + "[GIT UPDATE HOOK]: Repository object fetched") ); - debug!("[GIT UPDATE HOOK]: Repository object fetched"); let mut index = try!( repo diff --git a/libimagstorestdhook/src/vcs/git/util.rs b/libimagstorestdhook/src/vcs/git/util.rs index 0a022a9a..a87fc6dd 100644 --- a/libimagstorestdhook/src/vcs/git/util.rs +++ b/libimagstorestdhook/src/vcs/git/util.rs @@ -3,11 +3,22 @@ //! Contains primitives to create a repository within the store path use git2::Repository; -use git2::RepositoryInitOptions; - -use libimagstore::store::Store; use vcs::git::error::GitHookErrorKind as GHEK; use vcs::git::error::MapErrInto; -use vcs::git::result::Result; +use vcs::git::runtime::Runtime as GRuntime; +use vcs::git::action::StoreAction; +use vcs::git::error::MapIntoHookError; + +use libimagutil::debug_result::*; +use libimagstore::hook::error::HookError; + +pub fn fetch_repo<'a>(runtime: &'a GRuntime, action: &StoreAction) -> Result<&'a Repository, HookError> +{ + runtime + .repository() + .map_dbg_err_str(on_err_str) + .map_err_into(GHEK::RepositoryError) + .map_into_hook_error() +} From ca477441088b68a84dd8fa6f29a2f72686b78574 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 7 Sep 2016 21:37:08 +0200 Subject: [PATCH 4/9] Add StoreAction::uppercase() utility function For debugging output convenience --- libimagstorestdhook/src/vcs/git/action.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libimagstorestdhook/src/vcs/git/action.rs b/libimagstorestdhook/src/vcs/git/action.rs index 26caf5a0..277260f0 100644 --- a/libimagstorestdhook/src/vcs/git/action.rs +++ b/libimagstorestdhook/src/vcs/git/action.rs @@ -8,6 +8,18 @@ pub enum StoreAction { Delete, } +impl StoreAction { + + pub fn uppercase(&self) -> &str { + match *self { + StoreAction::Create => "CREATE", + StoreAction::Retrieve => "RETRIEVE", + StoreAction::Update => "UPDATE", + StoreAction::Delete => "DELETE", + } + } +} + impl Display for StoreAction { fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> { From 032110e6d83229a8bc82b6e47f13ce91f155fa14 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 7 Sep 2016 21:37:56 +0200 Subject: [PATCH 5/9] Rewrite fetch_repo() so we have less overhead in calling this helper --- libimagstorestdhook/src/vcs/git/create.rs | 8 +++----- libimagstorestdhook/src/vcs/git/update.rs | 8 +++----- libimagstorestdhook/src/vcs/git/util.rs | 4 +++- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/libimagstorestdhook/src/vcs/git/create.rs b/libimagstorestdhook/src/vcs/git/create.rs index d3df670d..079b1b60 100644 --- a/libimagstorestdhook/src/vcs/git/create.rs +++ b/libimagstorestdhook/src/vcs/git/create.rs @@ -113,11 +113,9 @@ impl StoreIdAccessor for CreateHook { try!(self.runtime.ensure_cfg_branch_is_checked_out()); debug!("[GIT CREATE HOOK]: Branch checked out"); - let repo = try!(fetch_repo(&self.runtime, - "[GIT CREATE HOOK]: Getting repository", - "[GIT CREATE HOOK]: Couldn't fetch Repository", - "[GIT CREATE HOOK]: Repository object fetched") - ); + let action = StoreAction::Create; + + let repo = try!(fetch_repo(&self.runtime, &action)); let mut index = try!( repo diff --git a/libimagstorestdhook/src/vcs/git/update.rs b/libimagstorestdhook/src/vcs/git/update.rs index e423c0de..1c91fa78 100644 --- a/libimagstorestdhook/src/vcs/git/update.rs +++ b/libimagstorestdhook/src/vcs/git/update.rs @@ -97,11 +97,9 @@ impl StoreIdAccessor for UpdateHook { .map_dbg_err_str("[GIT UPDATE HOOK]: Couldn't get Value object from config") ); - let repo = try!(fetch_repo(&self.runtime, - "[GIT UPDATE HOOK]: Getting repository", - "[GIT UPDATE HOOK]: Couldn't fetch Repository", - "[GIT UPDATE HOOK]: Repository object fetched") - ); + let action = StoreAction::Update; + + let repo = try!(fetch_repo(&self.runtime, &action)); let mut index = try!( repo diff --git a/libimagstorestdhook/src/vcs/git/util.rs b/libimagstorestdhook/src/vcs/git/util.rs index a87fc6dd..6bdd954d 100644 --- a/libimagstorestdhook/src/vcs/git/util.rs +++ b/libimagstorestdhook/src/vcs/git/util.rs @@ -15,9 +15,11 @@ 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_str(on_err_str) + .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() } From 4e2a980599a506789b3994545fdbe17fcb858ea2 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 7 Sep 2016 21:47:39 +0200 Subject: [PATCH 6/9] Refactor Index fetching into helper function --- libimagstorestdhook/src/vcs/git/create.rs | 15 ++++----------- libimagstorestdhook/src/vcs/git/update.rs | 15 ++++----------- libimagstorestdhook/src/vcs/git/util.rs | 11 ++++++++++- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/libimagstorestdhook/src/vcs/git/create.rs b/libimagstorestdhook/src/vcs/git/create.rs index 079b1b60..737c7402 100644 --- a/libimagstorestdhook/src/vcs/git/create.rs +++ b/libimagstorestdhook/src/vcs/git/create.rs @@ -92,7 +92,7 @@ impl StoreIdAccessor for CreateHook { use vcs::git::action::StoreAction; use vcs::git::config::commit_message; use vcs::git::error::MapIntoHookError; - use vcs::git::util::fetch_repo; + use vcs::git::util::{fetch_repo, fetch_index}; debug!("[GIT CREATE HOOK]: {:?}", id); @@ -113,16 +113,9 @@ impl StoreIdAccessor for CreateHook { try!(self.runtime.ensure_cfg_branch_is_checked_out()); debug!("[GIT CREATE HOOK]: Branch checked out"); - let action = StoreAction::Create; - - let repo = try!(fetch_repo(&self.runtime, &action)); - - let mut index = try!( - repo - .index() - .map_err_into(GHEK::RepositoryIndexFetchingError) - .map_into_hook_error() - ); + let action = StoreAction::Create; + let repo = try!(fetch_repo(&self.runtime, &action)); + let mut index = try!(fetch_index(repo, &action)); let file_status = try!( repo diff --git a/libimagstorestdhook/src/vcs/git/update.rs b/libimagstorestdhook/src/vcs/git/update.rs index 1c91fa78..9bd7f65a 100644 --- a/libimagstorestdhook/src/vcs/git/update.rs +++ b/libimagstorestdhook/src/vcs/git/update.rs @@ -87,7 +87,7 @@ impl StoreIdAccessor for UpdateHook { use vcs::git::action::StoreAction; use vcs::git::config::commit_message; use vcs::git::error::MapIntoHookError; - use vcs::git::util::fetch_repo; + use vcs::git::util::{fetch_repo, fetch_index}; debug!("[GIT UPDATE HOOK]: {:?}", id); @@ -97,16 +97,9 @@ impl StoreIdAccessor for UpdateHook { .map_dbg_err_str("[GIT UPDATE HOOK]: Couldn't get Value object from config") ); - let action = StoreAction::Update; - - let repo = try!(fetch_repo(&self.runtime, &action)); - - let mut index = try!( - repo - .index() - .map_err_into(GHEK::RepositoryIndexFetchingError) - .map_into_hook_error() - ); + let action = StoreAction::Update; + let repo = try!(fetch_repo(&self.runtime, &action)); + let mut index = try!(fetch_index(repo, &action)); let tree_id = try!( index.write_tree() diff --git a/libimagstorestdhook/src/vcs/git/util.rs b/libimagstorestdhook/src/vcs/git/util.rs index 6bdd954d..7e0a9f4d 100644 --- a/libimagstorestdhook/src/vcs/git/util.rs +++ b/libimagstorestdhook/src/vcs/git/util.rs @@ -2,7 +2,7 @@ //! //! Contains primitives to create a repository within the store path -use git2::Repository; +use git2::{Repository, Index}; use vcs::git::error::GitHookErrorKind as GHEK; use vcs::git::error::MapErrInto; @@ -24,3 +24,12 @@ pub fn fetch_repo<'a>(runtime: &'a GRuntime, action: &StoreAction) -> Result<&'a .map_into_hook_error() } +pub fn fetch_index(repo: &Repository, action: &StoreAction) -> Result { + debug!("[GIT {} HOOK]: Getting Index", action.uppercase()); + repo.index() + .map_dbg_err(|_| format!("[GIT {} HOOK]: Couldn't fetch Index", action.uppercase())) + .map_dbg(|_| format!("[GIT {} HOOK]: Index object fetched", action.uppercase())) + .map_err_into(GHEK::RepositoryIndexFetchingError) + .map_into_hook_error() +} + From f86b450cfa6bbc5e11ec575d659f9567f4cd347d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 7 Sep 2016 21:51:34 +0200 Subject: [PATCH 7/9] Simplify error printing if config value fetching failed --- libimagstorestdhook/src/vcs/git/create.rs | 7 +------ libimagstorestdhook/src/vcs/git/runtime.rs | 5 ++++- libimagstorestdhook/src/vcs/git/update.rs | 7 +------ 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/libimagstorestdhook/src/vcs/git/create.rs b/libimagstorestdhook/src/vcs/git/create.rs index 737c7402..9708f0e9 100644 --- a/libimagstorestdhook/src/vcs/git/create.rs +++ b/libimagstorestdhook/src/vcs/git/create.rs @@ -103,17 +103,12 @@ impl StoreIdAccessor for CreateHook { .map_into_hook_error() ); - let cfg = try!( - self.runtime - .config_value_or_err() - .map_dbg_err_str("[GIT CREATE HOOK]: Couldn't get Value object from config") - ); - debug!("[GIT CREATE HOOK]: Ensuring branch checkout"); try!(self.runtime.ensure_cfg_branch_is_checked_out()); debug!("[GIT CREATE HOOK]: Branch checked out"); let action = StoreAction::Create; + let cfg = try!(self.runtime.config_value_or_err(&action)); let repo = try!(fetch_repo(&self.runtime, &action)); let mut index = try!(fetch_index(repo, &action)); diff --git a/libimagstorestdhook/src/vcs/git/runtime.rs b/libimagstorestdhook/src/vcs/git/runtime.rs index 54334f44..dd53de95 100644 --- a/libimagstorestdhook/src/vcs/git/runtime.rs +++ b/libimagstorestdhook/src/vcs/git/runtime.rs @@ -47,7 +47,7 @@ impl Runtime { self.config.is_some() } - pub fn config_value_or_err(&self) -> HookResult<&Value> { + pub fn config_value_or_err(&self, action: &StoreAction) -> HookResult<&Value> { self.config .as_ref() .ok_or(GHEK::NoConfigError.into_error()) @@ -55,6 +55,9 @@ impl Runtime { .map_err(Box::new) .map_err(|e| HEK::HookExecutionError.into_error_with_cause(e)) .map_err(|mut e| e.with_custom_data(CustomData::default().aborting(false))) + .map_dbg_err(|_| { + format!("[GIT {} HOOK]: Couldn't get Value object from config", action.uppercase()) + }) } pub fn repository(&self) -> HookResult<&Repository> { diff --git a/libimagstorestdhook/src/vcs/git/update.rs b/libimagstorestdhook/src/vcs/git/update.rs index 9bd7f65a..9d5d18eb 100644 --- a/libimagstorestdhook/src/vcs/git/update.rs +++ b/libimagstorestdhook/src/vcs/git/update.rs @@ -91,13 +91,8 @@ impl StoreIdAccessor for UpdateHook { debug!("[GIT UPDATE HOOK]: {:?}", id); - let cfg = try!( - self.runtime - .config_value_or_err() - .map_dbg_err_str("[GIT UPDATE HOOK]: Couldn't get Value object from config") - ); - let action = StoreAction::Update; + let cfg = try!(self.runtime.config_value_or_err(&action)); let repo = try!(fetch_repo(&self.runtime, &action)); let mut index = try!(fetch_index(repo, &action)); From b50aacbf55ec13653320fd1bcc1aa12303c3f93f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 7 Sep 2016 21:54:20 +0200 Subject: [PATCH 8/9] Move error output to Runtime::repository() getter --- libimagstorestdhook/src/vcs/git/create.rs | 4 ++-- libimagstorestdhook/src/vcs/git/runtime.rs | 12 +++++++++--- libimagstorestdhook/src/vcs/git/update.rs | 4 ++-- libimagstorestdhook/src/vcs/git/util.rs | 11 ----------- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/libimagstorestdhook/src/vcs/git/create.rs b/libimagstorestdhook/src/vcs/git/create.rs index 9708f0e9..c8ada38a 100644 --- a/libimagstorestdhook/src/vcs/git/create.rs +++ b/libimagstorestdhook/src/vcs/git/create.rs @@ -92,7 +92,7 @@ impl StoreIdAccessor for CreateHook { use vcs::git::action::StoreAction; use vcs::git::config::commit_message; use vcs::git::error::MapIntoHookError; - use vcs::git::util::{fetch_repo, fetch_index}; + use vcs::git::util::fetch_index; debug!("[GIT CREATE HOOK]: {:?}", id); @@ -109,7 +109,7 @@ impl StoreIdAccessor for CreateHook { let action = StoreAction::Create; 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 file_status = try!( diff --git a/libimagstorestdhook/src/vcs/git/runtime.rs b/libimagstorestdhook/src/vcs/git/runtime.rs index dd53de95..74ed8fb3 100644 --- a/libimagstorestdhook/src/vcs/git/runtime.rs +++ b/libimagstorestdhook/src/vcs/git/runtime.rs @@ -10,6 +10,7 @@ use libimagstore::hook::error::HookErrorKind as HEK; use libimagstore::hook::result::HookResult; use libimagutil::debug_result::*; +use vcs::git::action::StoreAction; use vcs::git::result::Result; 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 .as_ref() .ok_or(GHEK::MkRepo.into_error()) - .map_err(Box::new) - .map_err(|e| HEK::HookExecutionError.into_error_with_cause(e)) + .map_err_into(GHEK::RepositoryError) + .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<()> { diff --git a/libimagstorestdhook/src/vcs/git/update.rs b/libimagstorestdhook/src/vcs/git/update.rs index 9d5d18eb..fa4af2c9 100644 --- a/libimagstorestdhook/src/vcs/git/update.rs +++ b/libimagstorestdhook/src/vcs/git/update.rs @@ -87,13 +87,13 @@ impl StoreIdAccessor for UpdateHook { use vcs::git::action::StoreAction; use vcs::git::config::commit_message; use vcs::git::error::MapIntoHookError; - use vcs::git::util::{fetch_repo, fetch_index}; + use vcs::git::util::fetch_index; debug!("[GIT UPDATE HOOK]: {:?}", id); let action = StoreAction::Update; 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 tree_id = try!( diff --git a/libimagstorestdhook/src/vcs/git/util.rs b/libimagstorestdhook/src/vcs/git/util.rs index 7e0a9f4d..56b66323 100644 --- a/libimagstorestdhook/src/vcs/git/util.rs +++ b/libimagstorestdhook/src/vcs/git/util.rs @@ -13,17 +13,6 @@ use vcs::git::error::MapIntoHookError; use libimagutil::debug_result::*; 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 { debug!("[GIT {} HOOK]: Getting Index", action.uppercase()); repo.index() From c19f269f59e99db69e4c5673d82450df12e2c5a4 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 7 Sep 2016 21:57:10 +0200 Subject: [PATCH 9/9] Adapt ensure_cfg_branch_is_checked_out() for new Runtime::repository() interface --- libimagstorestdhook/src/vcs/git/create.rs | 6 ++---- libimagstorestdhook/src/vcs/git/runtime.rs | 6 ++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libimagstorestdhook/src/vcs/git/create.rs b/libimagstorestdhook/src/vcs/git/create.rs index c8ada38a..fcba4535 100644 --- a/libimagstorestdhook/src/vcs/git/create.rs +++ b/libimagstorestdhook/src/vcs/git/create.rs @@ -103,11 +103,9 @@ impl StoreIdAccessor for CreateHook { .map_into_hook_error() ); - debug!("[GIT CREATE HOOK]: Ensuring branch checkout"); - try!(self.runtime.ensure_cfg_branch_is_checked_out()); - debug!("[GIT CREATE HOOK]: Branch checked out"); - let action = StoreAction::Create; + 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)); diff --git a/libimagstorestdhook/src/vcs/git/runtime.rs b/libimagstorestdhook/src/vcs/git/runtime.rs index 74ed8fb3..13902b7d 100644 --- a/libimagstorestdhook/src/vcs/git/runtime.rs +++ b/libimagstorestdhook/src/vcs/git/runtime.rs @@ -74,11 +74,12 @@ impl Runtime { .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, action: &StoreAction) -> HookResult<()> { use vcs::git::config::ensure_branch; + debug!("[GIT CREATE HOOK]: Ensuring branch checkout"); let head = try!(self - .repository() + .repository(action) .and_then(|r| { debug!("Repository fetched, getting head"); r.head() @@ -128,6 +129,7 @@ impl Runtime { } .map_err(Box::new) .map_err(|e| HEK::HookExecutionError.into_error_with_cause(e)) + .map_dbg_str("[GIT CREATE HOOK]: Branch checked out") } }