diff options
Diffstat (limited to 'git_hooks')
| -rwxr-xr-x | git_hooks/commit-msg | 35 | ||||
| -rwxr-xr-x | git_hooks/pre-commit | 24 |
2 files changed, 59 insertions, 0 deletions
diff --git a/git_hooks/commit-msg b/git_hooks/commit-msg new file mode 100755 index 0000000..e754e8d --- /dev/null +++ b/git_hooks/commit-msg | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | ### gitlint commit-msg hook start ### | ||
| 3 | |||
| 4 | # Determine whether we have a tty available by trying to access it. | ||
| 5 | # This allows us to deal with UI based gitclient's like Atlassian SourceTree. | ||
| 6 | # NOTE: "exec < /dev/tty" sets stdin to the keyboard | ||
| 7 | stdin_available=1 | ||
| 8 | (exec < /dev/tty) 2> /dev/null || stdin_available=0 | ||
| 9 | |||
| 10 | if [ $stdin_available -eq 1 ]; then | ||
| 11 | # Now that we know we have a functional tty, set stdin to it so we can ask the user questions :-) | ||
| 12 | exec < /dev/tty | ||
| 13 | |||
| 14 | # On Windows, we need to explicitly set our stdout to the tty to make terminal editing work (e.g. vim) | ||
| 15 | # See SO for windows detection in bash (slight modified to work on plain shell (not bash)): | ||
| 16 | # https://stackoverflow.com/questions/394230/how-to-detect-the-os-from-a-bash-script | ||
| 17 | if [ "$OSTYPE" = "cygwin" ] || [ "$OSTYPE" = "msys" ] || [ "$OSTYPE" = "win32" ]; then | ||
| 18 | exec > /dev/tty | ||
| 19 | fi | ||
| 20 | fi | ||
| 21 | |||
| 22 | gitlint --staged --msg-filename "$1" run-hook | ||
| 23 | exit_code=$? | ||
| 24 | |||
| 25 | # If we fail to find the gitlint binary (command not found), let's retry by executing as a python module. | ||
| 26 | # This is the case for Atlassian SourceTree, where $PATH deviates from the user's shell $PATH. | ||
| 27 | if [ $exit_code -eq 127 ]; then | ||
| 28 | echo "Fallback to python module execution" | ||
| 29 | python -m gitlint.cli --staged --msg-filename "$1" run-hook | ||
| 30 | exit_code=$? | ||
| 31 | fi | ||
| 32 | |||
| 33 | exit $exit_code | ||
| 34 | |||
| 35 | ### gitlint commit-msg hook end ### | ||
diff --git a/git_hooks/pre-commit b/git_hooks/pre-commit new file mode 100755 index 0000000..63b191d --- /dev/null +++ b/git_hooks/pre-commit | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | set -eu | ||
| 4 | |||
| 5 | if ! cargo fmt -- --check | ||
| 6 | then | ||
| 7 | echo "There are some code style issues." | ||
| 8 | echo "Run cargo fmt first." | ||
| 9 | exit 1 | ||
| 10 | fi | ||
| 11 | |||
| 12 | if ! cargo clippy --all-targets -- -D warnings | ||
| 13 | then | ||
| 14 | echo "There are some clippy issues." | ||
| 15 | exit 1 | ||
| 16 | fi | ||
| 17 | |||
| 18 | if ! cargo test | ||
| 19 | then | ||
| 20 | echo "There are some test issues." | ||
| 21 | exit 1 | ||
| 22 | fi | ||
| 23 | |||
| 24 | exit 0 \ No newline at end of file | ||