rhysd / cargo-husky

Setup Git hooks automatically for cargo projects with :dog:
https://crates.io/crates/cargo-husky
MIT License
325 stars 20 forks source link

pre-commit hook runs on local files, not on commited ones #3

Open ghost opened 5 years ago

ghost commented 5 years ago

The pre-commit hook generated by this crate run on whatever files are on disk at the moment including on content that has not been commited and is not included in this commit. It creates false-positives and false-negatives.

Everything that is not in the stagging area should probably be stashed before running the hooks.

This is probably best described in this article https://dzone.com/articles/why-your-need-git-pre-commit

Thank you for sharing this work by the way, even with this small issue, it is still a great tool to have.

rhysd commented 5 years ago

Yeah, as you said, currently tests are run against the local files. I think we should push stash the current changes and checkout the commit before running tests (and pop the stash finally) in a generated script.

https://github.com/rhysd/cargo-husky/blob/master/build.rs#L104

gilescope commented 4 years ago

A simple step forward might be a hook that fails if there are staged changes when you're trying to push. - that'd definitely catching things I meant to push but forgot to commit.

droundy commented 4 years ago

I presume this same bug applies to the pre-push script?