From 81cc6c822b180de8fb0996545feeb8b6f3f8bec6 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 18 Sep 2016 18:29:31 +0200 Subject: [PATCH] UpdateHook: Add config-based abort if repo init failed --- libimagstorestdhook/src/vcs/git/update.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/libimagstorestdhook/src/vcs/git/update.rs b/libimagstorestdhook/src/vcs/git/update.rs index 9576d6ec..8b0186ec 100644 --- a/libimagstorestdhook/src/vcs/git/update.rs +++ b/libimagstorestdhook/src/vcs/git/update.rs @@ -93,15 +93,34 @@ impl StoreIdAccessor for UpdateHook { /// if there is no configuration for an interactive commit. /// 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_NEW, STATUS_WT_MODIFIED, IndexMatchedPath}; debug!("[GIT UPDATE HOOK]: {:?}", id); - let action = StoreAction::Update; + let action = StoreAction::Update; + + if !self.runtime.has_repository() { + debug!("[GIT UPDATE 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 UPDATE HOOK]: Config says we should abort if we have no repository"); + debug!("[GIT UPDATE HOOK]: Returing Err(_)"); + return Err(GHEK::RepositoryInitError.into_error()) + .map_err_into(GHEK::RepositoryError) + .map_into_hook_error() + } else { + debug!("[GIT UPDATE HOOK]: Config says it is okay to not have a repository"); + debug!("[GIT UPDATE 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));