aboutsummaryrefslogtreecommitdiff
path: root/hooked
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
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')
-rw-r--r--hooked/src/bin/hooked-commit-msg.rs2
-rw-r--r--hooked/src/main.rs14
-rw-r--r--hooked/tests/init.rs4
3 files changed, 12 insertions, 8 deletions
diff --git a/hooked/src/bin/hooked-commit-msg.rs b/hooked/src/bin/hooked-commit-msg.rs
index 7f2a996..b7de022 100644
--- a/hooked/src/bin/hooked-commit-msg.rs
+++ b/hooked/src/bin/hooked-commit-msg.rs
@@ -1,3 +1,5 @@
+//! Linting tool for commit messages
+
use shared::find_root;
use std::{
env::args,
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()?;
diff --git a/hooked/tests/init.rs b/hooked/tests/init.rs
index 2596d5b..65c4aab 100644
--- a/hooked/tests/init.rs
+++ b/hooked/tests/init.rs
@@ -33,10 +33,10 @@ const HOOKS: [&str; 18] = [
#[test]
fn init() -> Result<(), Box<dyn Error>> {
let dir = tempdir()?;
- Repository::init(&dir)?;
+ let _ = Repository::init(&dir)?;
let mut cmd = Command::cargo_bin("hooked")?;
env::set_current_dir(&dir)?;
- cmd.arg("init").assert().success();
+ let _ = cmd.arg("init").assert().success();
let git = &dir.path().join(".git").join("hooks");
let dev = &dir.path().join(".dev-suite").join("hooked");