Merge pull request #749 from matthiasbeyer/libimagstorestdhook/git-reenable-warning-deny

libimagstorestdhook/git: reenable warning deny
This commit is contained in:
Matthias Beyer 2016-09-19 14:39:00 +02:00 committed by GitHub
commit 321b0493fb
7 changed files with 86 additions and 36 deletions

View file

@ -61,7 +61,7 @@ aspect = "vcs"
abort_on_repo_init_failure = true abort_on_repo_init_failure = true
# Ensure to be on this branche before doing anything. # Ensure to be on this branche before doing anything.
ensure_branch = "master" ensure_branch = "refs/heads/master"
# Try to checkout the ensure_branch if it isn't checked out # Try to checkout the ensure_branch if it isn't checked out
try_checkout_ensure_branch = true try_checkout_ensure_branch = true
@ -75,7 +75,7 @@ aspect = "vcs"
abort_on_repo_init_failure = true abort_on_repo_init_failure = true
# Ensure to be on this branche before doing anything. # Ensure to be on this branche before doing anything.
ensure_branch = "master" ensure_branch = "refs/heads/master"
# Try to checkout the ensure_branch if it isn't checked out # Try to checkout the ensure_branch if it isn't checked out
try_checkout_ensure_branch = true try_checkout_ensure_branch = true
@ -103,7 +103,7 @@ aspect = "vcs"
abort_on_repo_init_failure = true abort_on_repo_init_failure = true
# Ensure to be on this branche before doing anything. # Ensure to be on this branche before doing anything.
ensure_branch = "master" ensure_branch = "refs/heads/master"
# Try to checkout the ensure_branch if it isn't checked out # Try to checkout the ensure_branch if it isn't checked out
try_checkout_ensure_branch = true try_checkout_ensure_branch = true

View file

@ -1,18 +1,18 @@
// #![deny( #![deny(
// dead_code, dead_code,
// non_camel_case_types, non_camel_case_types,
// non_snake_case, non_snake_case,
// path_statements, path_statements,
// trivial_numeric_casts, trivial_numeric_casts,
// unstable_features, unstable_features,
// unused_allocation, unused_allocation,
// unused_import_braces, unused_import_braces,
// unused_imports, unused_imports,
// unused_must_use, unused_must_use,
// unused_mut, unused_mut,
// unused_qualifications, unused_qualifications,
// while_true, while_true,
// )] )]
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate toml; extern crate toml;

View file

@ -115,8 +115,8 @@ pub fn commit_message(repo: &Repository, config: &Value, action: StoreAction, id
} }
/// Check whether the hook should abort if the repository cannot be initialized /// Check whether the hook should abort if the repository cannot be initialized
pub fn abort_on_repo_init_err(cfg: Option<&Value>) -> bool { pub fn abort_on_repo_init_err(cfg: &Value) -> bool {
get_bool_cfg(cfg, "abort_on_repo_init_failure", true, true) get_bool_cfg(Some(cfg), "abort_on_repo_init_failure", true, true)
} }
/// Get the branch which must be checked out before running the hook (if any). /// Get the branch which must be checked out before running the hook (if any).

View file

