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
# 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_checkout_ensure_branch = true
@ -75,7 +75,7 @@ aspect = "vcs"
abort_on_repo_init_failure = true
# 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_checkout_ensure_branch = true
@ -103,7 +103,7 @@ aspect = "vcs"
abort_on_repo_init_failure = true
# 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_checkout_ensure_branch = true

View File

@ -1,18 +1,18 @@
// #![deny(
// dead_code,
// non_camel_case_types,
// non_snake_case,
// path_statements,
// trivial_numeric_casts,
// unstable_features,
// unused_allocation,
// unused_import_braces,
// unused_imports,
// unused_must_use,
// unused_mut,
// unused_qualifications,
// while_true,
// )]
#![deny(
dead_code,
non_camel_case_types,
non_snake_case,
path_statements,
trivial_numeric_casts,
unstable_features,
unused_allocation,
unused_import_braces,
unused_imports,
unused_must_use,
unused_mut,
unused_qualifications,
while_true,
)]
#[macro_use] extern crate log;
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
pub fn abort_on_repo_init_err(cfg: Option<&Value>) -> bool {
get_bool_cfg(cfg, "abort_on_repo_init_failure", true, true)
pub fn abort_on_repo_init_err(cfg: &Value) -> bool {
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).

View File

@ -79,15 +79,35 @@ 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 _ = 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));

View File

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

View File

@ -4,7 +4,7 @@ use git2::{Index, Repository};
use toml::Value;
use libimagerror::into::IntoError;
use libimagerror::trace::{MapErrTrace, trace_error};
use libimagerror::trace::MapErrTrace;
use libimagstore::hook::error::CustomData;
use libimagstore::hook::error::HookErrorKind as HEK;
use libimagstore::hook::result::HookResult;
@ -64,7 +64,7 @@ impl Runtime {
.map_err_into(GHEK::ConfigError)
.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_err(|e| e.with_custom_data(CustomData::default().aborting(false)))
.map_dbg_err(|_| {
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.
pub fn ensure_cfg_branch_is_checked_out(&self, action: &StoreAction) -> HookResult<()> {
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
.repository(action)
.and_then(|r| {
debug!("Repository fetched, getting head");
debug!("[GIT {} HOOK]: Repository fetched, getting head", action.uppercase());
r.head()
.map_dbg_err_str("Couldn't fetch HEAD")
.map_dbg_err(|e| format!("\tbecause = {:?}", e))
.map_err_into(GHEK::HeadFetchError)
.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
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());
}
debug!("HEAD is a branch");
debug!("[GIT {} HOOK]: HEAD is a branch", action.uppercase());
// Check out appropriate branch ... or fail
match ensure_branch(self.config.as_ref()) {
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| {
debug!("{} == {}", name, s);
debug!("[GIT {} HOOK]: {} == {}", action.uppercase(), name, s);
name == s
}) {
Some(b) => {
if b {
debug!("Branch already checked out.");
debug!("[GIT {} HOOK]: Branch already checked out.", action.uppercase());
Ok(())
} else {
debug!("Branch not checked out.");
unimplemented!()
debug!("[GIT {} HOOK]: Branch not checked out.", action.uppercase());
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) => {
debug!("No branch to checkout");
debug!("[GIT {} HOOK]: No branch to checkout", action.uppercase());
Ok(())
},
@ -144,7 +152,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")
.map_dbg(|_| format!("[GIT {} HOOK]: Branch checked out", action.uppercase()))
}
/// 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.
///
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 _ = 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));