aboutsummaryrefslogtreecommitdiff
path: root/hooked/src/main.rs
diff options
context:
space:
mode:
authorMichael Gattozzi <mgattozzi@gmail.com>2019-12-09 17:42:08 -0500
committerMichael Gattozzi <mgattozzi@gmail.com>2019-12-10 13:17:08 -0500
commit1dec32c37ac2f563e164021c9f21052f11fd1d20 (patch)
tree8d5508b09b742e63e72fbbf1571b5667b3ec0e1e /hooked/src/main.rs
parentfcd4ccbec30493872feba137342347541b6a4e28 (diff)
Make the pre-commit script pedantic and fix errors
This commit really ups the level and quality of the Rust code by setting clippy to pedantic mode. It also fixes an issue where bash continued to run scripts even if something failed with a non-zero exit status. We also deny all warnings so as to actually fail the builds and the commit hooks. This should make sure code quality stays at a high level.
Diffstat (limited to 'hooked/src/main.rs')
-rw-r--r--hooked/src/main.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/hooked/src/main.rs b/hooked/src/main.rs
index a3d8199..7e33499 100644
--- a/hooked/src/main.rs
+++ b/hooked/src/main.rs
@@ -1,3 +1,5 @@
+//! git hook manager tool
+
#[cfg(windows)]
use anyhow::bail;
use anyhow::Result;
@@ -45,9 +47,9 @@ enum Args {
#[paw::main]
fn main(args: Args) {
- env::var("RUST_LOG").map(drop).unwrap_or_else(|_| {
- env::set_var("RUST_LOG", "info");
- });
+ env::var("RUST_LOG")
+ .ok()
+ .map_or_else(|| env::set_var("RUST_LOG", "info"), drop);
pretty_env_logger::init();
if let Err(e) = match args {
Args::Init => init(),
@@ -74,7 +76,9 @@ fn init() -> Result<()> {
let git_hook = &git_hooks.join(hook);
debug!("git_hook path: {}", git_hook.display());
- if !path.exists() {
+ if path.exists() {
+ debug!("git hook {} already exists. Skipping creation.", hook);
+ } else {
debug!("Creating dev-suite hook.");
let mut file = fs::File::create(&path)?;
trace!("File created.");
@@ -86,8 +90,6 @@ fn init() -> Result<()> {
file.write_all(b"#! /bin/bash")?;
debug!("Writing data to file.");
debug!("Created git hook {}.", hook);
- } else {
- debug!("git hook {} already exists. Skipping creation.", hook);
}
let path = path.canonicalize()?;