swellaby / rusty-hook

git hook manager, geared toward Rust projects
MIT License
206 stars 11 forks source link

rusty-hook went silent on my system #109

Closed x80486 closed 4 years ago

x80486 commented 4 years ago

Environment Details

Description

I have a small pilot project that I use for testing. I'm trying to setup rusty-hook but it's not working in any shape or form. The way I installed it was by adding rusty-hook = "^0.11.2" on the [dev-dependencies] section inside Cargo.toml. Then I do:

[x80486@archbook:~/Workshop/Development/rust_basics]$ cargo test 
   Compiling autocfg v1.0.0
   Compiling serde v1.0.114
   Compiling fsio v0.1.3
   Compiling nias v0.5.0
   Compiling unicode-width v0.1.8
   Compiling rust_basics v0.1.0 (/home/x80486/Workshop/Development/rust_basics)
   Compiling getopts v0.2.21
   Compiling indexmap v1.4.0
   Compiling envmnt v0.8.3
   Compiling ci_info v0.10.2
   Compiling toml v0.5.6
   Compiling rusty-hook v0.11.2
    Finished test [unoptimized + debuginfo] target(s) in 6.31s
     Running target/debug/deps/rust_basics-8675574437f08b6a

running 2 tests
test tests::greeting_test ... ok
test tests::internal_greeting_test ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/rust_basics-d2e528f184d6c488

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/lib_test-eb12b06029d677aa

running 1 test
test greeting_test ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests rust_basics

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Then I create a .rusty-hook.toml file in the project's root with this content:

[hooks]
pre-commit = "cargo test --all"

[logging]
verbose = true

...modify a test case to make it fail, stage the changes, and finally do git commit --message="blah". The expectation is that something gets created in .git/hook and the hook to be executed...but nothing. Any clues?

I installed Rust + Cargo via asdf. That takes care of everything, even putting the needed stuff in the user's PATH environment variable. It does use rustup behind scenes to install Rust and everything else, but I'm thinking the hurdle is somehow around this folk, but I'm not sure if I'm missing something else.


By the way, I also tried to install it via cargo install rusty-hook, but I'm getting Fatal error encountered during initialization. Details: Unable to create git hooks when trying to initialize.

[x80486@archbook:~/Workshop/Development/rust_basics]$ cargo install rusty-hook 
    Updating crates.io index
  Installing rusty-hook v0.11.2
   Compiling autocfg v1.0.0
   Compiling serde v1.0.114
   Compiling fsio v0.1.3
   Compiling nias v0.5.0
   Compiling unicode-width v0.1.8
   Compiling getopts v0.2.21
   Compiling indexmap v1.4.0
   Compiling envmnt v0.8.3
   Compiling ci_info v0.10.2
   Compiling toml v0.5.6
   Compiling rusty-hook v0.11.2
    Finished release [optimized] target(s) in 8.97s
  Installing /home/x80486/.asdf/installs/rust/1.44.1/bin/rusty-hook
   Installed package `rusty-hook v0.11.2` (executable `rusty-hook`)
[x80486@archbook:~/Workshop/Development/rust_basics]$ asdf reshim rust 
[x80486@archbook:~/Workshop/Development/rust_basics]$ rust <TAB>
rustc       rustdoc     rustfmt     rust-gdb    rust-lldb   rustup      rusty-hook  
[x80486@archbook:~/Workshop/Development/rust_basics]$ rusty-hook init 
Fatal error encountered during initialization. Details: Unable to create git hooks
x80486 commented 4 years ago

OK, this one took me a while.

I was initially setting up the Git hooks business manually so I ended up doing some shell scripts. Then I wanted them to be in source control, so I added them in a .git-hooks/ sub-directory in the project's root and modifying Git's core.hooksPath setting.

The message Fatal error encountered during initialization. Details: Unable to create git hooks was what gave me the clue. Probably you folks might want to provide a similar error message with the location that's trying to be resolved to store the hooks.

It works flawlessly right now :tropical_drink: :trophy:

Thanks for the library! Feel free to close this one.

calebcartwright commented 4 years ago

Thanks for reaching out @x80486 and glad it's working! I have a few follow up questions for you just to ensure I understand the steps you went through to see whether we'll want to update any docs/error messages/etc. on our end.

When you first added rusty-hook as a dev dep and ran cargo test as I believe referenced in the issue description, am I understanding correctly that there was no .rusty-hook.toml config file created (you had to create it yourself) and you also didn't get any errors?

x80486 commented 4 years ago

No, I installed it via dev-dependencies and put a default .rusty-hook.toml with:

[hooks]
pre-commit = "cargo test --all"

[logging]
verbose = true

...then I tried to commit (with a failing test).

calebcartwright commented 4 years ago

No, I installed it via dev-dependencies and put a default .rusty-hook.toml with:

So you created your own config file before you ran cargo test?

calebcartwright commented 4 years ago

the build process will seed a default config file for you (if one doesn't already exist), but it sounded like one wasn't generated for you and that you had to create one for yourself.

I'd forgotten that the build.rs process always returns 0 even if the initialization fails during build, which it did in your case for precisely the reason you discovered. The build script does print a similar error message to the console, however, cargo swallows output during the build unless you run with -vv, so the same error that occurred during your first cargo test never popped up in the terminal.

There's really no reason our build script should exit with 0 in the event it failed and was unable to create the hook files and and config file, and the current behavior is obviously ambiguous and confusing. Users can always remove it from their dev-deps if it's failing and that's a blocking issue for them.

Thanks again for letting us know about this @x80486! I'm going to go ahead and close this given that the issue is resolved, but going to open a new issue (#110) to track updating the build script