@ -79,15 +79,35 @@ impl HookDataAccessorProvider for DeleteHook {
impl StoreIdAccessor for DeleteHook { impl StoreIdAccessor for DeleteHook {
fn access(&self, id: &StoreId) -> HookResult<()> { fn access(&self, id: &StoreId) -> HookResult<()> {
use libimagerror::into::IntoError;
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_index; use vcs::git::util::fetch_index;
use vcs::git::config::abort_on_repo_init_err;
use git2::{ADD_DEFAULT, STATUS_WT_DELETED, IndexMatchedPath}; use git2::{ADD_DEFAULT, STATUS_WT_DELETED, IndexMatchedPath};
debug!("[GIT DELETE HOOK]: {:?}", id); 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 _ = try!(self.runtime.ensure_cfg_branch_is_checked_out(&action));
let cfg = try!(self.runtime.config_value_or_err(&action)); let cfg = try!(self.runtime.config_value_or_err(&action));
let repo = try!(self.runtime.repository(&action)); let repo = try!(self.runtime.repository(&action));
let mut index = try!(fetch_index(repo, &action)); let mut index = try!(fetch_index(repo, &action));

View file

@ -11,9 +11,11 @@ generate_error_module!(
ConfigTypeError => "Configuration value type wrong", ConfigTypeError => "Configuration value type wrong",
RepositoryError => "Error while interacting with git repository", RepositoryError => "Error while interacting with git repository",
RepositoryInitError => "Error while loading the git repository",
RepositoryBackendError => "Error in the git library", RepositoryBackendError => "Error in the git library",
RepositoryBranchError => "Error while interacting with git branch(es)", RepositoryBranchError => "Error while interacting with git branch(es)",
RepositoryBranchNameFetchingError => "Error while fetching branch name", RepositoryBranchNameFetchingError => "Error while fetching branch name",
RepositoryWrongBranchError => "Error because repository is on wrong branch",
RepositoryIndexFetchingError => "Error while fetching Repository Index", RepositoryIndexFetchingError => "Error while fetching Repository Index",
RepositoryIndexWritingError => "Error while writing Repository Index", RepositoryIndexWritingError => "Error while writing Repository Index",
RepositoryPathAddingError => "Error while adding Path to Index", RepositoryPathAddingError => "Error while adding Path to Index",

View file

@ -4,7 +4,7 @@ use git2::{Index, Repository};
use toml::Value; use toml::Value;
use libimagerror::into::IntoError; use libimagerror::into::IntoError;
use libimagerror::trace::{MapErrTrace, trace_error}; use libimagerror::trace::MapErrTrace;
use libimagstore::hook::error::CustomData; use libimagstore::hook::error::CustomData;
use libimagstore::hook::error::HookErrorKind as HEK; use libimagstore::hook::error::HookErrorKind as HEK;
use libimagstore::hook::result::HookResult; use libimagstore::hook::result::HookResult;
@ -64,7 +64,7 @@ impl Runtime {
.map_err_into(GHEK::ConfigError) .map_err_into(GHEK::ConfigError)
.map_err(Box::new) .map_err(Box::new)
.map_err(|e| HEK::HookExecutionError.into_error_with_cause(e)) .map_err(|e| HEK::HookExecutionError.into_error_with_cause(e))
.map_err(|mut e| e.with_custom_data(CustomData::default().aborting(false))) .map_err(|e| e.with_custom_data(CustomData::default().aborting(false)))
.map_dbg_err(|_| { .map_dbg_err(|_| {
format!("[GIT {} HOOK]: Couldn't get Value object from config", action.uppercase()) format!("[GIT {} HOOK]: Couldn't get Value object from config", action.uppercase())
}) })
@ -91,42 +91,50 @@ impl Runtime {
/// Ensure that the branch that is put in the configuration file is checked out, if any. /// Ensure that the branch that is put in the configuration file is checked out, if any.
pub fn ensure_cfg_branch_is_checked_out(&self, action: &StoreAction) -> HookResult<()> { pub fn ensure_cfg_branch_is_checked_out(&self, action: &StoreAction) -> HookResult<()> {
use vcs::git::config::ensure_branch; use vcs::git::config::ensure_branch;
use vcs::git::config::do_checkout_ensure_branch;
debug!("[GIT CREATE HOOK]: Ensuring branch checkout"); debug!("[GIT {} HOOK]: Ensuring branch checkout", action.uppercase());
let head = try!(self let head = try!(self
.repository(action) .repository(action)
.and_then(|r| { .and_then(|r| {
debug!("Repository fetched, getting head"); debug!("[GIT {} HOOK]: Repository fetched, getting head", action.uppercase());
r.head() r.head()
.map_dbg_err_str("Couldn't fetch HEAD") .map_dbg_err_str("Couldn't fetch HEAD")
.map_dbg_err(|e| format!("\tbecause = {:?}", e)) .map_dbg_err(|e| format!("\tbecause = {:?}", e))
.map_err_into(GHEK::HeadFetchError) .map_err_into(GHEK::HeadFetchError)
.map_err(|e| e.into()) .map_err(|e| e.into())
})); }));
debug!("HEAD fetched"); debug!("[GIT {} HOOK]: HEAD fetched", action.uppercase());
// TODO: Fail if not on branch? hmmh... I'm not sure // TODO: Fail if not on branch? hmmh... I'm not sure
if !head.is_branch() { if !head.is_branch() {
debug!("HEAD is not a branch"); debug!("[GIT {} HOOK]: HEAD is not a branch", action.uppercase());
return Err(GHEK::NotOnBranch.into_error().into()); return Err(GHEK::NotOnBranch.into_error().into());
} }
debug!("HEAD is a branch"); debug!("[GIT {} HOOK]: HEAD is a branch", action.uppercase());
// Check out appropriate branch ... or fail // Check out appropriate branch ... or fail
match ensure_branch(self.config.as_ref()) { match ensure_branch(self.config.as_ref()) {
Ok(Some(s)) => { Ok(Some(s)) => {
debug!("We have to ensure branch: {}", s); debug!("[GIT {} HOOK]: We have to ensure branch: {}", action.uppercase(), s);
match head.name().map(|name| { match head.name().map(|name| {
debug!("{} == {}", name, s); debug!("[GIT {} HOOK]: {} == {}", action.uppercase(), name, s);
name == s name == s
}) { }) {
Some(b) => { Some(b) => {
if b { if b {
debug!("Branch already checked out."); debug!("[GIT {} HOOK]: Branch already checked out.", action.uppercase());
Ok(()) Ok(())
} else { } else {
debug!("Branch not checked out."); debug!("[GIT {} HOOK]: Branch not checked out.", action.uppercase());
unimplemented!()
if !do_checkout_ensure_branch(self.config.as_ref()) {
Err(GHEK::RepositoryWrongBranchError.into_error())
.map_err_into(GHEK::RepositoryError)
} else {
// Else try to check out the branch...
unimplemented!()
}
} }
}, },
@ -136,7 +144,7 @@ impl Runtime {
} }
}, },
Ok(None) => { Ok(None) => {
debug!("No branch to checkout"); debug!("[GIT {} HOOK]: No branch to checkout", action.uppercase());
Ok(()) Ok(())
}, },
@ -144,7 +152,7 @@ impl Runtime {
} }
.map_err(Box::new) .map_err(Box::new)
.map_err(|e| HEK::HookExecutionError.into_error_with_cause(e)) .map_err(|e| HEK::HookExecutionError.into_error_with_cause(e))
.map_dbg_str("[GIT CREATE HOOK]: Branch checked out") .map_dbg(|_| format!("[GIT {} HOOK]: Branch checked out", action.uppercase()))
} }
/// Check whether the WD is "dirty" - whether there is a diff to the repository /// Check whether the WD is "dirty" - whether there is a diff to the repository

View file

@ -93,15 +93,35 @@ impl StoreIdAccessor for UpdateHook {
/// if there is no configuration for an interactive commit. /// if there is no configuration for an interactive commit.
/// ///
fn access(&self, id: &StoreId) -> HookResult<()> { fn access(&self, id: &StoreId) -> HookResult<()> {
use libimagerror::into::IntoError;
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_index; 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}; use git2::{ADD_DEFAULT, STATUS_WT_NEW, STATUS_WT_MODIFIED, IndexMatchedPath};
debug!("[GIT UPDATE HOOK]: {:?}", id); 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 _ = try!(self.runtime.ensure_cfg_branch_is_checked_out(&action));
let cfg = try!(self.runtime.config_value_or_err(&action)); let cfg = try!(self.runtime.config_value_or_err(&action));
let repo = try!(self.runtime.repository(&action)); let repo = try!(self.runtime.repository(&action));
let mut index = try!(fetch_index(repo, &action)); let mut index = try!(fetch_index(repo, &action));