Repository: rhysd/cargo-husky (language: rust)

Issue:
Add a way to not add hooks during tests
It'd be nice if there was something like `DONT_INSTALL_HUSKY_HOOKS` to not install hooks when `cargo test` is run.

Related: https://github.com/Cogitri/gxi/issues/199


Discussion / hints:

Fix patch:
diff --git a/build.rs b/build.rs
index 996d0cc..7610862 100644
--- a/build.rs
+++ b/build.rs
@@ -4,6 +4,7 @@ use path::{Path, PathBuf};
 #[cfg(not(target_os = "windows"))]
 use std::os;
 use std::{env, fmt, fs, io, path};
+use std::env::var_os;
 
 enum Error {
     GitDirNotFound,
@@ -312,12 +313,17 @@ fn install() -> Result<()> {
 }
 
 fn main() -> Result<()> {
-    match install() {
-        Err(e @ Error::GitDirNotFound) => {
-            // #2
-            eprintln!("Warning: {:?}", e);
-            Ok(())
+    if var_os("DONT_INSTALL_HUSKY_HOOKS").is_some() {
+        println!("Found 'DONT_INSTALL_HUSKY_HOOKS' in env, not doing anything!");
+        Ok(())
+    } else {
+        match install() {
+            Err(e @ Error::GitDirNotFound) => {
+                // #2
+                eprintln!("Warning: {:?}", e);
+                Ok(())
+            }
+            otherwise => otherwise,
         }
-        otherwise => otherwise,
     }
 }


Test patch: